Sequencers

randy

Supporting Member
Join Date
Apr 2002
Posts
158
This is in regards to Sequencers on the Allen-Bradley SLC-500. I would like to have a better understanding of the Mask function. Can someone gave me some examples? Also the Control element function. And just one more question, Way the pound sign before the file number?

Thanks
 
Randy,

A "MASK" is simply a way to "Filter" information.

Some input-data comes in and the program looks at it through a filter (think, Rose Colored Glasses - making the world look Rosy).

The program responds to the "filtered-data" as you have designed the program to respond.

You define the content of the filter (mask) and then define how the filter (mask) is applied. There are several ways to apply the filter; AND, OR, XOR, NOR... the types available generally depends on the functions available from the PLC. However, even if your PLC doesn't have an XOR Function, you can produce the same effect by data manipulation.




INPUT: DCBA
DATA: 1010 1010 1010 1010

MASK: 1001 1001 1001 1001

METHOD: AND OR XOR NOR

RESULT: 1000 1011 0011 0100




Now, as to what you can do with this "filtered-data", it depends on your situation.

Now, assuming that the "DATA" represents a group of Inputs, you might, in general, always pay attention to the state of each. However, in some circumstances, you might say, "I need to ignore Input-B and Input-C in this particular case".

So you create a mask = 1001 and apply it using the AND Function. The result shows only the conditions of Input-A and Input-D.

Masking is not a common thing to see in most PLC programs... but it is a tool that is available when you need it.


I'm not that "up" on AB anymore, but I think the "Control Element Function" you are referring to is the "trigger" that causes a sequencer to move to the next step.

Some sequencers are "Event-Based", some are "Time-Based", and others are both, "Event/Time-Based".

In the "Event-Based" model, once the sequencer is initiated, the sequencer simply looks for the state of a particular bit. The sequencer might be looking for the bit to be ON or it might be looking to see the bit is OFF. This is defined in the Sequencer structure as you have defined it.

In the "Time-Based" model, once the sequencer has been initiated, the sequencer remains at each step for the amount of time that you have specified before proceeding to the next step.

The "Event/Time Based" model is a combination of both.

With respect to the "#" sign, in some circles that means "HEX".
 
Just to supplement what Terry said, the AB uses an AND mask in the SQO (and all other masks, such as MVM (MoVe with Mask)

The control element (R6:0) is used to track how many steps the sequence has (R6:0.Len), what step it's currently on (R6:0.POS), and some other sundry bits (.EN, .DN) that you can use.

The SQO increments the current step each time it gets a low-to-high transition (just like a counter) The instruction must go back to low before it will increment again (just like a counter).

It moves the bit pattern in the File Number, offset by the step number, just like an indexed (not indirect) addressing.

If you are familiar with non-AB PLCs which allow Function Block (FB) programming, (especially those that allow you to create your own FBs), then the SQO
 
+-------- SQO ---+
--| File: #N10:0 |
| Mask: N11:1 |
| Dest: N11:0 |
| Control: R6:0 |
+----------------+


is exactly the equivalent of the following code:

CTU R6:0 (yeah, you can't use a Control with a counter, but there's no logical reason why not - both are 3 word elements, with the same bits in the same position (.DN = word 0 bit 13))

MOV R6:0.POS S:24 (the index address register. When the PLC encounters an address preceded by a '#' sign, it reads/writes to the data table address offset by the the value in S:24. If S:24=5, then #N10:3 will address N10:8. The PLC uses S:24 for internal housekeeping of some instructions, like COP (which also require a '#' sign)

MVM #N10:0 N11:1 N11:0

I've rarely found it necessary to use the mask, and am likely to set it FFFF(hex) and forget about it. After all, if you didn't want the bit to move from the source to the destination, you wouldn't have put it in the source in the first place, right?

But you could use if for all sorts of things. Permissives come to mind. Lets say that on step 5, you want to have a pump run and a valve open ("Step 5 - Refill tank"). But you don't want the pump to start until after the valve is open (i.e, you don't want to run the pump dead-headed). The bit in the mask that corresponds to the pump would only be set when the valve is open. You wouldn't make an extra step ("Step 5 - open valve, step 6 - keep valve open and start pump"), just a single step with built-in permissives.

This leads to a PLC program that gets a little "spooky", in that it starts to do the right thing, even though you didn't specifically program it. For example, if you were to lose plant air, and the valve were to close in the middle of the operation, the permissive gets lost, and the pump shuts down. But you didn't specifically program that function, it "just happens".

If you write your code with lots of these small algorithms, the code starts to act intelligently, much like those robotic insects that have the algorithms "Get Food" and "Don't fall down" - they succeed in overcoming obstacles that they aren't specifically programmed to handle.

There are a few other tricks with the SQO instruction: Because they act like a MVM, it helps if you can leave them in an enabled state. That way, if you need to make them jump ("On E-Stop, go to step 0"), you can just move a value into the control .POS word, and the destination word will have the correct bits. Similarly for a semi-automatic Advance 1 Step" and "Go Back 1 Step". That means you must program a high-to-low-to-high transition for each step.

Search through the archives for others - the topic's come up fairly frequently.
 
Masking

Terry & Allen,

Close but no cigar!

The SQO & MVM instructions in AB PLC's are not simple AND operations. The function is:

source_data AND mask OR output = output

  • when a source bit coincides with a '1' in the mask, then the corresponding output bit = source bit
  • when a source bit coincides with a '0' in the mask then the corresponding output bit is not changed

This is useful if you want to sequence a group of outputs that doesn't take up a whole 16-bit word. You place 1's in the mask corresponding to the controlled outputs and 0's corresponding to the outputs that you wish to control some other way.
 
Ooops!

I wrote in haste and didn't get the function expression quite right - the description, however, was correct.

(source AND mask) OR (old_output AND (NOT mask)) = new_output

....makes a difference.
 
Randy, I think that on your first attempt to use a an AB Sequencer you should think of a control register(R6:?) as the working part of the sequencer that keeps track of everything. Each sequencer needs it's own R file so dont assign the same R file to different sequencers. Then after you get a grip on the sequencer you can start to play with manipulating the R file.
 
If you learn something new every day, this is what I learned today.

Gerry, you're right about how AB does it's masks.

Mask is not the same as an AND. That's why they use differnt words.

Which I know, when I think about it - that's why I use a mask, to leave the bits that don't correspond to the mask unchanged (OFF or ON).

I've seen Terry's description of MASK before, and I just didn't give it any critical thought. I should have. Even Terry Woods can make mistakes, and he did.

I am right that the SQO is essentially a CTU + MVM.
I was wrong that it would be useful for permissives.
Loosing the bit in the mask would not turn off the bit in the destiniation, it would just leave it in the last state. While this could be useful, it wasn't what I had intended.

As shown below, when the Mask bit is set, whatever the Input bit is set to overwrites the Output.
When the mask bit is not set, the output remains unchanged.

Original Final
Input Mask Output Output
0 ===> 1 ===> 0 ===> 0
1 ===> 1 ===> 0 ===> 1
0 ===> 1 ===> 1 ===> 0
1 ===> 1 ===> 1 ===> 1

0 ===> 0 =X=> 0 ===> 0
1 ===> 0 =X=> 0 ===> 0
0 ===> 0 =X=> 1 ===> 1
1 ===> 0 =X=> 1 ===> 1

 
SQO's and MASKs

The following analogy may help our newcomer friends visualize how the SQO operates. For those of you who are already familiar with this type of instruction, you probably have much better things to do than reading this rather lengthy post. If you want to play along with the instructions which follow, you may have to reassign the input and output addresses to match your particular hardware.

Let's try to get a handle on the SQO by analogizing it to a wind-up music box. In the music box, a series of metal bars are arranged in a row. Each of these bars produces a different note when it is plucked. A cylinder is fitted with many little pins and, as the cylinder turns, the pins pluck the note bars. The order in which the pins are placed on the cylinder determines the song which the music box will play.

Now for the setup of the SQO. In an effort to keep our discussion as straight-forward as possible, we'll skip around a little as we make the entries for the SQO instruction. First, for the "destination" we'll use an output word (ex. O:3.0). The bits in this word could be thought of as the little note bars in the music box.

Next, we'll set up the "file" as a series of words in a binary file (ex. #B9:0). Incidentally, the # in front of an AB address denotes "indexed addressing" but may be thought of, for this exercise, as simply meaning "start here". For this example, suppose that the length of the SQO is set to 6. Big surprise! The SQO requires ONE MORE word than the length setting. So we'll actually need 7 words in our file. Now back to the #B9:0 file setting. So far the "file" and the "length" entries are telling the processor that the file which "starts here" at B9:0 is 6+1=7 words long - so the file begins at word B9:0 and goes through (and therefore includes) word B9:6. The SQO's "file" could be thought of as the rotating cylinder in the music box.

Next we'll go to the B9 data table and find words B9:0 through B9:6. For our example, we'll change the radix to "decimal" and enter the following values:
B9:0 = -1
B9:1 = -32383
B9:2 = 16962
B9:3 = 9252
B9:4 = 6168
B9:5 = 9252
B9:6 = 16962
We changed the radix just to make it easier to transcribe the numbers. Now change the radix back to binary and look at the pattern. Little ones are marching back and forth in a pattern which will be interesting to watch on the LED's of a sixteen bit output card. The "-1" entry is the binary equivalent of "turn everything on". This will be our "position 0" and we'll want it to be obvious every time this position comes up. (And naturally you can go back into the B9 file later and set your own bit patterns). The ones that you set in these "file" words may be thought of as the PINS on the music box cylinder. In effect, by setting these bits off and on you are determining the "song" which our SQO will play when we finally run it.

Next, we'll enter FFFFh for the "mask" setting. When we hit the enter key, the software will display this as "0FFFFh". Don't worry about the initial zero, it's only there to confuse you - so just ignore it. The "h" at the end of this setting indicates that this entry is in the "hexadecimal" format. If you convert the remaining FFFF hex number into binary, it comes out 1111111111111111 (or 16 ones). In simplest terms, our FFFF "mask" setting is telling the processor that the SQO is allowed to control all 16 bits in the destination word. A more detailed discussion about masks is included below.

Next, for our example, we'll set the "control" for the SQO at R6:0. To help visualize the function of the control, let's contrast its operation to that of the timers and counters. Specifically, the purpose of a T4 TIMER is to time; the purpose of a C5 COUNTER is to count; the purpose of an R6 CONTROL is to point. In other words, the R6:0 CONTROL element is used to "point" to word B9:0 and then to word B9:1 ... and so on through the "file". This "pointing" operation is the method by which the processor keeps track of its position as it progressively moves forward through the SQO's file. Be careful here. Once we run the SQO all the way from position 0 through position 6, it doesn't go back to position 0 again. Instead it goes back to position 1. Stay tuned for more details.

The last entry in the setup of our SQO is the "position". Set this to zero. In simplest terms, the SQO's "position" setting is sort of like the "accumulator" setting for a timer. We always start out with the timer's accumulator set to zero and the processor takes care of it from there. As the SQO advances through the file, the processor will change the SQO's "position" reading to tell us how far along through the file we've come.

Now as for the pushbutton in front of the SQO. A real-world application usually involves a timer "done" bit to automatically pulse the SQO through its file. The button in our example will allow us to monitor the operation of the SQO in slow motion.

Now we're ready to execute the SQO. Download the program and put the processor in the RUN mode. Look at the output word. Assuming that this is the first time you've executed this program, all of the bits should be off. And notice that the "position" setting of the SQO is at 0. Even though the SQO is still in its position 0, it hasn't really moved any data yet. The outputs are still all off. We set all of the bits to ON in the 0 position "file" word (B9:0) to make this fact more obvious. In fact, if you really want the SQO to move its 0 position data, then you'll have to jump through some extra hoops (covered below).

Next push the button to advance the SQO to position 1. Notice that now the output word O:3.0 changes to match the bits which you set in "file" position 1 (B9:1). Each time you push the button, watch the bits in the output word march to a new position. The "tune" which our music box is playing was set up by the ones and zeros we placed in the words of the B9 "file". Pay careful attention to what happens when the SQO reaches the LAST position (position 6 in our example). The next push of the button takes the SQO back to position 1 - NOT to position 0 as you might have thought. And so the LED's on the output module continue to march.

So what good is an SQO anyway? Well, suppose you had a large number of solenoid valves to turn off and on in a certain predefined but rather complicated sequence. (Think of the dancing fountains at Wally-World). The ladder logic to accomplish this could become quite convoluted to write. But with the SQO, the ladder logic might easily be resolved down to just two rungs with a total of four instructions.

For more fun with SQO's: try changing the flashing pattern by storing additional bit patterns in other file locations. Then copy these files into the B9 area with a COP instruction. This allows you to change the tune on your "music box".

Try the SQC (Sequencer Compare) instruction. This can be used to condition the SQO's rung so that the outputs won't advance until a certain pattern of input conditions has been met.

And how about the bits we left in the "file" word at position 0? In NORMAL operation, the only way the SQO sends out this 0 position's bit pattern is if the SQO is reset to position 0 (an RES instruction is the obvious way); AND the rung with the SQO is false when we go to PROGRAM mode; AND the rung with the SQO is true on the first scan when we go back to the RUN mode. You'll definitely want to do some experimenting before you try to use this one in the real world.

Try a different mask (after reading below) and see what happens to the output word.

Something to watch out for: Resetting the SQO doesn’t automatically change the bits in the output word. The SQO doesn't actually send out a different pattern until its rung transitions from false to true.

So just what is a "mask" anyway? (This is good to know because many other instructions besides the SQO use masks). Remember that the output of the SQO is always a word (that means a full 16 bits in a row). But suppose that we only wanted the SQO to control SOME but not ALL of the bits in the destination word. (Maybe we're going to control the other bits with regular old ladder logic). Without a mask, the SQO would always overwrite the ladder logic control for these particular bits. BUT we can set some of the bits in the mask to zeros. Any ZERO setting in the "mask" will "hide" its particular target bit from the SQO. The SQO would ignore the ON/OFF status of this particular target bit and leave it unchanged. Any ONE setting in the "mask" will "enable" the SQO to control the ON/OFF status of its particular target bit. In our example, the "FFFF" setting lets the SQO take control over ALL 16 of the bits in the destination (output) word.

Tip for beginners: Suppose you're reading through a program and run into an MVM (Masked Move) instruction with a mask of "0D4E7h". How would you figure out what this mask means? First, ignore the initial zero and also drop off the final "h". Next, go to an UNUSED word in a binary file and set the radix to Hex/BCD. Type in D4E7. Now switch the radix back to binary. In this example, the bit pattern should come out 1101010011100111. So this particular MVM will move the contents of the Source word into the Destination word - BUT the ONLY source bits which will be moved are the bits which are "enabled" with ones in the mask. The bits marked with zeros in the mask will be "hidden" and so the bits in the destination word at these positions will NOT be affected by the MVM instruction. And incidentally, you don't need a processor to do this handy "mask-to-bit" conversion - the RSLogix software will do this even if you're offline.

Finally, go to: www.ab.com/manuals/cp/1747-rm001c-en-p.pdf

This is the Instruction Set Reference Manual for the SLC and you should certainly become familiar with it. Look on page 7-6 for more details on the SQO.

Sorry, out of post room.

Best regards.
 
That was interesting Ron. A small tip for others with masks in AB. If you type the mask in as binary (0011101000110110 for example) then type a "b" after the last digit (0011101000110110b) then RSLogix will convert the binary value to the Hex for you. Regards Alan
 
SQO

Excellent explanation of the SQO Ron.
Thanks Alan for the tip on entering the Binary code and then the letter B to convert it to Hex.
This is the kind of information that makes me come back here faithfully.
 
I would like to thank everybody that has participated in my pursuit for information in regards to sequencers used in the AB SLC-500 PLC’S. This truly has helped me to understand the fundamentals and applications of sequencers. This certainly makes live a lot easier in the PLC world.

Randy
 
Little known trick about SQOs (and many other commands, for that matter):

Click on the SQO.
Right Click, and select "Display Special"

You'll get a view of the destination, and the entire sequence in Bit-wise form. You can even edit the bit pattern here. Handy if your destination is in a different data table than your source file.

FWIW
 

Similar Topics

Hi All, I need some clarification on sequencers, I researched this forum but haven't been able to find a good explanation, including the ones...
Replies
10
Views
5,287
I am trying to program the traffic control simulation on logixpro using sequencers. I have done the previous simulations with the stop light but i...
Replies
1
Views
1,909
First of all, I want to thank everyone for all the help on previous questions. My new job is proving to be a challenge (in a good way)and your...
Replies
10
Views
5,231
hi, I looked on google and faq but with no result.. My questions are: -how do i call a subroutine from structured text? -i was looking at the...
Replies
3
Views
2,087
I was wondering how I might go about using my sequencer in such a way that I can set a time at each step or positon in the sequence. What will be...
Replies
1
Views
1,710
Back
Top Bottom