ndzied1
Lifetime Supporting Member
After the recent discussion regarding different philosophies of coding in Structured Text (ST) I thought it would be interesting to take a small system and program it in different languages.
I picked a cylinder control that can be seen here in the simulation I did to test the programs:
Basic System Discription
I picked a cylinder control that can be seen here in the simulation I did to test the programs:
Basic System Discription
- The system has Power ON and OFF pushbuttons. All outputs are turned off and sequences cancelled when the power is off.
- There is a mode select switch for Manual/Off/Auto Control.
- The Retract / Extend Pushbuttons only work in the Manual Mode as jogging functions.
- The Cycle Pushbutton only works in Auto Mode and will initiate a cycle to Extend the Cylinder / Dwell for 2 sec. / Retract the Cylinder. Above the Cycle Pushbutton is a Cycle Counter Display.
- The "Home / Cancel Cycle" Pushbutton functions in Manual and Auto Modes (but not OFF) and immediately retracts the cylinder and cancels the Cycle if it is active.
- Whenever the cylinder is under power and reaches an end limit switch (LS1 & LS2) the logic will seal in the Solenoid to keep any cushions or shock absorbers from pushing the cylinder away from its end position.
- PLC_FB: Function Block Version
- PLC_PRG_LD: Ladder Logic
- PLC_ST1: Structured Text (IF/THEN/ELSE type format)
- PLC_ST2: Structured Text (Peter & Norm Prefered ST Format)
[/list=1]
Besides the program files, there is also a Global Variables File which is common to all the programs. It contains the (simulated) I/O for the system.
The programs and Global Variable file are documented in the following pdf file:
iec_1.pdf
This system is definately geared more toward ladder than ST as it it mostly logical combinations of the I/O and internal bits. Note that except for one jump in the Function Block (FB) program, the PLC_FB and PLC_ST2 are line for line copies of the Ladder Logic code.
The ST program PLC_ST1 was an attempt to follow a more traditional Computer Science type programming which may be clearer to someone not familiar with ladder logic. You'll notice several places where many items are reset (set to FALSE) as the program leaves certain conditions. These can be 'gotchas' that creep up on you later as bugs in your program.
Also, for those unfamiliar with IEC programs, there is a set of local variables at the beginning of each program. Note that these are the same for all programs (Although not shared as the global variables are).
Once I'm back in work next week I can connect my PLC to the internet and let you'all play with the simulation yourselves (It runs on the PLC).
In the future, I hope to create another simulation which will be much easier to program in ST than Ladder. I did a project a while back the read an ascii string from an LVDT gage column and parsed it out to get the number into a register. It should be much easier in ST than what I had to go through in Ladder. Anyone else have suggestions for programs that would be easier to write in ST than LD?