Shift and Rotate Elements in Advanced Ladder

See also: Project Toolbox for Advanced Ladder

 

Topic Menu

The Cscape Shift Register Instruction

Shift and Rotate Overview

Home > View > Project Toolbox > Move Operations

The Move Operations allow data values to be copied or moved from one place to another in variables or arrays or registers. They are useful for initializing values at run time or capturing the state of values during a process, among other things. The Move operations work at a bit level, ignoring data formats. The data formats REALClosed These numbers use IEEE 754-1985 format to store numbers in following ranges. 32-bit single-precision floating point (REAL) – -3.40282E+38 to +3.40282E+38 64-bit double-precision floating point (LREAL) – -1.79769E+308 to +1.7976E+308 Floating Point refers to both REAL and LREAL data types. and LREALClosed These numbers use IEEE 754-1985 format to store numbers in following ranges. 32-bit single-precision floating point (REAL) – -3.40282E+38 to +3.40282E+38 64-bit double-precision floating point (LREAL) – -1.79769E+308 to +1.7976E+308 Floating Point refers to both REAL and LREAL data types. are provided for ease of use in some instances. The Move operations will execute regardless of the values in the source and will always pass power flow. The only exception to this is the Indirect Block Move as noted below. Move Operations are configured with a Source and a Destination. In the case of Move operations that work to move multiple values, the Source and/or Destination may be just the first of multiple consecutive array elements or registers.

Shift Elements

The Element Shift, aka the Multi-Shift function, will shift data in a specified location to the right or to the left a specified number of places. The data to be shifted into vacated places is specified and the last data to be shifted out is captured.

Shift Elements Parameters

  • Source (SRC): The first location of the block of data to shift. Must be an array/register. Registers must be on a Word Boundary.
  • Length (LEN): The length of the block of data to shift in terms of the Type specified. Must be a constant value equal to 2048 total 16-bit Words or less, (i.e. 1024 DWORD or less, 32767 BIT or less, etc.)
  • Number (N): The number of elements to shift when this function is executed in terms of the Type specified. May be a variable/register or a constant value. Must be less than or equal to the Length parameter.
  • Direction (DIR): A 1-bit trigger to specify the direction of the shift. When this trigger is active, data is shifted left (noted by the “DIR (left)” on the function block), otherwise it is shifted right.
  • Input (IN): The data to shift into vacated places when the shift happens. Must be a variable/register that matches the function Type
  • Output (OUT): Will contain the last value to be shifted out when the function is executed. Must be a variable/register that matches the function Type
  • Type: The type of the data being shifted. As a Move function that doesn’t pay attention to data format, the REAL format is covered by DWORD type

Note: The direction “Left” refers to going from Least Significant to Most Significant, i.e. from %R1 to %R2 or from Array[0] to Array[1]. The direction “Right” is from Most Significant to Least Significant.

Power Flow

The Element Shift function executes immediately and entirely as soon as it receives power from the incoming rung. The resulting shifted data is available for any other use immediately.

The Element Shift function will execute on every scan that it has received power from the incoming rung. The Element Shift function will always pass power flow to the next function on the rung.

There is no need for any further functions to exist to the right of the Element Shift function on the rung. The function’s result is considered an output.

Element Shift Example 1

Shift a block of 8 WORD values to the left by 3 places. Zero the vacated places.

Data before the function is executed:

Out (%R52) %R8 %R7 %R6 %R5 %R4 %R3 %R2 %R1 N (%R51)
-- 8001 7001 6001 5001 4001 3001 2001 1001 0

Data after the function is executed the first time:

Out (%R52) %R8 %R7 %R6 %R5 %R4 %R3 %R2 %R1 N (%R51)
6001 5001 4001 3001 2001 1001 0 0 0 0

Data after the function is executed the second time:

Out (%R52) %R8 %R7 %R6 %R5 %R4 %R3 %R2 %R1 N (%R51)
3001 2001 1001 0 0 0 0 0 0 0

Element Shift Example 2

Shift bits in a bit array to the right by 1 place. Vacated places should populate with current state of a proximity sensor. Output bit should activate a diverter flap.

Data before the function is executed:

Prox Tracker [31]-[24] Tracker [23]-[16] Tracker [15]-[8] Tracker [7]-[0] Divert
0 0100 1001 1110 1010 0001 0100 1001 1001 ---

Data after the function is executed the first time:

Prox Tracker [31]-[24] Tracker [23]-[16] Tracker [15]-[8] Tracker [7]-[0] Divert
0 0010 0101 1111 0101 0000 1010 0100 1100 1

Data after the function is executed the second time, now proximity sensor gets tripped:

Prox Tracker [31]-[24] Tracker [23]-[16] Tracker [15]-[8] Tracker [7]-[0] Divert
1 0001 0010 1111 1010 1000 0101 0010 0110 0

Data after the function is executed the third time:

Prox Tracker [31]-[24] Tracker [23]-[16] Tracker [15]-[8] Tracker [7]-[0] Divert
1 1000 1001 0111 1101 0100 0010 1001 0011 0

Return to the Top: Shift and Rotate Elements in Advanced Ladder

Rotate Elements

The Element Rotate, aka the Multi-Rotate function will rotate data in a specified location to the right or to the left a specified number of places. The data rotated off either the right or left sides of the Source block will be placed at the opposite side of the block as if the block’s ends were connected in a circular fashion.

Element Rotate Parameters

  • Source (SRC): The first location of the block of data to rotate. Must be an array/register. Registers must be on a Word Boundary

  • Length (LEN): The length of the block of data to rotate in terms of the Type specified. Must be a constant value equal to 2048 total 16-bit Words or less, (i.e. 1024 DWORD or less, 32767 BIT or less, etc.)

  • Number (N): The number of places to rotate when this function is executed in terms of the Type specified. May be a variable/register or a constant value. Must be less than or equal to the Length parameter.

  • Direction (DIR): A 1-bit trigger to specify the direction of the rotate. When this trigger is active, data is rotated left (noted by the “DIR (left)” on the function block), otherwise it is rotated right.

  • Type: The type of the data being rotated. As a Move function that doesn’t pay attention to data format, the REAL format is covered by DWORD type.

Note: The direction “Left” refers to going from Least Significant to Most Significant, i.e. from %R1 to %R2 or from Array[0] to Array[1]. The direction “Right” is from Most Significant to Least Significant.

Power Flow

The Element Rotate function executes immediately and entirely as soon as it receives power from the incoming rung. The resulting shifted data is available for any other use immediately.

The Element Rotate function will execute on every scan that it has received power from the incoming rung. The Element Rotate function will always pass power flow to the next function on the rung.

There is no need for any further functions to exist to the right of the Element Rotate function on the rung. The function’s result is considered an output.

Element Rotate Example 1

Rotate a block of 5 WORD values to the left by 2 places.

Data before the function is executed:

%R5 %R4 %R3 %R2 %R1
1005 1004 1003 1002 1001

Data after the function is executed the first time:

%R5 %R4 %R3 %R2 %R1
1003 1002 1001 1005 1004

Data after the function is executed the second time:

%R5 %R4 %R3 %R2 %R1
1001 1005 1004 1003 1002

Return to the Top: Shift and Rotate Elements in Advanced Ladder