LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

deterministic while loop in windows7 environment

Solved!
Go to solution

Hi, i would like to execute while loop at 30ms sample time while reading and writing to serial port.

is there any way to execute while loop in exact sample rate in windows 7 environment.

platform is Windows 7

labview ver 2015

 

0 Kudos
Message 1 of 12
(2,669 Views)

@DMic wrote:

Hi, i would like to execute while loop at 30ms sample time while reading and writing to serial port.


Use a 30ms wait in your loop

 


@DMic wrote:

is there any way to execute while loop in exact sample rate in windows 7 environment.


No. Antivirus, random other applications, user activity and so on can all disrupt "exact" timing. But you'll be pretty close, 30ms is not so tight. Just make sure that your loop contents (apart from the wait) take less than 30ms (ideally a smallish fraction, e.g. 10ms) to execute.


GCentral
0 Kudos
Message 2 of 12
(2,629 Views)

Window it not deterministic in terms of timing. Interacting with external hardware (reading and writing to the serial port! I assume this is the same port for both directions, is it?) adds additional constraints, because the communication itself as well as the response time depends on external factors. Can you guarantee that writing to the serial port and receiving all expected data is guaranteed to happen in the time constraints?

Instead of demanding tight timing limits, maybe you could explain what's so magical about the 30ms and why it has to be that way. Is the computer supposed to dictate the timing or is the external device sending at that rate? What's the worst that can happen if jitter exceeds the envelope? What should happen if somebody accidentally unplugs the serial cable?

You could use a timed loop. At least it will notify you if the timing cannot be kept.

Message 3 of 12
(2,619 Views)

Neither Windows nor Serial are deterministic.  Determinism is a lot like the idea of a chain being as strong as its weakest link.  If any portion isn't deterministic, none of it is.

 

But, as others mentioned that doesn't mean you can't typically meet the 30ms benchmark.  We don't have enough information to suggest whether or not that's a plausible expectation.

0 Kudos
Message 4 of 12
(2,613 Views)

Please let us know not just why you need 30 ms, but how tight the timing is. If it's an *average* of 30 ms over time, with +/-10 ms jitter acceptable, that's much more doable than 30 ms +/- 0.1 ms, each and every time. The former isn't *definitely* doable but it's a lot more achievable than the latter.

0 Kudos
Message 5 of 12
(2,561 Views)

Requirement is each loop iteration to be 30ms or i have to send 1 packet over serial port. so that the data points correspond to proper sample time on receiver side . +- one sample point might acceptable

0 Kudos
Message 6 of 12
(2,535 Views)

@DMic wrote:

Requirement is each loop iteration to be 30ms or i have to send 1 packet over serial port. so that the data points correspond to proper sample time on receiver side . +- one sample point might acceptable


I that 1 sample point every 30ms?  Or are you sending multiple sample points in a packet?

 

And for everybody else, here is some more detail to the application from another thread: serial port read and write : executing link establish once


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 7 of 12
(2,521 Views)

Not wait! It will not compensate for internal delays

Wait for next ms multiple or timed loop.

Message 8 of 12
(2,502 Views)
Solution
Accepted by DMic

Wait for next ms takes you from e.g. 32 ms to 60 ms. I suppose it depends which is preferable.

 

Perhaps this is a rare use for a timed loop on Windows? Then you could have it reduce the waiting in the next iteration in order to get back on schedule, assuming that missing the timing was unusual... 

Example_VI.png

The results array isn't so easy to read here, since the values are a bit mixed between previous and current iteration, but from left to right they give:

  • Current iteration number
  • If the previous iteration finished late
  • The current ms timer value
  • The time taken to run the code inside the previous iteration (not the time targeted for the previous iteration). This value should for a working Timed Loop always be less than the target time (here 30ms)
  • The difference between tick counts for this iteration and the previous iteration (i.e. the time taken for the previous iteration, including extra waiting caused by the 'Timed-ness' of the Timed Loop).

With the "process missed, maintain phase" setting, it will shorten the wait in the iterations after a missed deadline in order to try and restore the expected timing of measurements (the Wait Until behaviour) but also won't just skip a measurement (as you would with Wait Until, potentially giving problems if you expect arrays to have the same length).


GCentral
Message 9 of 12
(2,477 Views)

Whenever I have a request for something like this I usually something along these lines:

 

Have you ever used Windows and it just locks up, and the mouse and keyboard just do nothing for a few seconds at a time, and then all of the sudden Windows wakes up and starts doing what you want again.  What do you think your program will be doing during that time?  Think it will be able to maintain a 30ms rate exactly?  Ever have Windows blue screen or crash on you?  Are you prepared to have your application die because Windows did?  Ever have a Windows update happen when you aren't around and have the computer spontaneously reboot?  What state will all the devices you are talking to be in?  Will high voltage equipment be kept on?  Or will motors keep moving into things?  These are some reasons someone might use an embedded real-time device to be more deterministic, and more reliable.

Message 10 of 12
(2,421 Views)