BSR (Bit Shift Right) Ladder Logic Instruction

The BSR instruction is a ladder logic rung output instruction that shifts data in an array one bit to the right every execution.

The instruction loads the value of the source bit into the bit pointed to by the Length. The instruction is enabled when the preceding logic is true and disabled otherwise.

When the instruction is enabled the least significant bit in the array is placed into the unload bit. For instance if the length is set to 12 the 1st bit in the array will be placed in the unload bit.  After the 1st bit is placed in the unload bit the remaining upper bits are shifted one position to the right. The last step places the Source_Bit value into the array at the position pointed to by the Length. All bits above 12 are not affected or invalid. Keep in mind all three steps are one rung scan.


The value of bit 1 is place in the UL bit which in this case is 1.



The least significant bits in the array are shifted 12 bits to the left.


Finally the Source Bit is loaded into the 0 bit of the array. The Source Bit is = 1so a one is loaded into the 1st bit of the array.


List of possible arguments

ARRAY:                    Must be an array of type DINT. Example MY_ARRAY[0]
CONTROL:              Must be of type control.
SOURCE BIT:          Must be a tag defined Boolean bit. No constants.
LENGTH:                  Must be a constant. For example a number like 2.

Control Element Members

.EN                  BOOL             On when the instruction is enabled.
.DN                 BOOL             Set upon completion of a bit shift.
.UL                  BOOL             Value of the bit shifted out of the array.
.ER                  BOOL             Set if the length is less than 0.
.LEN               DINT              Length of bits to shift in array. Also points to the load bit.
Note: Watch the length. If you put a length in that exceeds the size of your array you will copy data into memory allocated to other tags. Be careful.

Leave a Comment