Bit Shift Right BSR
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 |
|---|---|
| BSR1 | LEN 16 POS 1 EN 1 DN 0 EM 1 FU 0 |
| BSR1_Data | [0] |
| BSR1_Execute | 1 |
| BSR1_Out | 0 |
| BSR1_Reset | 0 |
How it works
Each time Execute turns on, moves the first Length bits of the array down one place. Bit in enters at position Length - 1, and bit 0 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 position Length - 1. Every bit moves down one place, and bit 0 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 0 of one element moves down into bit 31 of the one before it.
- 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 BSR to move bits the other way along a track. Length is 4 here, so the track has 4 positions.
1. Shift in a 1. Bit in is 1. It goes in at bit 3 and 1001 becomes 1100. The 1 that was at bit 0 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. 1100 becomes 0110. Bit 0 was 0, so Bit out is 0.
4. Turn Step off. Execute is off. Nothing moves.
5. Shift in a 0 again. 0110 becomes 0011. The 1s are now at the first positions.
6. Turn Step off. Execute is off. Nothing moves.
7. Shift a fourth time. 0011 becomes 0001. A 1 leaves bit 0, 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 | [12] | 1 | 1 | 1 | 0 |
| 2. Turn Step off, Bit in off | [12] | 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 | [3] | 0 | 0 | 3 | 0 |
| 6. Turn Step off | [3] | 0 | 0 | 3 | 0 |
| 7. Shift a fourth time | [1] | 0 | 1 | 4 | 1 |
The word went 9 (1001) to 12 (1100) to 6 (0110) to 3 (0011) to 1 (0001). Each shift put Bit in at bit 3 and moved the rest down. Bit out was on after the first and fourth shifts, when a 1 left bit 0. 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.