24.01.2015 Views

PLC Programming

  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3 - We Write a Little Program<br />

At first it is checked whether Q has already been set at TRUE (as though the counting had already<br />

been executed), in this case we change nothing with the occupation of ZAB, but we call the function<br />

block ZAB without input (in order to check whether the time period is already over).<br />

Otherwise we set the variable IN in ZAB at FALSE, and therefore at the same time ET at 0 and Q at<br />

FALSE. In this way all variables are set at the desired initial condition. Now we assign the necessary<br />

time from the variable TIME into the variable PT, and call ZAB with IN:=TRUE. In the function block<br />

ZAB the variable ET is now calculated until it reaches the value TIME, then Q is set at FALSE.<br />

The negated value of Q is saved in OK after each execution of WAIT. As soon as Q is FALSE, then<br />

OK produces TRUE.<br />

The timer is finished at this point. Now it is time to combine our two function blocks WAIT and<br />

SEQUENCE in the main program <strong>PLC</strong>_PRG.<br />

"SEQUENCE" first expansion level<br />

First we declare the variables we need. They are: an input variable START of the type BOOL, two<br />

output variables TRAFFICSIGNAL1 and TRAFFICSIGNAL2 of the type INT and one of the type WAIT<br />

(DELAY as delay). The program SEQUENCE now looks like shown here:<br />

Program SEQUENCE, First Expansion Level, Declaration Part<br />

Create a SFC diagram<br />

The beginning diagram of a POU in SFC always consists of an action "Init" of a following transition<br />

"Trans0" and a jump back to Init. We have to expand that.<br />

Before we program the individual action and transitions let us first determine the structure of the<br />

diagrams. We need one step for each TRAFFICSIGNAL phase. Insert it by marking Trans0 and choosing<br />

'Insert' 'Step transition (after)'. Repeat this procedure three more times.<br />

If you click directly on the name of a transition or a step, then this is marked and you can change it.<br />

Name the first transition after Init "START", and all other transitions "DELAY.OK".<br />

The first transition switches through when START is TRUE and all others switch through when DELAY<br />

in OK produces TRUE, i.e. when the set time period is finished.<br />

CoDeSys V2.3 3-5

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

Saved successfully!

Ooh no, something went wrong!