You are on page 1of 9

PLC Programming

Muhammad Jawad
muhjawad.786@gmail.com

Further Resources:
Information and the PLC emulator is available from here: http://homepage.ntlworld.com/barrylennox

An excellent, and free, book describing PLC’s in detail is available here:


http://claymore.engineer.gvsu.edu/~jackh/books/plcs/

Aim:
The aim of this unit is to provide an overview of Programmable Logic Controllers and an introduction to the
programming techniques that they employ.

Learning Outcomes:
In successfully completing this unit you will be able to:
• Describe the purpose and functionality of a PLC
• Enter simple programmes in to a PLC emulator and simulate their use

1.0 PLC Emulator


For the purposes of this unit we will use a PLC emulator programme. This programme emulates the basic
operation of a fairly standard PLC and is available in Java. To install this software visit the web site
(http://homepage.ntlworld.com/barrylennox) and download the file SetupTL5Edu.exe. When executed, this
file will install the emulation software on to your computer. You may install this software on to a university
cluster machine, however you need to be sure that you choose to install the software in your P drive. If you
install the software on your own computer then you will need to have Java installed. There are instructions
on how to do this when you run the installation file.

Following the installation of the programme you may find that the programme does not run. On the
university clusters this is because of a conflict between the Power Archiver that the university uses and .jar
files. The simplest way to run the programme is to open up a Command Window (Start – All
Programmes – Accessories – Command Prompt, or Start – Core – Accessories –
Command Prompt, from a university machine) and in the command window type the following
(assuming you have installed the software in to the directory p:\plc):

p: <CR> <CR> means to press the enter button


cd \plc\TL5 <CR>
java –jar TL53edu.jar <CR>

The following window should now open:

1
2.0 Basic Programming
PLC’s are programmed using ladder logic. Ladder logic is based up on relay logic wiring schematics. Both
the programming and the software that is used in PLC’s is unusual and difficult to use. We will start by
writing a simple programme that will simply activate an output of the PLC when an input is activated.

To begin we will define an input and output for the PLC. To do this select Edit – I/O Table or press
F2. The following window should now appear:

Type in the name ‘IN1’ as the first label name and press enter. Then select Outputs from the pull down menu
and type the name ‘OUT1’ as the first label name and press enter. Now close this window. The first input
channel is now referred to as IN1 and the first output channel as OUT1.

We will now programme what happens when IN1 is activated. To do this press the space bar. The following
toolbar will now appear.

2
Click on the first item in this toolbar: and select Inputs – IN1. The following should now
appear:

The symbol means what will happen if IN1 is active.

Now select option 7 from the toolbar, , and your diagram should look like this:

To execute and simulate this software select Simulate – Run (all I/O Reset). The following
screen should appear:

Left click the number 1 beside the IN1 Input. You should see the OUT1 become activated (it will appear
red). When you release the mouse button the input and hence the output will de-activate. To permanently
activate the input, right click IN1. OUT1 should now remain active until you right click IN1 again.

Quit the simulation by closing the Programmable Logic Simulator window.

3
We will now make the programme a little more complicated by adding a second input, IN2. The output,
OUT1, will now be active if both IN1 and IN2 are active.

To do this, firstly edit the I/O table and define the second input as IN2. Then double click on the IN1 block
on the logic diagram. This should highlight the ladder rung that you previously entered and the IN1 block
should be highlighted in yellow. Make sure that there is a small square to the right of this block – this is
where the next block will be inserted. You can toggle the position of this square by pressing the shift button.
Now left click on the number 1 block on the toolbar menu and this time select IN2.

Your programme should now have this appearance:

The IN1 and IN2 blocks will now act as an AND gate. If IN1 AND IN2 are active then OUT1 will activate.
Simulate the system and test that it does what you expect.

Lighting Circuit
We will now try to simulate a lighting circuit, where we have one light and two switches that are able to
independently switch the light on and off. For such a system we can establish the following rules:

1. If switch A and switch B are both off then the light should be off
2. If switch A is on and switch B is off or if switch A is off and switch B is on then the light should be
on.
3. If switch A is on and switch B is on then the light should be off.

To configure this system we will firstly edit the rung that we have already created. We need to make the rung
read IF IN1 is active AND IN2 is not active THEN OUT1 is active. To do this, select the rung by double
clicking on it. Then highlight IN2 by clicking on it and select the button marked . This will change
the logic diagram to the following:

Run this as a simulation to see what happens.

We now need to add an OR gate to this logic, such that ‘IF IN1 is on AND IN2 is off OR IN1 is off AND
IN2 is on THEN OUT1 is ON.

4
To do this highlight IN1 and toggle the small square using the shift button so that the square lies to the left of
IN1. Then right click on option 5 from the menu. Then highlight IN2 and toggle the shift button until the
small square appear to the right hand side of IN2 and then left click on option 6 () from the toolbar. Select
IN1 when prompted. Your logic diagram should now look like this:

We now need to add in IN2 to the right of the NOT IN1 box. To do this make sure that the NOT IN1 box is
highlighted and the small box appears to the right hand side of this box and then left click on option 1 from
the toolbar and select IN2. The final diagram should have this form:

Now simulate this system and check that it does what you expect. It should operate as a standard two-way
light switch.

Problem 1
Can you design a 3-way light switch?

To save your logic diagrams, select File – Save As (Local Drive).

3.0 Timers and Sequencing


In this session we are going to build the following ladder logic programme:

5
Start with a new and blank logic diagram. Specify the following inputs, outputs etc:

Inputs: Start, Stop, Manual and Step


Outputs: Out1, Out2, …, Out8
Relays: Run
Timers: Duration
Counter/Sequencer: Seq1

To do this select the Edit – I/O Table or by pressing F2. To move between inputs, outputs etc you can
click on the arrow buttons.

For the timer specify that Duration has a set value of 1000 (see figure below). Timers have a time base of 0.1
seconds. Therefore this timer will have a duration of 100 seconds.

The sequencer is a very useful device. To specify the sequencer required here, enter the following:

6
This sequencer will have four steps.

Now create the following circuit:

Note that start and stop are inputs and Run is a relay.

We will now create the second circuit, so that your logic programme looks like this:

To insert a second circuit you simply need to left click a point on the screen below the first circuit.

The Clk:0.5s is a half second timer that is activated every 0.5 seconds. To insert this timer, select the
button and then select 0.5s clock from the Special Bits list.

The Seq1 [AVseq] component is available by selecting option 9: and then choosing the 4. Advance
Sequencer option for Sequencer 1. This will advance the sequencer through its steps.

Finally add four more circuits in to your programme so that the final programme has this appearance:

7
To add each of the sequencers, Seq1:1, Seq1:2, etc, click on the option and select the item #1
SeqN:x from the Special Bits table.

Now simulate the programme and try to identify what is happening and why.

Problem 2:
How can you change the circuit so that the sequencing stops when the duration timer has reached 0? This
stage can be completed by including one more element in to your circuit.

Now change the circuit so that when the timer reduces to zero, all the outputs become deactivated and the
sequencing stops until the start button is activated again. This might be simpler to solve after you have
completed the following section.

4.0 Miscellaneous
In this section we will look at some miscellaneous logic options available to PLC’s.

Relay Locks
Enter the following programme in to the PLC emulator:

8
In this programme there is one input, Switch1, one timer, Time10 which is set to 100, one relay, Relay1 and
one output, Light1. The only new part of the circuit here is the Relay 1[Latch] and Relay 1[Clear] elements.
These can be found under the option 9/0 buttons ( ) and are labelled Latching Relay/Output
and Clear Latched Relay. When you simulate this circuit you should see that when you activate Switch1,
Light1 is activated for 10 seconds.

Problem 3:
The above circuit is not ideal. When the switch is activated the light is activated for 10 seconds. Activating
the switch again has no effect. Design a circuit so that when the switch is activated the light is activated for
10 seconds. However, if during this 10 second period the switch is activated again the output is de-activated.

Problem 4:
Using the techniques you have learned, design a PLC programme that will operate a single set of traffic
lights. The lights should be scheduled by three outputs, Red (red light), Amber (amber light) and Green
(green light). The sequence should be as follows:

1. Red should be lit for 10 seconds.


2. Red and Amber should then be lit for 3 seconds.
3. Green should then be lit for 10 seconds.
4. Amber should then be lit for 3 seconds.
5. Return to 1.

For extra marks, design a programme that will operate two traffic lights. One set of lights is to be used to
control traffic travelling in the N-S direction at a crossroads and the other set is to control traffic travelling in
the E-W direction.

Assignment
You should complete a 4-page (maximum) report describing your solutions to the four problems. You must
also e-mail your saved circuits to muhjawad.786@gmail.com. When you save the circuits please save them
with the file names YourName1.pc5, YourName2.pc5, YourName3.pc5 and YourName4.pc5 for problems 1
to 4 respectively. For YourName use your full name, surname/family name followed by first name.

You might also like