07-11-2018 11:22 PM
Hi,
I am working on an application that requires me to execute a certain task (turn a motor) every 1 hour for 1 minutes.
Though I am getting my code to run correctly, I can only get it to run once for some reasons.
Can someone help me make it a continuous VI until the user decides to stop it, please?
I am using dummy variables to check if it works (1hr -> 30 s, 1 min -> 10 s and the motors are replaced by LED)
Thanks
07-12-2018 12:49 AM - edited 07-12-2018 12:50 AM
Hi Joel,
build a statemachine with some states:
1. wait for x seconds
2. switch on motor
3. switch off motor
Then it will become easy to fulfill your requirements…
I can only get it to run once for some reasons.
- Well, you compare the elapsed time with some set value: the elapsed time is counting up all the time while your value is fixed. There is only one opportunity to have both equal…
- Comparing floating point numbers for equality often gives unexpected results. There are a lot of threads here on this very topic - read them! (Search for "floating point accuracy".)
- Your outer loop is running as fast as it can: that's the reason why that floating point comparison is working so far. But do you really want to burn a CPU core just to wait for some amount of time?
07-12-2018 09:57 PM
I came across a solution later today.
It does what I want it to do, but I want to make sure that it is a viable and robust enough solution for the application.
Could you look at it? Meanwhile, I will look into statemachines, get familiar with it and come up with something for it.
Thank you for the suggestion.
07-12-2018 10:58 PM
It's not a great solution.
Suppose you set up for a 1 hour loop iteration. Then you decide to stop the VI. It might take up to 2 hours after you hit the stop button, for the VI to actually come to a stop. Not a robust solution.
A state machine can execute much more quickly and can respond to a stop command quickly.
07-13-2018 10:33 AM
I see. I will work on coming up with a state machine and post any concern along the process.
Thank you