Beckhoff Automation GmbH & Co. KG TX1200 — 3 Sample Program

Sample Program 3 Sample Program Let us now start to write a small example program. It is for a small traffic signal unit which is supposed to control two trafficsignals at an intersection. The red/green phases of both trafficsignals alternate and, in order to avoid accidents, we will insert between the phases yellow or yellow/red transitional phases. The latter will be shorter than the former. In this example you will see how time dependent programs can be shown with the language ressources of the IEC61131-3 standard, how one can edit the different languages of the standard with the help of TwinCAT PLC Control. Create POU First start TwinCAT PLC Control and choose "File" "New".

In the dialog box which appears, the first POU should have the name PLC_PRG. The type of POU should definitely be a program. In this case we choose as the language of this POU the sequential function chart (SFC). Now create two more objects with the command "Project" "Object Add" with the menu bar or with the context menu (press right mouse button in the Object Organizer). A function block in the language Function Block Diagram (FBD) by the names of TRAFFICSIGNAL, along with a POU WAIT, also of the type function block, which we want to program as an instruction list (IL). In the POU TRAFFICSIGNAL we will assign the individual trafficsignal phases to the lights, i.e.

we will make sure that the red light is lit red in the red phase and in the yellow/red phase, the yellow light in the yellow and yellow/red phases, etc. In WAIT we will program a simple timer which as input will receive the length of the phase in milliseconds, and as output will produce TRUE as soon as the time period is finished. PLC_PRG will combine everything at the end so that the right light lights up at the right time for the desired time period. Let us now turn to the POU TRAFFICSIGNAL. In the declaration editor you declare as input variable (between the keywords VAR_INPUT and END_VAR) a variable named STATUS of the type INT.

STATUS will have five possible conditions, that is one for the TRAFFICSIGNAL phases green, yellow, yellow/red, red, and off. Therefore our TRAFFICSIGNAL has four outputs, that is RED, YELLOW, GREEN, and OFF. You should declare these four variables. Then the declaration part of our function block TRAFFICSIGNAL will look like this: Function block TRAFFICSIGNAL, declaration part TX1200 32 Version: 1.3