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.