LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with my timed state machien

Solved!
Go to solution

Hi all,


The project

I'm trying to create a timed state machine that can cycle through a series of cool-then-heat cycles, where each cool or heat function happens for a specific length of time.
For example, if I set the number of cycles to 20 'cool-then-heat cycles', with a cool cycle lasting 10 seconds and a heat cycle lasting 10 seconds, the programme will run for 400 seconds and then stop.

Upon initialising a clock will begin. In the cool loop, there will be a cool clock which will be compared to the set cool cycle time. If they are noto equal, cooling continues, if they are equal the programme progresses into a heat cycle.

The heat cycle has an heat clock which will be compared to the set heat cycle time. If the hot clocks are not equal, heating continues, if they are equal the heat cycle is over and proceeds to either finish or running into another cool cycle.

Another cool cycle is only selected if the elapsed time (since state machine was initialised) matches the total programme run time (i.e. total time = 400 seconds).

(I've also attached a state machine drawing which explains the process I want diagrammatically).

The problem


I have a few but the first one is I think I'm using the wrong timing block- in my VI, the tick clock does not start from zero when I press run. I included it in a while loop as am I right in thinking it will be easier to run (for the computer) if I set a delay (without delaying the state machine functions). Rather than starting from 

I have a little calculator that determines how long the total run time will be (this value is compared against the elapsed time since initialisation).

If anyone spots anything else that need sadjusting let me know- I'm very new to labview and want to pick up good practice along the way!


0 Kudos
Message 1 of 7
(3,694 Views)

Can't open your VI here, but you seem to be barking up the right tree.

 

Tick count gives a time since the machine booted, so you are correct in that you have to compare time differences. Don't look for exact equality in times as a state change trigger - use 'if current time>=required state exit time then exit state' to avoid the possibility of getting stuck if you don't poll the time at the right millisecond.

0 Kudos
Message 2 of 7
(3,687 Views)

@ToeCutter wrote:

Can't open your VI here, but you seem to be barking up the right tree.

 

Tick count gives a time since the machine booted, so you are correct in that you have to compare time differences. Don't look for exact equality in times as a state change trigger - use 'if current time>=required state exit time then exit state' to avoid the possibility of getting stuck if you don't poll the time at the right millisecond.





Okay so if it's time since machine booted then how do I get a timer that starts from 0 the moment I start running my state machine?


Does this work uplpoad work?

Download All
0 Kudos
Message 3 of 7
(3,674 Views)

Get the tick count right before you enter the state machine- this is your 'zero' count. Subtract this zero count from the current count to get the time since the machine started.

 

Alternatively, calculate everything in terms of absolute tick counts, e.g. if I enter state a which waits 10s, it will need to exit at a tick count of ('entry tick count'+10*1000). Calculate this required exit time once when you enter the state, then just compare it with the current tick count to poll for exit time.

0 Kudos
Message 4 of 7
(3,665 Views)

I don't quite follow what you mean? How would I set this up (do you have any examples?)

0 Kudos
Message 5 of 7
(3,625 Views)

Sorry I don't.

 

You understand the concept- the count returns the time in milliseconds since the computer was on. Subtracting one count from another gives you the elapsed time in milliseconds between when the two counts were taken.

 

 

0 Kudos
Message 6 of 7
(3,618 Views)
Solution
Accepted by topic author rwills

There's also the 'elapsed time' express VI you could use.

0 Kudos
Message 7 of 7
(3,607 Views)