LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine Timer Issues

Hello all,  I'm trying to build a simple state machine that changes steps based on a timer.  As time elapses, go to the next step.  The simple example I created here, uses two steps with a step to check for an e-stop and an idle step to burn off the time.  I'm using the Express Elapsed Time vi.   The steps are 60 seconds each, after sixty seconds, the express vi resets, and the next step is started.

 

The problem I'm haveing is that the timer falls behind after a few minutes compared to the system clock.  After 5 minutes, I'm already behind almost two seconds.

 

To test the app, hit reset when the system clock minute is at a whole number and watch the two clocks,  after a cup of coffee it will slowly fall behind.

 

I'm pretty sure I'm doing this wrong and would really appreciate any suggestions as to a better method, such as using the tick counter.  Thank you.

Download All
0 Kudos
Message 1 of 11
(4,181 Views)

First delete the wait function with the 125ms at the upper right.

Second, delete the elapsed time function. You already use a timed loop so you can measure time.

Adding a second timed function in a timed function is... confusing.

Use a shift register and increase it by one in each iteration. When you reach 600 you will have 1 minute. (as your loop has period 100ms) Then reset it to zero.

 

0 Kudos
Message 2 of 11
(4,157 Views)
Hi Pnt,  thanks for your imput.  I forgot about that time delay when I converted the while loop to a timed loop.  I took up your suggestions and tried it again.  I see improvements, but after an hour, I'm about 3 seconds behind.  I think it may have to do with the way I'm resetting the clock.  If you could take a look that would be great.  Thanks again.
Download All
0 Kudos
Message 3 of 11
(4,128 Views)
Hello johnnyt,

I think you need to consider what would happen if on the 598th iteration (Count=599) the local variable Elaspsed time is read before it is updated by your math in the lower part of the loop. The local variable would output 59.8. This wouldn't trigger the reset and it would be two more iterations before it would be read again. This behavior would add an addtional .1 seconds to the time it takes to reset the clock. Try to change the code to eliminate most of the local variables.
Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 4 of 11
(4,100 Views)

Try this.

The other case is the "Default" and it's emty.

 

 

0 Kudos
Message 5 of 11
(4,082 Views)
Actually in the default case you can add your code, to handle a button which is pressed...
0 Kudos
Message 6 of 11
(4,067 Views)

Pnt,  I spent today playing around.  I'm convinced that I just can't get an accurate time from the loop timer.  I switched to the system clock and seem to be making progress.  Depending on my +- range selection in the Idle state, I can control how accurate my loop time is.  Still not confident, I will have to work more on this.

 

 

 

Download All
0 Kudos
Message 7 of 11
(4,061 Views)
Perhaps you should look at this KnowledgeBase.
Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 8 of 11
(4,053 Views)
Hi Jon,  I'm actually using the cRIO timed loop, synched to the scan engine.  Not sure if that is a hardware clock but it is much better than XP.  I didn't post that because I'm sure a lot of people don't have an cRIO system handy.  I simply could not find a state machine example from NI that switches states based on time.  Anywhere.  So I'm kind of making this up as I go.  I think, in the end, I'm going to have to create some kind of fudge factor and run some states for 59 seconds, some for 61 seconds etc... to make the total elapsed time accurate.  Or go with some kind of hardware interrupt clocking mechanism.
0 Kudos
Message 9 of 11
(4,049 Views)

Hello johnnyt,

 

This VI should work much better on a cRIO than on a Windows machine. There is a significantly less amount of jitter on an RT system than on a Windows system. Have you tired to eliminate the local variables in your code.  I would expect the total iteration count to correspond to the total elapsed time and be very accurate.

Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 10 of 11
(3,984 Views)