IEC 61131 Case Study 1: Cylinder Control

ndzied1

Lifetime Supporting Member
Join Date
Aug 2002
Location
Chicago, Illinois
Posts
2,857
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:

simulation.gif


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.
I Created 4 separate but equal program files which are:
  1. PLC_FB: Function Block Version
  2. PLC_PRG_LD: Ladder Logic
  3. PLC_ST1: Structured Text (IF/THEN/ELSE type format)
  4. 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?
 
What name and webpage software? System run and winout hardware?

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).

All peoples in word possible connect PLC (fix IP).Yes ???
 
dandrade:

The software is Moeller XSoft. More information at
http://www.moeller.net

It is based on the CoDeSys software which is supported by a bunch of companies (mostly European) and makes a common programming environment for different hardware platforms.

I'm glad you picked up on the simulation with no hardware required thing. I did have to write a program to simulate the I/O and run a little animation of the cylinder. Actually I had two other programs not in the pdf file. One is the main plc program which calls the simulation routine and switches between the calls to the different programs and the other is the simulation routine.

Yes, I have a public IP address that I can put the PLC on. The processor containes a web server which will run a java ap that does the interface to the plc program. That is all supplied w/ the software. I have tools to link buttons and fields directly to PLC variables. There will be a slight problem in that it is not multi-user capable so you might do something and someone half way around the world might undo it just as fast.... Oh well, we'll see how that goes next week.

The main program is here and is in ST language:
Code:
PROGRAM PLC_PRG
VAR
	pbladder	:BOOL;
	Ctrl		:BYTE	:=1;
	pbST1		:BOOL;
	pbST2		:BOOL;
	pbFBD		:BOOL;

	aPrograms	:ARRAY[1..4] OF STRING[10] :=
					'Ladder', 'ST 1', 'ST 2', 'FBD';
	sProgram	:STRING[10] := 'Ladder';

END_VAR
Simulate();

IF pbladder THEN
	Ctrl	:= 0;
	Ctrl.0	:= 1;
	sProgram := aPrograms[1];
END_IF;

IF pbST1 THEN
	Ctrl	:= 0;
	Ctrl.1	:= 1;
	sProgram := aPrograms[2];
END_IF;

IF pbST2 THEN
	Ctrl	:= 0;
	Ctrl.2	:= 1;
	sProgram := aPrograms[3];
END_IF;

IF pbFBD THEN
	Ctrl	:= 0;
	Ctrl.3	:= 1;
	sProgram := aPrograms[4];
END_IF;

CASE Ctrl OF

	1:	PLC_PRG_LD();
	2:	PLC_ST1();
	4:	PLC_ST2();
	8:	PLC_FB();

ELSE	PLC_PRG_LD();

END_CASE;
 
This will be an interesting project, Norm. But the true power of 61131 software is being able to sub-divide your program among a number of languages. You can write "canned" code to handle basic tasks in whichever language is best suited to the task.

Side note: my experience with CoDeSys was the version created for ABB PLCs. In that version, the LD functions were limited to bits and coils only. Later versions of that software don't even have ladder! Does the general, or Moeller, version have more functions available in the ladder editor?

AK
 
akreel,

You are absolutely right. w/ 61131 you can write your own functions and function blocks. So, for instance, you could write a general routine to handle index tables. Then re-use it. In fact, the cylinder example I posted could be re-worked into a general function block to control any cylinder w/ manual jogging and an extend/dwell/retract cycle. Parameters would be the LS and PB inputs along with the dwell and the Function Block Outputs would be the Signals to the solenoids.

W/ CoDeSys you can combine standard functions into libraries and re-use them.

With the Moeller CoDeSys (XSoft) you can insert standard functions and function blocks and into the ladder diagrams. This makes the ladder much more useable than Moeller's previous offering called S40. And with the functions, sometimes it is even to use them in ladder because you can insert them in a box with an enable input. In FBD programming, this is not an option.

They still have a way to go when it comes to documentation vs. RSLogix. For instance, in XSoft LD you can give an instruction a comment but it only appears at the location where you inserted it. There is no common description data base like AB.

Thanks for chiming in.
 

Similar Topics

Hello, I have a small programming task that I need help solving. I have to: * Create an analog input (4-20v)and a digital output * The analog...
Replies
45
Views
25,128
I was poking through the Stackoverflow PLC Tag when I saw this answer to a question about converting a Real to a DWord and back again. What...
Replies
8
Views
2,909
I am looking for some expert advice. I have always made function blocks both with inputs and outputs and without inputs or outputs. I make the...
Replies
21
Views
6,794
Hello and happy new year! I would like to further understand who needs to design by this standard and is it a requirement for everyone or only...
Replies
3
Views
1,789
So Ladder is easy to read graphically, most everything can be coded in ladder, and it represents wiring diagrams the closest. SCL and ST are good...
Replies
5
Views
1,739
Back
Top Bottom