LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a loop run every 5 ms

Hi guys, I am working with this  cable that has two integrated sensors. I am using a communication protocol that delivers continuous Datastream without new request, 4 bytes for flow data and 2 bytes for pressure data. 
Each Packet ends with 0xFF,0x03 so i have a packet of 8 bytes in total. Now, the cable returns me these 8 bytes with a very high frequency, around 1115 Hz, but i want these data to be displayed and saved at 200 Hz, so every 5 ms. I am able to display them and save them at the default frequency, but when i add the '5 ms' variable it doesn't work. 
As you can see i placed two loop in parallel, where the lower one should run every 5 ms, setting up my '5 ms' boolean variable and controlling my button value changes. The upper loop should manage the serial communication and, when the '5 ms' variable is up should display the data and set the '5 ms' variable back down. Isn't the lower loop supposed to run every 5 ms with the delay function that i placed inside it? The numeric control that i placed for it never increases and it suggests me that it run the first time and then it does not run anymore.
I know that it is not a great VI and I have to fix lots of things, but at the moment for me it's important to make this timing work. Any suggestion? Thank you very much.

0 Kudos
Message 1 of 5
(1,572 Views)

The eventloop halts the while loop as it is not triggered. You will probably see the "Numeric 2" increases each time you press the "Save" of "Reset" button, since this fires the event loop.

0 Kudos
Message 2 of 5
(1,555 Views)

Your Event Structure waits until an event.  You don't define a timeout for the Event Structure, so it will wait forever.

 

Still, this is just riddled with race conditions.  If you really want to update at the 5ms rate, then put the 5ms wait in the main loop.  I would also get rid of a bunch of these controls and work to get rid of all of these Local Variables.


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 3 of 5
(1,547 Views)

Ok i see, but in my event structure there is also a Timeout event, it is not suppose to run while waiting? Anyway,  the wait function cannot be put in the main loop because it generates issues with the serial communication. I have tried now to create a third loop with the wait function only, now i can see the data and save it, but the frequency is way lower respect to 200 Hz. The numeric indicator associated with this third loop indicates me that is running almost precisely every 5 ms, while the numeric indicator of the main loop increases slower. What can it be?

0 Kudos
Message 4 of 5
(1,543 Views)

It would really help to keep all your related discussion in one thread so we don't need to start from scratch every time. This seems to be a continuation of your old discusssion.

 

(You haven't listened to any of our suggestions and your VI is still peppered with the same old race conditions, glaring mistakes, and Rube Goldberg code constructs! Actually, whatever you did, you made it worse!)

 

Please start over with the basic LabVIEW training resources. You cannot write a reasonable program without knowing the principles!

0 Kudos
Message 5 of 5
(1,512 Views)