LEFT/RIGHT shift register
Shifts 1 bit of the 16-bit data range to the left or to the right.
Input
Left/right trigger; specifies the direction of the shift-out:
Specifies the new shift-in data.
new shift-in data = TRUE = 1: when the data input is in the TRUE-state.
Activates shift
Shifts 1 bit to the left or right when the rising edge of the trigger is detected (FALSE®TRUE).
Turns all the bits of the data range specified by d1_Start and d2_End to 0 if this trigger is in the TRUE-state.
Resets data in area specified by d1_Start and d2_End to 0
Ending 16-bit area
Starting 16-bit area
Output
Bit shifted out
The variables d1_Start and d2_End have to be of the same data type.
This function does not require a variable at the output Carry.
Left/right shift is a shift register which shifts 1 bit of the specified data area to the left (to the higher bit position) or to the right (to the lower bit position).
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
data_array: ARRAY [0..2] OF INT:=[2#0000000000000001,2#0011111111111111,2#0011111111111110];
enable_leftShift: BOOL:=FALSE;
(*function shifts left if TRUE,
else it shifts right*)
reset: BOOL:=FALSE;
(*if TRUE, the whole array
will be set to zero*)
input: BOOL:=TRUE;
(*specifies the new shift-in data*)
shift_trigger: BOOL:=FALSE;
(*activates the function at a 0->1
leading edge*)
carry_out_value: BOOL:=FALSE;
(*result after a 0->1 leading edge
from shift_trigger: 1.
After the next cycle the value will be
set back to zero.*)
END_VAR
When the variable enable_leftShift is set to TRUE, the function shifts left, else it shifts right.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 9 ;
NETWORK_BODY
B(B_F,F119_LRSR!,Instanz,12,1,22,9,,?DLeftDirection?DDataInput?DShiftTrigger?DReset?Dd1_Start?Dd2_End?ACarry);
B(B_CONTACT,,enable_leftShift,7,2,9,4,);
B(B_VARIN,,input,9,3,11,5,);
B(B_VARIN,,shift_trigger,9,4,11,6,);
B(B_VARIN,,reset,9,5,11,7,);
B(B_VARIN,,data_array[0],9,6,11,8,);
B(B_VARIN,,data_array[2],9,7,11,9,);
B(B_VAROUT,,carry_out_value,22,2,24,4,);
L(1,3,7,3);
L(9,3,12,3);
L(11,4,12,4);
L(11,5,12,5);
L(11,6,12,6);
L(11,7,12,7);
L(11,8,12,8);
L(1,0,1,9);
END_NETWORK_BODY
END_NET_WORK
END_BODY
carry_out_value:=F119_LRSR( LeftDirection:= enable_leftShift,
DataInput:= input,
ShiftTrigger:= shift_trigger,
Reset:= reset,
d1_Start:= data_array[0],
d1_End:= data_array[2]);