LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving values from VISA Serial Read to an array

I made a few more mods.  So Jeff added in some error handling (which was needed).  I cleaned some things up and a few other things.

1. No real need for the Wait in there.  You have a 10 second timeout on your VISA Reads.  So let the VISA Read limit your loop rate.

2. Replace your Stop Switch with a Stop Button.  It makes a lot more sense and can reset itself when read (a feature called Latching).

3. Change your array to be of numeric instead of strings.  This way you are not constantly reconverting all of the previous measurements.

 

My main curiosity is that you have a dt of 300us (what you claim to be your sample rate), but your wait was 333ms.  That is a large difference and I think the dt is wrong (I don't see serial data getting out that fast).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 11 of 24
(2,003 Views)

Sorry for the late reply but the array only stores 46 values and I'm not sure why it does that. I wanted to save 100 values but not sure how to go about it.

0 Kudos
Message 12 of 24
(1,971 Views)

@engineerbeginner wrote:

Sorry for the late reply but the array only stores 46 values and I'm not sure why it does that. I wanted to save 100 values but not sure how to go about it.


Need to see code...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 13 of 24
(1,968 Views)

Don't have access to labView right now but check out the vi posted by user Jeff Bohrer at the bottom of the first page. Thanks!

0 Kudos
Message 14 of 24
(1,963 Views)

I also tried out your version but it still oly stores around 45-46 values in the array 😞

0 Kudos
Message 15 of 24
(1,960 Views)

@engineerbeginner wrote:

I also tried out your version but it still oly stores around 45-46 values in the array 😞


After the 45-46 values get stored what happens?

 

Does the vi quit with an error? what error?

Does the vi continue to run? What is received from the reads? Are you sure? did you display the strings as \codes or in Hex?  What are you expecting from the device on the other end?  Is the compiler generating that many messages?


"Should be" isn't "Is" -Jay
0 Kudos
Message 16 of 24
(1,953 Views)

It does keep running but after a few seconds all the values disappear and after a while an error message pops up. The last time I checked the error I believe it was a timeout error. I have not displayed the code in \codes or in Hex but I plan on doing so tomorrow. On the ccs complier at the other end my code is something like this:

 

int i, array[100];

for(i=0; i<=99; i++)

{

     array[i] = read_adc();

}

for(i=0; i<=99; i++)

{

    printf("\r\n%f", (array[i]*(5.0)/(255.0)));

}

0 Kudos
Message 17 of 24
(1,943 Views)

That explains a bit.

 

    printf("\r\n%f", (array[i]*(5.0)/(255.0)))

should be

    printf("%f\n", (array[i]*(5.0)/(256.0)+(5.0)/(512.0)))  //Assuming Vref=5V and 8 bit ADC (yes, you need to a 1/2lsb!) and printf now ENDs with the expected termination character rather than having it in the middle like that.


"Should be" isn't "Is" -Jay
0 Kudos
Message 18 of 24
(1,940 Views)

Alright I will try that out and update you tomorrow. Thanks for the reply!

 

I used (5.0/255.0) because that's what was mentioned on the PIC developmental kit I was using about how to get the voltage values from the adc readings.

0 Kudos
Message 19 of 24
(1,930 Views)

@engineerbeginner wrote:

Alright I will try that out and update you tomorrow. Thanks for the reply!

 

I used (5.0/255.0) because that's what was mentioned on the PIC developmental kit I was using about how to get the voltage values from the adc readings.


They should know better!  there are 256 steps from 0 to 5 volts assume your actual voltage is 1/2 way between two steps rather than on the edge..


"Should be" isn't "Is" -Jay
0 Kudos
Message 20 of 24
(1,925 Views)