24.01.2015 Views

PLC Programming

  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3 - We Write a Little Program<br />

3 We Write a Little Program<br />

3.1 Controlling a Traffic Signal Unit...<br />

Create POU<br />

Let us now start to write a small example program. It is for a simple traffic signal unit which is<br />

supposed to control two traffic signals at an intersection. The red/green phases of both traffic signals<br />

alternate and, in order to avoid accidents, we will insert yellow or yellow/red transitional phases. The<br />

latter will be longer than the former.<br />

In this example you will see how time dependent programs can be shown with the language resources<br />

of the IEC1131-3 standard, how one can edit the different languages of the standard with the help of<br />

CoDeSys, and how one can easily connect them while becoming familiar with the simulation of<br />

CoDeSys.<br />

Starting always is easy: Start CoDeSys and choose 'File' 'New'.<br />

In the dialog box which appears, the first POU has already been given the default name <strong>PLC</strong>_PRG.<br />

Keep this name, and the type of POU should definitely be a program. Each project needs a program<br />

with this name. In this case we choose as the language of this POU the Continuous Function Chart<br />

Editor (CFC)<br />

Now create three more objects with the command 'Project' 'Object Add' with the menu bar or with the<br />

context menu (press right mouse button in the Object Organizer). A program in the language<br />

Sequential Function Chart (SFC) named SEQUENCE, a function block in the language Function Block<br />

Diagram (FBD) named TRAFFICSIGNAL, along with a POU WAIT, also of the type function block,<br />

which we want to program as an Instruction List (IL).<br />

What does TRAFFICSIGNAL do<br />

In the POU TRAFFICSIGNAL we will assign the individual trafficsignal phases to the lights, i.e. we will<br />

make sure that the red light is lit red in the red phase and in the yellow/red phase, the yellow light in<br />

the yellow and yellow/red phases, etc.<br />

What does WAIT do<br />

In WAIT we will program a simple timer which as input will receive the length of the phase in<br />

milliseconds, and as output will produce TRUE as soon as the time period is finished.<br />

What does SEQUENCE do<br />

In SEQUENCE all is combined so that the right light lights up at the right time for the desired time<br />

period.<br />

What does <strong>PLC</strong>_PRG do<br />

In <strong>PLC</strong>_PRG the input start signal is connected to the traffic lights' sequence and the "color<br />

instructions" for each lamp are provided as outputs.<br />

TRAFFICSIGNAL simulation<br />

Now test your program in simulation mode. Compile ('Project' 'Build') and load ('Online' 'Login') it.<br />

Start the program by 'Online' 'Start', then set variable ON to TRUE, e.g. by a double-click on the<br />

entry "ON" in the input box of the CFC editor. This will mark the variable as prepared to be set to<br />

. Then press or command 'Online' 'Write values', to set the value. Now variable<br />

START in ABLAUF (which we had set to TRUE manually in the first extension level of the program)<br />

gets this value by variable ON, which is used in <strong>PLC</strong>_PRG. This will make run the traffic light cycles.<br />

<strong>PLC</strong>_PRG has changed to a monitoring window. Click twice on the plus sign in the declaration editor,<br />

the variable display drops down, and you can see the values of the individual variables.<br />

CoDeSys V2.3 3-1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!