Sequences

xzen

Lifetime Supporting Member
Join Date
Jun 2006
Location
Oslo
Posts
97
While programming sequences I usually have each step represented by individual bits. In other cases it makes sense using Integer representation, for example when programming in Structured Text or other scripting languages, using CASE expression.

Sometimes the customer decides. Personally I prefer bit representation and FBD (Siemens) or ladder (AB).

When the sequences becomes complex, we may have parallel branches with AND-divergence, meaning that several steps in the same sequence will be active at the same time. By my opinion this excludes the use of integer representation. I also think it is easier to read online status when individual steps are represented by individual bits.

What’s your opinion on this?
 
Last edited:
For the exact reason you pointed out (more than one sequence active at a time), I don't use them (and my bigger customers don't allow them). Each action or motion has its own "truth" or "solve" that allows it to execute. Easy to debug.
 
When the sequences becomes complex, we may have parallel branches with AND-divergence, meaning that several steps in the same sequence will be active at the same time.

I used to use bits for sequencing and would sometimes do diverging/converging sequences. I ultimately decided that the advantages of this were not worth the extra complications they created.

Now I usually use integers for sequence tracking (in ladder). I initially increment all my steps by 10 to allow for insertion of steps in the future (not possible with bits). I also select integer ranges based on the portion of the sequence:
0 = sequence not initialized
1-99 = initialization steps to reset actuators, servos, etc.
100 = sequence initialized and ready
200+ = main operating sequence, return to 100 when done

When I need to do a diverging sequence as you mentioned, I just use another integer to create a sub-sequence. I find this easier to troubleshoot compared to bit-driven sequences.
 
I'm a fan of SFC (grafset) for when the sequence starts getting complicated. Graphical, and you can have multiple branches if needed, without having to worry about accidentally having multiple bits active where it doesn't make sense.
 
There was only one company that I worked for that allowed us to use sequencers, and when the individual that used them left, I was left fixing the mess he made.
We do not use or allow sequencers period. No one in maintenance understands them or how they work and when you are the one on call for the month, 2 am calls gets really annoying.

james
 
I'm with James. Keep it simple, stay in bed ;)

I tend to use bit representation for each step, although integer is fine as well - just a personal preference. If it gets too complex, I start trying to split it out into multiple sequences - for example, I did one machine that had a raise/lower, a rotate CW/CCW, and an extend/retract. There were a LOT of different combinations as to how it had to run, depending on both switches that were set before the sequence started, and also sensors that would either be in place or not, so the decision was made mid-sequence when the sensor was either triggered or not triggered. Each of the three actions above had their own sequence, and there was a "global" sequence to trigger each of the individual motion's sequences. Sure, it meant that there were now four sequences to look at, but it made troubleshooting super easy because you just said "OK, it should be raising here and it's not", and you go look at the raise/lower sequence. Which is now very simple and easy to follow, seeing as it's only sequencing one thing.
 
we use SFC for our state machines. Could just as easily use an INT, but the SFC makes it crystal clear and obvious which states can go to which states, whereas with an INT it gets written to in multiple places and if it happens to get the wrong value all the sudden the machine can want to be doing the wrong thing.

if your application can transition from any state to any state then the SFC isn't much help.

The reason I don't use bits in a byte is to avoid having multiple states active at once by accident.

we avoid writing code inside the SFC transitions and just use bools written from normal PLC logic to trigger the transition between states. code inside the transitions makes it hard to read the whole sequence at once to see how it works, too much opening of windows.

I have seen one program that was totally driven by the SFC, it used "actions" and timers built in to the steps. It took a couple weeks to figure out how to modify it to fix a problem with the turbine spinning backwards after shutdown.
 
my two cents.
when changing states, change the state of a nxtStepTag so that every step at least gets one scan.
Then, copy the nxtStepTag into StepTag before solving step logic.
 
I am not a fan of sequence control logic using bits to represent the sequence stages.

Using an integer "step" or "stage" number has some unique advantages....

1. The sequence can only have one step or stage active at any one time, because the "step-number" tag or register can only hold one value. Manipulating a bunch of bits will inevitably be more complex than using a value from an integer tag or register. How do you ensure that only one bit is on ?

2. Sequence control is easier. You can have a "step-on" bit in your sequence logic (which will most certainly need to be an OTL in A-B speak), or you can easily have a "step-jump" tag or register that you MOV a new step-value to.

3. The sequence logic can be more easily described in the functional specification, and vice-versa, the functional specification can more easily describe the logic.

4. The sequence "control logic" is identical for all sequences, can be written as a subroutine and called for multiple sequences, or in the A-B world the sequence control logic can be (which I approve of) an AOI.

5. A numerical sequence allows easy control of the sequence during commissioning and troubleshooting. In many applications I have worked on, I have had to put the sequence into a Hold condition, make some changes to the logic, revert the sequence to a particular step number, just by changing the value in the sequence "step" register, and restart it. The sequence restarts at the new step just as if it were running as normal.

6. All the maintenance people I have worked with have loved it, on every rung of the sequence they can see what step number or stage the sequence is at, and can relate that directly to the functional spec.

7. A numerical sequence can have up to 2,147,483,647 steps or stages (using a single 32-bit signed integer), enough for most people. How do you decide how many BOOL bits to create ? (I'm assuming you'll be using bit arrays to be efficient). Inevitably you'll create far more than you'll ever need (or think you will), but that just wastes memory if you don't need the "extras". What happens if you need to extend the number of bits during commissioning when you can't shut the process down for a download ?

8. I may need to do a bit of extra sequencing, say 20 or so steps, in the middle of the sequence. This isn't a problem with a numerical sequencer, I can simply jump to step (say) 800, do my new steps, then jump back. The sequence control logic or AOI handles everything I throw at it, so that doesn't need to be revisited.

9. A numerically driven sequence will survive "as is" if the power goes off, because the values in numerical tags or registers are usually "retentive", standard "bits" are not. In the A-B world we do not have separate "retentive" and non-retentive" memory - everything is retentive, but a pre-scan will reset bits that are not programmed as retentive (by using OTL and OTU).

10. The current "step" or "stage" can easily be displayed on the HMI or SCADA if desired, not so easy if using bits to regulate the sequence.

11. Outputs can easily be driven using LIMit instructions, eg. ...

Functional Spec...
Step 15 : "Open Coolant Valve V107"
Step 39 : "Close Coolant Valve V107"

Code...
LIM 15, Step_Number, 38, OTE Seq1_V107_Slave

How do you achieve that using bits ?
How do you keep the valve open for steps 16 to 38 ?

I have yet to see a "bit-driven" sequence offer the simplicity and robustness that a "numerically driven" sequence can deliver, but I'm thick-skinned enough to be re-educated.
 
Sure, it meant that there were now four sequences to look at, but it made troubleshooting super easy because you just said "OK, it should be raising here and it's not", and you go look at the raise/lower sequence. Which is now very simple and easy to follow, seeing as it's only sequencing one thing.

I'm with you on that one, if the different pieces are independent, it would be way easier and more flexible to keep them separate.
 
Definitely good points, and I do think that using integers is a good approach - just not my favourite. Here's my take on your points, just in case you're interested. Not trying to "re-educate", just trying to show the other side of the coin :) it should be noted that most of my sequences tend to be smallish - never more than 32 steps, so I've never had to use anything more than one DINT for a sequence. If you have more steps than that, integers do start to look more attractive, even to me ;)

daba said:
1. The sequence can only have one step or stage active at any one time, because the "step-number" tag or register can only hold one value. Manipulating a bunch of bits will inevitably be more complex than using a value from an integer tag or register. How do you ensure that only one bit is on ?
I do this by using a CLR instruction right before the OTL instruction. Sure, it relies on the programmer to do that every time, but once the code is commissioned, no problem. But then as you say, it's physically impossible to have two values in an integer, so in all fairness your method does slightly have the upper hand here.

daba said:
3. The sequence logic can be more easily described in the functional specification, and vice-versa, the functional specification can more easily describe the logic.
I disagree with this one. "Step 5" can just as easily mean "Bit 5" as "Value 5". I also like the fact that you can individually comment each bit - so when I just to Step 6, there's a comment attached to that OTL describing what Step 6 does. You can't do that when MOV'ing a value into an integer.

daba said:
4. The sequence "control logic" is identical for all sequences, can be written as a subroutine and called for multiple sequences, or in the A-B world the sequence control logic can be (which I approve of) an AOI.
Couldn't you do this equally either way?

daba said:
5. A numerical sequence allows easy control of the sequence during commissioning and troubleshooting. In many applications I have worked on, I have had to put the sequence into a Hold condition, make some changes to the logic, revert the sequence to a particular step number, just by changing the value in the sequence "step" register, and restart it. The sequence restarts at the new step just as if it were running as normal.
This can also be done using bits, just by toggling on the required bit. Or if you must toggle one bit off and another bit on at the same instant, you can just move the respective value into the DINT as a whole - e.g. if you need step 2, set the DINT to 2^2=4. Sure, it's not quite a s simple as doing it using integer steps, so you again win out slightly here - but it's still doable.

daba said:
6. All the maintenance people I have worked with have loved it, on every rung of the sequence they can see what step number or stage the sequence is at, and can relate that directly to the functional spec.
Ditto :ROFLMAO:

daba said:
7. A numerical sequence can have up to 2,147,483,647 steps or stages (using a single 32-bit signed integer), enough for most people. How do you decide how many BOOL bits to create ? (I'm assuming you'll be using bit arrays to be efficient). Inevitably you'll create far more than you'll ever need (or think you will), but that just wastes memory if you don't need the "extras". What happens if you need to extend the number of bits during commissioning when you can't shut the process down for a download ?
True - this one is definitely a winner. As I mentioned, most of my sequences are quite small - if you've got less than 20 or 25 steps you'll never have a problem, but if you have more than that - yes.

daba said:
8. I may need to do a bit of extra sequencing, say 20 or so steps, in the middle of the sequence. This isn't a problem with a numerical sequencer, I can simply jump to step (say) 800, do my new steps, then jump back. The sequence control logic or AOI handles everything I throw at it, so that doesn't need to be revisited.
You can just as equally do this with bits - just jump from bit 3 up to bit 21 and then back down. Again, longer sequences are a different ballgame, but for shorter sequences, no problem.

daba said:
9. A numerically driven sequence will survive "as is" if the power goes off, because the values in numerical tags or registers are usually "retentive", standard "bits" are not. In the A-B world we do not have separate "retentive" and non-retentive" memory - everything is retentive, but a pre-scan will reset bits that are not programmed as retentive (by using OTL and OTU).
If you're using bits in a DINT, they're just as retentive as the DINT you're using for your step integer. That being said, in most sequences I find that after a power failure, the most desired result is to abort the current sequence and return to the home position, so it seems a moot point. That again depends on what kind of sequence you're driving though.

daba said:
10. The current "step" or "stage" can easily be displayed on the HMI or SCADA if desired, not so easy if using bits to regulate the sequence.
Quite easy! In AB land you can select the LSB for your multistate indicator instead of the value - for any other visualisation solution that doesn't have that option, there's a simple calculation to convert a bit position to an integer - it's been a while since I've done it so I don't remember it exactly, but it's basically the reverse of 2^[Step Value]. I think Log 2 or something...

daba said:
11. Outputs can easily be driven using LIMit instructions, eg. ...

Functional Spec...
Step 15 : "Open Coolant Valve V107"
Step 39 : "Close Coolant Valve V107"

Code...
LIM 15, Step_Number, 38, OTE Seq1_V107_Slave

How do you achieve that using bits ?
How do you keep the valve open for steps 16 to 38 ?
True - that one IS easier with integer step values. You CAN still use LIM's and just put them in as binary: LIM 2#0000_0000_0001_0000, StepBitDint, 2#0000_0100_0000_0000 will keep the valve open for steps 4 through 10, for example. Or you can use my Log 2 trick above to give yourself a integer running alongside in paralell to use for things like this. But yes, a little more complex.
 
I'm w/daba. Integer designation just flows better across the scope of a project.

Function Description: "Step 10"...

HMI Display: "Step 10"

Data logging/tracking/reporting: "Step 10"

Talking with operators when there is a problem "It was on Step 10 and got stuck..."

Why in world a programmer decides to convert to bits or hex at this point is beyond me. I understand 20 years ago, but today not so much. Recently I was troubleshooting a program that used bits, but displayed the step number in hex. HMI didn't have any indication of the sequence and there was parallel and divergence which were not needed at all. This was a simple process but a convoluted sequence engine.

I also agree that steps of a sequence are exclusive and only one can be active at any given time. If you need more, then add another sequence engine to drive it (or create another step for the conditions required). Keeps the logic nearly identical and once you understand how one engine works you understand them all.
 
I prefer using bits for individual steps. For instance you maybe in an overall starting mode, but there are sub-steps that are helpful to indicate during that starting process. Just indicating "starting" doesnt give very helpful feedback to an operator or for historical troubleshooting purposes.
 
I am on Team DINT when it comes to sequences, mainly because it stops me from going "oh, I want to be in step 40, I'll turn on bit 40" and then the sequence is in two states at once.

I also find the visual layout appealing, having an EQU displaying the actual state on each rung, and then a single MOV instruction instead of a CLR and an OTE. Definitely a fan of the zoom out function :D
 
I prefer using bits for individual steps. For instance you maybe in an overall starting mode, but there are sub-steps that are helpful to indicate during that starting process. Just indicating "starting" doesnt give very helpful feedback to an operator or for historical troubleshooting purposes.

Forgive me but your example doesn't make much sense to me.

"Starting", as you have said implies a mode or state the machine is in, not a sequence. This screams bits to represent each mode or state. Within each mode/state you have a sequence that occurs. Or you could have 1 sequence, where steps 0 - 10 make up your "starting" mode, steps 11 - 20 your "running" mode, steps 21 - 30 your "stopping" mode...etc.

I can see on a large complex system having a master sequence of "Step 1 - Starting", "Step 2 - Running", "Step 3 - Stopping"...etc which is a sequence but really used to track state. Each of these kick off their required sub-sequences. Thinking about it, this example seems to be a good justification of integer:

Code:
// Using code formatting for clarity

Step 1 - Starting
    Step 10 - "Starting Step initialize"
    Step 11 - "Starting Step #1"
    Step 12 - "Starting Step #2"
    .
    .
    .
    Step 19 - "Staring Step #9"

Step 2 - Running
    Step 20 - "Running Step initialize"
    Step 21 - "Running Step #1"
    Step 22 - "Running Step #2"
    .
    .
    .
    Step 29 - "Running Step #9"

Step 3 - Stopping
    Step 30 - "Stopping Step initialize"
    Step 31 - "Stopping Step #1"
    Step 32 - "Stopping Step #2"
    .
    .
    .
    Step 39 - "Stopping Step #9"
Of course you can use bits in my example, but again for fluidity across the PLC/HMI/Documentation, integers are very clear. Even in this case, you have multiple sequences occurring but each is exclusive and identifiable simply by the integer step number.
 
Last edited:

Similar Topics

Hey guys, A couple of quick questions but first a layout of what I'm working with. Compactlogix 1769-L37erm controller. The current system we...
Replies
2
Views
1,221
Hi dear programmers, Im a newbie in plc programming, i start using s7-graph to program a palletizer i wrote a typical program but im facing a...
Replies
3
Views
3,107
Hi all! I have one question: How do i create in a STEP7 GRAPH object in which more than one (2,3...) sequence running? Thx!
Replies
7
Views
1,916
Dear all, I would like to do several logical sequences to do implement in an auto mode using fbd for exemple : 1 move motor forward until stop...
Replies
4
Views
3,244
I have a uni project to develop a traffic light sequencer for a 4 way junction (with filter lights and pedestrian crossings...). Is there any...
Replies
18
Views
6,927
Back
Top Bottom