TANGENT ALERT
Earlier this year there was many threads (also tangents) with PLC versus PC, Ladder vs Instruction list and related topics.
Poster's feelings was involved and there was many comments, like :
- "dumbing down the code for the sake of maintenance"
- "programming versus maintenance"
- "that ladder is overall just as effective "
- "engineers that want it to be so high level that the working man can not deal with it, which in turn puts more money in their pocket"
The debate ended quickly.
As I guess the oldtimers here know, I am a listprogrammer. And I also consider Index/Indirect adressing as standard tools. (Hey, this sounds like a AA meeting : My name is XXX and I am a listprogrammer)
To the end (or until some money) I will be convinced that Instruction List is:
- Faster to write
- More compact
- have more opportunities
- less "copy-errors"
etc
(There can be PLC brand exception's)
Mr John Grizia's "problem" can be used as an example:
--------------
Example of STRUCTURED TEXT:
(This code can be used by a Telemecanique Micro or Premium PLC. STRUCTURED TEXT conforming to standard IEC 1131-3)
Code:
IF RE PushBotton (* RE = RaisingEgde *)
THEN
ToggleBit := NOT ToggleBit; (* Invert internal bit *)
END_IF
IF RE ToggleBit (* RE = Raising Egde *)
THEN
OutPutNumber := OutPutNumber + 1; (* Increment OutPutNumber *)
IF OutPutNumber > 5 (* 6 outputs: OutPutNumber = 0-5 *)
THEN
OutPutNumber:=0; (* Reset index *)
END_IF;
END_IF;
Output[OutPutNumber] := ToggleBit; (* Output(Adress+OutPutNumber) gets status of Togglebit *)
Where:
Pushbotton = input of type %Ix.i
Togglebit = internal bit of type %Mi
OutPutNumber = internal word of type %MWi
Output= output(s) of type %Qx.i
The initial status of OutPutNumber and the outputs are zero. All outputs must be in a sequence and on the same module.
--------------------------------
INSTRUCTION LIST example from another PLC:
The initial status of OutPutNo and the outputs are zero. All outputs must be in a sequence and on the same module OR useing 16 output modules in following slots.
Code:
PushBotton EQU I 0 ;Input: PushBotton
OutPutBase EQU O 16 ;Output: 1. in sequence
DynBit1 EQU F 600 ;Internal bit
DynBit2 EQU F 601 ;Internal bit
ToggleBit EQU F 500 ;Internal bit: Toggle
OutPutNo EQU R 500 ;Int DoubleWord: OutputNumber
;- "RUNG1": IF RaisingEgde Pushbotton THEN invert (COMplement) Togglebit ELSE jump to PASS
STH PushBotton
DYN DynBit1
JR L PASS
COM ToggleBit
;- "RUNG2": IF RaisingEgde ToggleBit THEN INCrement OutPutNo ELSE jump to PASS2
PASS: STH ToggleBit
DYN DynBit2
JR L PASS2
INC OutPutNo
;- "RUNG3": IF (CoMPare) OutPutNo < 6 THEN jump to OK ELSE LoaD OutPutNo to 0
PASS2: CMP OutPutNo
K 6
JR N OK
LD OutPutNo
0
;- "RUNG4": SEt Index to OutPutNo
OK: SEI OutPutNo
; Status of ToggleBit goes to output (OutPutBase + indeX)
STH ToggleBit
OUTX OutPutBase
Especially the first example should be readable for everybody. As it has been said here in the forum: It is almost in plain english!
May be "C" is not comming as a PLC programming language, but structured text is part of IEC and I am looking forward to the time when all PLCs can be programmed with it.
my 2 cents
Regards
Karl Egil Liaset
(a engineer that want it to be so high level that the working man can not deal with it, which in turn puts more money in my pocket)
BTW: OK, this can be solved with ladder. Also without use of index.
If it hasn't been for the off state for each second push, I guess a shiftreg could be used "as is".
2 suggestions from the top of my head (remember I am not a Ladder-man... )
Increment a word (OutPutNumber) each time ToggleBit goes high (egde), and then make a rung for each output:
Code:
ToggleBit Output1
--(Compare OutPutNumber with 1, Equal?)---| |--------( )-
ToggleBit Output2
--(Compare OutPutNumber with 2, Equal?)---| |--------( )-
etc
Or use a shiftreg with internal bits ("MirrorBits") that shiftes each time ToggleBit goes high (egde) and then make a rung for each output:
Code:
"MirrorBit1" ToggleBit Output1
--| |-----------| |--------( )
"MirrorBit2" ToggleBit Output2
--| |-----------| |--------( )
etc
I'm shure (wellcome back Pierre..) others can put in some more examples. (a half-dozen or more.....)