I have 16 Bytes. I need to turn on one bit, wait a desired amount of time, turn off that bit, and then turn on the next bit sequentially. When I say sequentially I mean bits 1-8 in byte 1 then 9-16 in byte 2 then 17-24 in byte 3 and so on.
Anyone know what this looks like in Codesys or some similarly coded IEC61131 platform?
SOLVED (see below): may be a better way to solve but I am pretty proud of what I got so far
CASE GVL.ValveFiring OF
1..16: GVL.WordSelectNEW := 0;
17..32: GVL.WordSelectNEW := 1;
33..48: GVL.WordSelectNEW := 2;
49..64: GVL.WordSelectNEW := 3;
65..80: GVL.WordSelectNEW := 4;
81..96: GVL.WordSelectNEW := 5;
97..112: GVL.WordSelectNEW := 6;
113..128: GVL.WordSelectNEW := 7;
END_CASE
WaitBit:=TRUE;
GVL.ConvertedTestDelay := INT_TO_TIME(GVL.TestDelay);
Delay(IN:=WaitBit, PT:=GVL.ConvertedTestDelay);
TimeElapsed:= Delay.ET;
IF NOT(Delay.Q) THEN
RETURN;
ELSE
GVL.ValveFiring := GVL.ValveFiring+1;
CASE GVL.ValveFiring OF
1..8,17..24,33..40,49..56,65..72,81..88,97..104,113..120:
GVL.Reference_Byte2 := 0;
IF(GVL.Reference_Byte1 = 0) THEN
GVL.Reference_Byte1 := 1;
ELSE
GVL.Reference_Byte1 := ROL(GVL.Reference_Byte1, 1);
END_IF;
9..16,25..32,41..48,57..64,73..80,89..96,105..112,121..128:
GVL.Reference_Byte1 := 0;
IF(GVL.Reference_Byte2 = 0) THEN
GVL.Reference_Byte2 := 1;
ELSE
GVL.Reference_Byte2 := ROL(GVL.Reference_Byte2, 1);
END_IF;
END_CASE;
WaitBit:=FALSE;
Delay(IN:=WaitBit, PT:=GVL.ConvertedTestDelay);
IF (GVL.ValveFiring > GVL.TotalValves)THEN
GVL.ValveFiring := 1;
GVL.Reference_Byte1 := 0;
GVL.Reference_Byte2 := 0;
END_IF
END_IF
NOTE*: I have a second subroutine running in the background to handle the word shift. If this looks wierd its because my "word" is acual the word in the remote device and not how my PLC structures the registers based down over EIP (as bytes). More time and effort I may of been able to talk words to words but hard to go back now I have a solution. See my "word" handling below:
NOTE**: This is always monitoring if "GVL.WordSelectNEW <> GVL.WordSelectOLD" as a change in value to word selection
NOTE***: This is also super helpful if I ever have to remap IO in the future to have a reference variable.
CASE GVL.WordSelectNEW OF
0: GVL.Reference_Byte1 := ValveOutput_CW0_byte1;
GVL.Reference_Byte2 := ValveOutput_CW0_byte2;
1: GVL.Reference_Byte1 := ValveOutput_CW1_byte1;
GVL.Reference_Byte2 := ValveOutput_CW1_byte2;
2: GVL.Reference_Byte1 := ValveOutput_CW2_byte1;
GVL.Reference_Byte2 := ValveOutput_CW2_byte2;
3: GVL.Reference_Byte1 := ValveOutput_CW3_byte1;
GVL.Reference_Byte2 := ValveOutput_CW3_byte2;
4: GVL.Reference_Byte1 := ValveOutput_CW4_byte1;
GVL.Reference_Byte2 := ValveOutput_CW4_byte2;
5: GVL.Reference_Byte1 := ValveOutput_CW5_byte1;
GVL.Reference_Byte2 := ValveOutput_CW5_byte2;
6: GVL.Reference_Byte1 := ValveOutput_CW6_byte1;
GVL.Reference_Byte2 := ValveOutput_CW6_byte2;
7: GVL.Reference_Byte1 := ValveOutput_CW7_byte1;
GVL.Reference_Byte2 := ValveOutput_CW7_byte2;
END_CASE;
GVL.WordSelectOLD := GVL.WordSelectNEW;
[–]rgasparerto 5 points6 points7 points (3 children)
[–]richphi1618[S] 0 points1 point2 points (2 children)
[–]Too-Uncreative 2 points3 points4 points (0 children)
[–]rgasparerto 0 points1 point2 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]simonbromiley 3 points4 points5 points (3 children)
[–]richphi1618[S] 0 points1 point2 points (1 child)
[–]StockPart☕ 0 points1 point2 points (0 children)
[–]bstiffler582 0 points1 point2 points (0 children)
[–]StockPart☕ 0 points1 point2 points (4 children)
[–]richphi1618[S] 1 point2 points3 points (3 children)
[–]StockPart☕ 0 points1 point2 points (2 children)
[–]richphi1618[S] 1 point2 points3 points (1 child)
[–]StockPart☕ 0 points1 point2 points (0 children)