BSL (bit shift left)

The BSL instruction shifts a bit in an array element to the left.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the L20E, L50E, and L70E controllers.
Operation details:
The BSL instruction is an immediate process on false-to-true rung transition and updates output synchronously. When Execute is TRUE, the leftmost bit (Src + SrcOffset and Length) is copied into the Unload bit and all bits in the array or non-array are shifted left 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.
BSL
BSL
BSL parameters
Parameter
Parameter Type
Data Type
Description
Execute
Input
BOOL
Instruction enable.
  • TRUE: Rising edge detected, shifts bit to the left one position.
    • Verify fault conditions first.
    • If Length = 0, the external bit is moved into the Unload bit. No bit shift is done on Scr. Error and ErrorID bits are reset. Done bit is set.
    • If Length > 0 and Length <= 2048, the Error and ErrorID bits are reset. After the bit shift completes, the Done bit is set.
    • If Length > 0 and Length <= 2048, the leftmost bit (addressed by Src + SrcOffset and Length) is copied into the Unload bit and all bits that are part of the array or non-array are shifted left by one bit (up to the bit Length and 16-bit boundary except for BOOL). External bit is moved to bit 0 (Src + SrcOffset) of the first element.
  • FALSE: Rising edge not detected, do not enable BSL 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-bit 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 sent 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 the error code.
Done
Output
BOOL
When TRUE, operation completed successfully. When FALSE, operation encountered an error condition.
BSL 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.

BSL examples

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