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.
| Tag | After two scans |
|---|---|
| BSL1 | LEN 16 POS 1 EN 1 DN 0 EM 1 FU 0 |
| BSL1_Data | [0] |
| BSL1_Execute | 1 |
| BSL1_Out | 0 |
| BSL1_Reset | 0 |
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.
| Bit | Meaning |
|---|---|
| .EN | On while Execute is on. |
| .EM | Empty: on while none of the Length bits is on. |
| .FU | Full: on while all of the Length bits are on. |
| .DN | Done: on once a shift has run Length times (POS equals LEN). |
| .LEN | Length: how many bits take part. It cannot be more than 32 for each element of the array. |
| .POS | Position: 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
| Scan | Execute | .EN | .POS |
|---|---|---|---|
| 1 | Off | Off | 0 |
| 2 | On | On | 1 |
| 3 | On | On | 1 |
| 4 | Off | Off | 1 |
| 5 | On | On | 2 |
| 6 | On | On | 2 |
| 7 | On | On | 2 |
| 8 | Off | Off | 2 |
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.
2. Turn Step off, Bit in off. Execute is off. Nothing moves.
3. Shift in a 0. Bit in is 0. 0011 becomes 0110. Bit 3 was 0, so Bit out is 0.
4. Turn Step off. Execute is off. Nothing moves.
5. Shift in a 0 again. 0110 becomes 1100. The 1 is now at bit 3, the last position.
6. Turn Step off. Execute is off. Nothing moves.
7. Shift a fourth time. 1100 becomes 1000. The 1 at bit 3 leaves, so Bit out is 1. POS is now 4, the same as Length, so DN is on.
| Step | Belt | BitIn | BitOut | Track.POS | Track.DN |
|---|---|---|---|---|---|
| 1. Shift in a 1 | [3] | 1 | 1 | 1 | 0 |
| 2. Turn Step off, Bit in off | [3] | 0 | 1 | 1 | 0 |
| 3. Shift in a 0 | [6] | 0 | 0 | 2 | 0 |
| 4. Turn Step off | [6] | 0 | 0 | 2 | 0 |
| 5. Shift in a 0 again | [12] | 0 | 0 | 3 | 0 |
| 6. Turn Step off | [12] | 0 | 0 | 3 | 0 |
| 7. Shift a fourth time | [8] | 0 | 1 | 4 | 1 |
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
| Operand | What it is for | Data type | Read or write |
|---|---|---|---|
| Execute | A BOOL that makes the instruction act once each time it turns on. | BOOL | Reads |
| Reset | A BOOL that, while on, clears the control tag and starts over. | BOOL | Reads |
| Array | The array of DINT words whose bits are shifted. | Array of DINT | Reads and writes |
| Control | The CONTROL tag that tracks the position, length and status. | CONTROL | Reads and writes |
| Bit in | The bit that enters at one end. | BOOL or a number | Reads |
| Bit out | The bit that leaves at the other end. | BOOL | Writes |
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.