04-21-2018 01:04 PM
My application uses EtherCAT, so it's built around a loop that is timed by hardware, iterating once per millisecond. My program is then implemented as a state machine, changing state within that loop when certain signals indicate. However, sometimes I need to remain in a state for a set amount of time, rather than waiting for a particular signal.
What is the most elegant way of doing this? I could just keep a counter variable, another shift register alongside of my state, but I wonder if there is a nicer way that doesn't need a shift register running all the way across my main loop.little localized operators to say "load timer for 20 ms" and "is timer finished?"
Any ideas?
04-22-2018 06:39 AM
Did I understand correctly that your timed loop runs once per millisecond, and then does whatever State is indicated at that time? Then as long as your program runs for less than 7 weeks (I think that's the right number), the following should work:
Note that you should possibly "cache" the "Replaced-by-Timeout State" so that when finishing the Timeout State, you can (if it makes sense to do so) next do the Cached State. You should also think whether you want to do two "States" in a single Tick, the "Timeout" code + whatever would have next run if the Timeout had not occurred.
Bob Schor