From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timing control of a state machine

I'm looking for some help regarding timing of a state machine, and appreciate any assistance!

 

My states are all used for data acquisition (each state reads different data), but I don't want them to run continuously. I'd like the machine to run at an adjustable rate, say every 2 seconds, or 5 seconds, or 10, etc so I can set a sample rate for data acquisition. Obviously the data isn't all collected at the exact same time since the machine has to move through various states, but for my needs it doesn't matter. The data is sent to a consumer loop for writing to a spreadsheet.

 

I'd also like to be able to bypass the sample rate for stopping the program, and with a user switch or button. So press the button and the state machine skips the delay (sample rate) and runs through the states, then picks back up with the set sample rate.

 

Does anyone know how to do this while using a state machine and a consumer loop?

 

Thanks!!

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

I'd suggest attaching your current VI so we can see what you are doing now.  I can't quite picture what you are talking about at the moment particularly the "adjustable rate" and more so "bypass the sample rate".

 

Is this data acquisition through a DAQ chassis, or something else?  If it is DAQmx, I'd set it for continuous sampling and you can use the consumer loop to decide whether the should be kept or discarded.  If in the state where you read data, if you just read all available data rather than waiting for it to acquire a given amount of data, it will quickly move through that state, do the other stuff, and get back around as fast as the other states allow to get the new data that comes in.

 

But this is me just imagining what your VI looks like.  Please do us a favor and show us.

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

Thanks for your reply RavensFan. I will get some code up soon, I should have done it with my first post.

 

The data acquisition is through a cRIO, it's serial commands between 3 instruments, so each state is a query to the instrument to get the data I want.

 

What I mean by adjustable rate, is I don't really need to be going through these states over and over as fast as possible. I want to get through all the individual states like normal but then pause before cycling back through. Say run the state machine once every 5 seconds, or 10 or even 30. Otherwise it's an unnecessary amount of data for my purpose. 

 

Now this might be a case, like you suggested, where you simply only write the data in the consumer loop every 5, 10 seconds, etc. I'm trying to establish a sample rate that a user could adjust so data in the spreadsheet is in nice intervals of "x" seconds, and x is user defined.

 

What I mean by bypass, is that some states change instrument settings. These states don't run until a user enters a number and flips a switch on the front panel. So if you had a 30 second sample rate, i wouldn't want it to take 30 seconds for the state machine to run and thus 30 seconds to change an instrument setting. Same with a stop button.

 

I will post code to hopefully clarify my rambling. Good luck in the playoffs!

 

0 Kudos
Message 3 of 5
(1,243 Views)

Remember that state machines aren't just state 1 -->>  State 2 -->  State 3--> back to State 1 -->, etc.   You can make decisions as to what state is next.

 

So you can proceed to an idle state that checks how much time has elapsed and keeps returning to it.  And if the time has elapsed, moved to another state.  Or that timing. Could be withing the give state.    State 2 could keep returning to state 2.  If the time has elapsed, then it it can go into a case structure, do what it is supposed to do, then it feed State 3 to the shift register so it moves on.

 

You can use decisions for other things as well.  If you only occasionally need to do a configuration, you move to the configuration state only when you need to, and move to the next operation state directly if you don't need to configure.

 


@Nadweb wrote:

 

I will post code to hopefully clarify my rambling. Good luck in the playoffs!

 


Thanks!  😀

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

I apologize for the delay, but attached is my current VI. As I stated above, I'd like to be able to control how often the states execute so I can set a sample rate.

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