[Logix] Controlling a sequence with a "state machine"

defcon.klaxon

Lifetime Supporting Member
Join Date
Feb 2015
Location
Far NorCal
Posts
616
Hi guys,

I have a sequence for my water treatment units and I'm running it with a "sort of" state machine. I say that because I'm not sure if this technically qualifies, but that's at least what I was going for. Here's how it works:

Upon first scan, clear all bits in a "state" DINT, then set bit 0 (offline state). When the filter is called to run, reset bit 0 and set bit 1 (start up state). Once start up is done, reset bit 1 and set bit 2 (filtering state). If I'm running a clarifier flush it's bit 3 through 8 (depending on step), and if I'm running a filter backwash it's bit 9-13 (again, depending on step).

My sequence is a big ladder logic routine, with the "state" bit in front of each rung; thus, they only energize if the state is set. It actually works quite well but one problem I came across today is, each state isn't exclusive and that could really mess things up. I was in the final stage of a backwash (step 13), and long story short I made an HMI change that resulted in the start up bit (bit 1) being set simultaneously.

What I need to program in is some sort of exclusivity, so that only one bit can be set at any time. I'm trying to figure out the best way to do this but I'm not sure the best way to go about it. Is there some sort of XOR function I could do, or some sort of bit mask? I'm guessing the solution is pretty straightforward but I'm not sure of what the most elegant, efficient solution would be.
 
Simple.
When activating a state, instead of reset just the bit of the previous state, write a zero to the entire DINT, then finish by activating the bit of the new state.
 
Simple.
When activating a state, instead of reset just the bit of the previous state, write a zero to the entire DINT, then finish by activating the bit of the new state.

Thanks for the reply. Right now when I transition a state, I unlock the set bit, and lock the next bit. I'll add the "clear DINT" command and that should help for transitions.

To go one step further, what if I wanted to prevent additional states from activating when in the middle of one of the states? This is more of a thought experiment at this point (since all my state transitions are controlled by logic), but let's say I was in state 13, and about half way through the timer. How would I prevent another state from activating simultaneously (like if there was a program bug)? In other words, how would I ensure that only one bit at a time could be set, and all others would be kept at 0? I'm not sure if I'm putting this question into words, let me know if I'm not being clear.
 
I usually use a DINT with values 0, 10, 20, 30... and so on for each state. That guarantees only one possibility at a time. I use increments of 10 instead on increments of one in case I need to add a step in the middle later (0, 10, 20, 21, 30...). Then just use an EQU statement on each line to choose what logic to run.
 
I usually use a DINT with values 0, 10, 20, 30... and so on for each state. That guarantees only one possibility at a time. I use increments of 10 instead on increments of one in case I need to add a step in the middle later (0, 10, 20, 21, 30...). Then just use an EQU statement on each line to choose what logic to run.

This is what I do for anything that needs a sequence. This works out really well. It works well for restarting midcycle if there was some sort of a problem.
 
+1 what has been said about integers.

Never use flags for something that can have only one state at a time.

Integers also makes it easier to show status on a HMI or to jump to a specific state when testing the program.

If you use a second integer and compare it to the first integer you can detect a state change. For instence if you have one timer to show the amount of time spent in the current state.

In pseudocode:
Code:
if current_state <> old_state then newstate=true else newstate=false
old_state = current_state
Every time the state changes the newscan flag will be set (for one scan).


PS. Another obvious reason for integers (over bits) is of course the amount of states you can have. No need to use a DINT, you can use a SINT (8-bit) and have 256 possible states.

.
 
Last edited:

Similar Topics

Hi, Getting some hands on training and putting together a Micrologix 1100 trainer that that will be used to control DeviceNet DrIves and Valves. I...
Replies
8
Views
1,614
Well mis-communication has lead me to a point where my micro is no longer the proper controller for the application its currently being utilized...
Replies
0
Views
1,431
So I have an ABB ACS880 drive with a built in ethernet module, the FENA011. I'm using a Controllogix processor to control it via the ethernet...
Replies
6
Views
3,785
Hello! I need to control a sinter moisture in a mixing drum. I have a moisture meter with analog output 4-20 mA connected to analog input of PLC...
Replies
5
Views
4,643
All, I am setting up some systems and am trying to utilize BOOL Inputs on my CompactLogix to trigger a change in frequency command on a PowerFlex...
Replies
5
Views
2,012
Back
Top Bottom