BSR (bit shift right)

The BSR instruction shifts a bit in an array element to the right.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the L20E, L50E, and L70E controllers.
Operation details:
The BSR instruction is an immediate process on false-to-true rung transition and updates output synchronously. When Execute is TRUE, the right most bit (bit 0 of the element addressed by Src + SrcOffset) is copied into the Unload bit and all bits in the array or non-array are shifted right by one bit. Length and 16 bit boundary are considered except for BOOL data types. The external bit is then moved to bit 0 (Src + SrcOffset) of the first element.
For wraparound operations, set the position of the BitAddr to the last bit position or to the Unload bit. A possible usage of the BSL instruction is tracking bottles through a bottling line, where each bit represents a bottle.
BSR
BSR
BSR parameter
Parameter
Parameter Type
Data Type
Description
Execute
Input
BOOL
Instruction enable.
  • TRUE: Rising Edge detected, shifts bit to the right one position.
  • FALSE: Rising Edge not detected, do not enable BSR operation.
Scr
Input
ANY_ELEMENTARY
The address of the Src (bit) to be shifted. Supported data types: BOOL, DWORD, INT, UINT, WORD, DINT and UDINT.
  • Arrays: Set Scr to a variable based address such as Source1, Source1[0], or Source1[1].
  • Non-arrays: Set Scr to a variable address such as Source1.
SrcOffset
Input
UINT
If SrcOffset is 0, start from the first element.
  • Arrays: Set SrcOffset to 0. If set to Source1[0] or Source1[1], the error "Source offset exceeds the size of the array" occurs.
  • Non-arrays: Set SrcOffset to 0 or the error "Source offset exceeds the size of the array" occurs
BitAddr
Input
BOOL
Location of the bit shifted into Src.
Length
Input
UINT
Length contains the number of bits in the Src to be shifted. Supports shifting across array elements.
  • For BOOL data type, number of Booleans in the array to be shifted.
  • For 16- and 32-bit data types, bits are shifted in multiples of 16 (such as 16, 32, and 64). If Length is not an even multiple of 16, the number of shifted bits is to the next 16-bit boundary.
  • Length is based on the size of the data type. If Length exceeds the range, the error "Source offset exceeds the size of the array" occurs. Length values are:
    • BOOL: 1
    • 16-bit word: 1‒16
    • 32-bit word: 1‒32
    • 64-bit word: 1‒64
Unload
Output
BOOL
Bit shifted out from Src address.
Error
Output
BOOL
When a fault occurs, Error is set to true.
ErrorID
Output
USINT
When a fault occurs, ErrorID contains error code.
Done
Output
BOOL
When TRUE, operation completed successfully. When FALSE, operation encountered an error condition.
BSR error codes
Error code
Error description
01
Dimension not supported.
02
Data type not supported.
03
Length of bits exceeds 2048.
04
Source offset exceeds the size of the array.
05
Length of bits exceeds the size of the array.
07
Invalid parameters.

BSR examples

BSR function block diagram example
BSR ladder diagram example
BSR ladder diagram example
BSR structured text example
BSR structured text example
Results
Results
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal