Industrial Process Automation, Exercise3: PLC (Programmable INSTITUTE Logic OFController) AUTOMATION SYSTEMS Prof. Dr.-Ing. Wolfgang Meyer PLC design Industrial Process Automation (Exercise) PLC (Programmable Logic Controller) Introduction to the PLC environment CoDeSys Implementation of the traffic light state graph as Sequential Function Chart (SFC) Instruction List (IL) Literature: [Lewis, 95] R. W. Lewis; Programming industrial control systems using IEC 1131-3; Inst. of Electrical Engineers; London; 1995 1 Revision: Functionality of a PLC (Permanent) cyclic run: Most PLCs execute a cyclic scan continuously. The cycle starts with the hardware I/O system gathering the latest values of all input signals and storing their values in fixed regions in memory. Then the PLC program is executed. New values for physical outputs as determined by the PLC program are written to an output memory region. Finally, when the program execution is completed the output values held in the memory are written to the physical outputs in one operation. Afterwards the cycle starts again. Memory PLC Programcycle Environment Input- Memory Read Inputs Inputs Sensors Flag Memory Execute Program : 1. Instruction 2. Instruction : : n. Instruction Output- Memory Write Outputs Outputs Actuators 2
CoDeSys a PLC environment A wide spread PLC tool which supports the IEC 1131-3 standard is CoDeSys (www.3s-software.com). It runs on many different hardware PLCs and of course as a Soft PLC. After starting CoDeSys, the following window appears: If a project is already opened, close the project with File Close. 3 New Project To create a new project, select New from the File Menu. Then the Target Settings appears for configuration of the target system. Select 3S CoDeSys SP PLCWinNT V2.4 from the combo box. Accept the default settings with OK. 4
Program Organisation Unit (POU) The first POU is created automatically. Its name is PLC_PRG and it is the main POU. That means, this POU is called by the PLC by default. All other POUs have to be called by this POU or a POU that is called by PLC_PRG. The PLC languages are displayed at the right side. Additionally, CFC (Continuous Function Chart) is listed. It is not part of the IEC1131-3 yet, therefore it is not used in the exercises. Use Structured Text for PLC_PRG, because the calling of other POUs is very easy in this language. 5 Simulation Mode CoDeSys expects that the workstation is connected to PLC hardware. As it is not the case, enable the Simulation Mode in the Online menu. To run the program, select Login and then Run from the Online menu. Select Logout to edit the program again. 6
To add a new POU, click Project Object Add The POU PLC_PRG is called automatically. The call of added POUs must be done by the user (see below). Select a language and name the POU. 7 Define Variables Variables must be defined in the declaration part (upper text area) of a POU. One option is to write the declaration manually between VAR and END_VAR. A second possibility is to use undeclared variables in the program part. When an undeclared variable is recognized by the tool, then a window arises with some default values. For example, type Red:=Switch; and press <RETURN> in a ST-POU. Then the Declare Variable windows appears as depicted. 8
Visualisation 4. Select the tab Visualizations and add a new object by clicking the right mouse button on Visualizations Add Object Name the Object (e. g. Traffic_Light). A window appears on the right side with a grid. With the drawing buttons, graphical elements can be added. The drawings are configured by double clicking. 3. 1. 2. 9 Configure graphical elements Variables (application: lights) In the category Variables, the link between a graphical element and a Boolean variable in the PLC program is defined. The semantic is: <POU>.<Boolean variable> Colours (application: lights) Color is the colour which is shown when the associated Boolean variable is FALSE, otherwise Alarm color is shown. 10
Change values of variables (application: switch) For the switch it is required that the user changes the variable by the visualisation object. In the Input category of the switch shape, a toggle variable can be defined. The value of the Boolean variable changes with every click on the shape. 11 Exercise 3.2-3.3 The result of exercise 3.1 is shown below. Implement the automata graph as SFC and IL. Init-Phase Red=1 Green=0 Yellow=0 Red=0 Green=0 Yellow=1 Red-Phase Switch=1 / Red=1 TimmerYellow=1s Yellow=0, Red=1 Yellow-Phase TimerRed=3s / Yellow=1 TimerGreen=3s / Green=0, Yellow=1 Red=1 RedYellow-Phase Green=0 Yellow=1 TimerRedYellow=1s / Red=Yellow=0, Green=1 Red=0 Green-Phase Green=1 Yellow=0 12
Exercise 3.2: SFC First of all, the IEC-Steps must be enabled (Extras Use IEC-Steps) Select a Step or Jump and add a new Step and Transition by a right-click Step-Transition (before) If additional actions are required, select Extras Associate Action 13 Exercise 3.2: SFC The first steps of the solution are shown. Complete the program. Do not forget to adapt the variables of the Visualisation. 14
Exercise 3.3: IL The Instruction List is not similar to automata. But the idea of states and state changes can be implemented in IL, too. The required operators are listed below: LD variable load operand into result register ST variable store result into operand AND variable link actual result and variable by logical AND OR variable link actual result and variable by logical OR S variable set variable TRUE if actual result is TRUE R variable set variable FALSE if actual result is TRUE CAL functionblock call functionblock Set (S) and Reset (R) only works with Boolean values. The ST operator is not restricted to a data type. 15 Timer Declaration When an undeclared variable is used the first time, then a dialog box arises for variable declaration. If the variable is a timer, then the type can be selected in the Help Manager. After applying, the type is taken over and can be accepted. 16
Exercise 3.3: IL The usage of IL-statements and the timer-function-block is explained in the following RedPhase. Complete the program. Remember that the InitPhase must be executed exactly one time. (*RedPhase*) LD RedPhase S Red LD RedPhase ST TimerRed.IN LD T#3s ST TimerRed.PT CAL TimerRed LD TimerRed.Q S RedYellowPhase R RedPhase Comment Load content of RedPhase into result register If result register is TRUE set Red to TRUE Store actual result in INput of TimerRed Load constant T#3s into result register Call functionblock TimerRed If actual result is TRUE set RedPhase to FALSE 17