LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case statement update on millisecond timer

Hello,

I am currently plotting data from a serial port in the time domain as well as the frequency domain.  My data sample rate is 3Khz, but when trying to display all of that data I was missing some data in between. I know it is not true data loss because the raw data written to the file is all accounted for.   I am now trying to update the waveform chart display (along with some data conversion) off of a millisecond timer.  


This seems to have fixed my data loss, however, my frequency domain (x axis) is now off and am wondering what I need to do to fix this.   I'm sure this is not the most elegant way to do this, but I am still very early in the LabView learning process. 

 

Any help would be very much appreciated.  I have attached my code.
Thanks

0 Kudos
Message 1 of 9
(2,265 Views)

Hello,

 

VISA Read includes layer(s) of software buffer(s), so trying to match its output to your current ms-timer (even if the data has been sent with a specific sample rate) is not something that will work.

 

Or in other words: get rid of your check if the ms-counter is a multiply of 6.

 

Regards, Jens.

Kudos are welcome...
0 Kudos
Message 2 of 9
(2,239 Views)

How do you know you are missing data?

 

Your baud rate is set for 9600 baud.  At roughly 10 bits per byte,  (8 data, 1 start, 1 stop, no parity), you are only going to get about 960 bytes per second.

 

There is no way you can achieve data at 3kHz data rate when you get less than 1000 bytes per second.

Message 3 of 9
(2,230 Views)

Hi,

 

an addition to my first reply:

even if you receive your data with the same sample rate as is was aquired and sent - you now add data to your graph at the most each 6 ms (i.e. 166 Hz in ideal circumstances, but probably much less), but you plot that data with a sample rate of 3 kHz.

 

Regards

Kudos are welcome...
0 Kudos
Message 4 of 9
(2,211 Views)

sorry, the baud rate is 1Mbaud... I just did not change the default rate in the text box.

0 Kudos
Message 5 of 9
(2,202 Views)

It appears the data manipulation portion and or the display cannot keep up with the incoming data.  I know it's not in the serial transmission because all of the data is present in the saved file.  

 

I see glitches in both the time-domain and frequency domain plots in periodic intervals where is looks like it misses the start byte (0x24) and has to wait until it finds the next one before correctly resuming the display.

 

Any pointers?

Thanks for all of your replies!

0 Kudos
Message 6 of 9
(2,201 Views)

Actually, if all data are consistently present into the file, you are not missing any packet. You may miss data in the processing part, however.

In the attached vi I show a possible way to go.

I assumed that you are interested in the last 1000 samples and want to analyze only every 10 samples.

One advantage of this code is that the samples array will not grow indefinitely, preventing memory allocations that can slow down execution.

If instead want to analyze at every new sample and this code cannot keep up, you will need to split the code in two loops, one where you only read raw data, convert to voltage and put them in a queue, the other (that will run at a slower pace) where you read the queue content ad analyze the data.

EDIT: you should also check that the received packet is good before proceeding

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 7 of 9
(2,165 Views)

Wow thank you this is exactly what I needed.  I'm sorry can you please just explain what you did, I'm having a little bit of a hard time following the code.

Thanks again!

0 Kudos
Message 8 of 9
(2,140 Views)

@LKcire  ha scritto:

 I'm sorry can you please just explain what you did, I'm having a little bit of a hard time following the code.

 


a) Process all packets. If the array of voltages has less than 1000 elements, simply add the value to end of the array (Build Array), otherwise rotate the array backwards and replace the 1000th value

b) Count the total number of voltage data (N) in a shift register (this number will be > 1000 from a given time on)

c) Process the array when N >= 1000 AND the rest of the integer division N / 10 is =0 (that is when N= 1000, 1010, 1020, etc.)

 

EDIT: I forgot to recommend you to keep the BD more compact. It will be easier to read and debug the code.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 9 of 9
(2,134 Views)