Sequencer Compare SQC

At the right of a rung in a program's ladder routine. Not in a Logic Class. Placing it creates its control tag.

TagAfter two scans
SQC1LEN 8 POS 1 EN 1 DN 0
SQC1_Actual[0, 0, 0, 0, 0, 0, 0, 0]
SQC1_Data[0, 0, 0, 0, 0, 0, 0, 0]
SQC1_Diff-1
SQC1_Equal1
SQC1_Execute1
SQC1_Reset0

How it works

Each time Execute turns on, compares the first Length steps of the table with the Source array under Mask. Equal is on when they match, and Diff is the first step that differs, counting from 0, or -1 when they are equal. POS moves to the next step at every Execute.

Status bits

The Control tag holds the state. Read a bit with the tag name and a dot, such as Control.DN.

BitMeaning
.ENOn while Execute is on.
.DNDone: on when Execute takes the sequencer past its last step. POS returns to 0, and DN stays on until Execute turns off or Reset is on.
.LENLength: how many steps the sequencer has. It cannot be more than the size of the array.
.POSPosition: moves on at every Execute, from 0 to LEN - 1, and Reset sets it to 0. The compare covers every step, wherever POS is.

Rules

  • Diff counts steps from 0. It is the first step that differs, and -1 when the tables are equal. Equal is on when they are.
  • Equal and Diff change only when Execute turns on. In between, they keep their last values.
  • POS moves on at every Execute, whether or not the tables are equal.
  • A sequencer has no EU, EM or FU bits.

Over time

A FIFO Load with Execute on for scans 2 and 3, off at scan 4, then on for scans 5 to 7. POS moves one step at scan 2 and one at scan 5, each time Execute turns on. Holding Execute on adds no steps.Scan12345678Execute.EN.POS011122222 Execute turns on: one step3 Held on: no step5 Turns on again: next step
ScanExecute.EN.POS
1OffOff0
2OnOn1
3OnOn1
4OffOff1
5OnOn2
6OnOn2
7OnOn2
8OffOff2

The chart shows a FIFO Load; the others act on Execute the same way. One step happens on the scan where Execute turns on. Holding Execute on does nothing more, so turn it off and on for the next step.

How it's used

Use SQC to check a recorded pattern against the pattern now in use. Two copies of the check run here: one on a table that differs, one on a table that matches.

1. Execute. Recipe and Now differ first at step 1, so Diff is 1. Recipe and Spare match, so SpareDiff is -1. POS becomes 1 on both.

StepEqualDiffSpareEqualSpareDiffVerify.POS
1. Execute011-11
2. Turn Check off011-11
3. Execute again011-12

Against [1, 9, 4] the tables first differ at step 1, so Diff is 1. Against [1, 2, 4] they are equal, so Diff is -1. POS moved on at every Execute.

Operands

OperandWhat it is forData typeRead or write
ExecuteA BOOL that makes the instruction act once each time it turns on.BOOLReads
ResetA BOOL that, while on, clears the control tag and starts over.BOOLReads
ArrayThe array holding one value for each step.Array of DINTReads
ControlThe CONTROL tag that tracks the position, length and status.CONTROLReads and writes
MaskWhich bits count: only bits that are on in Mask are used.DINT or a numberReads
SourceThe word compared with the steps.Array of DINTReads
EqualOn when every compared step matches.BOOLWrites
DiffThe index of the first step that did not match.DINTWrites

Common mistakes

  • Comparing arrays of different sizesUse a Source array at least as long as Length, so every step has a value to compare.
  • Rung already true on the first scanA rung that is already true on the first scan after a reset acts once, the same as any other scan where Execute turns on.

Related