Bit Shift Left BSL

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
BSL1LEN 16 POS 1 EN 1 DN 0 EM 1 FU 0
BSL1_Data[0]
BSL1_Execute1
BSL1_Out0
BSL1_Reset0

How it works

Each time Execute turns on, moves the first Length bits of the array up one place. Bit in enters at bit 0, and the bit that leaves position Length - 1 is written to Bit out.

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.
.EMEmpty: on while none of the Length bits is on.
.FUFull: on while all of the Length bits are on.
.DNDone: on once a shift has run Length times (POS equals LEN).
.LENLength: how many bits take part. It cannot be more than 32 for each element of the array.
.POSPosition: how many shifts have run, up to LEN. Reset sets it to 0.

Rules

  • Bit in goes in at bit 0. Every bit moves up one place, and the bit leaving position Length - 1 goes to Bit out.
  • It shifts once when Execute turns on, not on every scan.
  • Bits count from bit 0 of the first element of the array. Bit 31 of one element moves up into bit 0 of the next.
  • Reset clears the bits and Bit out and sets POS to 0.
  • A shift has no EU bit. It has no queue to unload.

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 BSL to follow parts along a conveyor with one bit per position. Length is 4 here, so the track has 4 positions.

1. Shift in a 1. Bit in is 1. It goes in at bit 0 and 1001 becomes 0011. The 1 that was at bit 3 leaves, so Bit out is 1.

StepBeltBitInBitOutTrack.POSTrack.DN
1. Shift in a 1[3]1110
2. Turn Step off, Bit in off[3]0110
3. Shift in a 0[6]0020
4. Turn Step off[6]0020
5. Shift in a 0 again[12]0030
6. Turn Step off[12]0030
7. Shift a fourth time[8]0141

The word went 9 (1001) to 3 (0011) to 6 (0110) to 12 (1100) to 8 (1000). Each shift put Bit in at bit 0 and moved the rest up. Bit out was on after the first and fourth shifts, when a 1 left bit 3. After the fourth, POS equals Length, so DN is on.

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 of DINT words whose bits are shifted.Array of DINTReads and writes
ControlThe CONTROL tag that tracks the position, length and status.CONTROLReads and writes
Bit inThe bit that enters at one end.BOOL or a numberReads
Bit outThe bit that leaves at the other end.BOOLWrites

Common mistakes

  • Setting Length past the arrayLength counts bits: at most 32 for each DINT element of the array.
  • 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