Experiment (4) Ladder Logic Programming
Experiment (4) Ladder Logic Programming
Objectives
This experiment aims to:
1- Introduce the set and reset coil instructions.
2- Understand the function of timers, counters and logic operators in ladder logic
programming.
3- Use timers, counters and logic operators in different applications.
4- Be able to perform sequence dependent operations.
Theory
Description: ---( S )--- (Set Coil) is executed only if the RLO of the preceding instructions is "1"
(power flows to the coil). If the RLO is "1" the specified <address> of the element is set to "1".
An RLO = 0 has no effect and the current state of the element’s specified address remains
unchanged.
The following example illustrates the operation of set coil instruction, see figure 2:
The signal state of output Q4.0 is "1" if one of the following conditions exists:
• The signal state is "1" at inputs I0.0 and I0.1
• Or the signal state is "0" at input I0.2.
Mechatronics Systems Design Lab
If the RLO is "0", the signal state of output Q4.0 remains unchanged.
Description: ---( R )--- (Reset Coil) is executed only if the RLO of the preceding instructions is
"1" (power flows to the coil). If power flows to the coil (RLO is "1"), the specified <address> of
the element is reset to "0". A RLO of "0" (no power flow to the coil) has no effect and the state
of the element’s specified address remains unchanged.
The <address> may also be a timer (T no.) whose timer value is reset to "0" or a counter (C no.)
whose counter value is reset to "0".
The following example illustrates the operation of reset instruction, see figure 4:
The signal state of output Q4.0 is reset to "0" if one of the following conditions exists:
• The signal state is "1" at inputs I0.0 and I0.1
• Or the signal state is "0" at input I0.2.
If the RLO is "0", the signal state of output Q4.0 remains unchanged.
The signal state of timer T1 is only reset if:
• the signal state is "1" at input I0.3.
The signal state of counter C1 is only reset if:
• the signal state is "1" at input I0.4..
2
Mechatronics Systems Design Lab
Description: S_ODT (On-Delay S5 Timer) starts the specified timer if there is a positive edge at
the start (S) input. A signal change is always necessary in order to enable a timer. The timer runs
for the time interval specified at input TV as long as the signal state at input S is positive. The
signal state at output Q is "1" when the timer has elapsed without error and the signal state at the
S input is still "1". When the signal state at input S changes from "1" to "0" while the timer is
running, the timer is stopped. In this case the signal state of output Q is "0". The timer is reset if
the reset (R) input changes from "0" to "1" while the timer is running. The current time and the
time base are set to zero. The signal state at output Q is then "0". The timer is also reset if there is
a logic "1" at the R input while the timer is not running and the RLO at input S is "1". The
current time value can be scanned at the outputs BI and BCD. The time value at BI is binary
coded, at BCD is BCD coded. The current time value is the initial TV value minus the time
elapsed since the timer was started.
Table 1 illustrates the function of each parameter of on-delay S5 timer:
Table 1: On-delay S5 timer parameters
Parameter Data type Description
T no. Timer Timer identification number; range depends on CPU
S Bool Start input
TV S5Time Preset time value
R Bool Reset input
BI Word Remaining time value, integer format
BCD Word Remaining time value, BCD format
Q Bool Status of the timer
Figure 6 shows the timing diagram for on-delay S5 timer:
3
Mechatronics Systems Design Lab
The following example illustrates the operation of on-delay timer, see figure 7:
If the signal state of I0.0 changes from "0" to "1" (positive edge in RLO), the timer T5 will be
started. If the time of two seconds elapses and the signal state at input I0.0 is still "1", the output
Q4.0 will be "1". If the signal state of I0.0 changes from "1" to "0", the timer is stopped and Q4.0
will be "0" (if the signal state of I0.1 changes from "0" to "1", the time is reset regardless of
whether the timer is running or not).
Description: ---( P )--- (Positive RLO Edge Detection) detects a signal change in the address
from "0" to "1" and displays it as RLO = "1" after the instruction. The current signal state in the
RLO is compared with the signal state of the address, the edge memory bit. If the signal state of
the address is "0" and the RLO was "1" before the instruction, the RLO will be "1" (pulse) after
this instruction, and "0" in all other cases. The RLO prior to the instruction is stored in the
address.
Table 2 illustrates the function of each parameter of Positive RLO Edge Detection:
Table 2: Positive RLO edge detection parameters
Parameter Data type Description
<adress> Bool Edge memory bit, storing the previous signal state of RLO
The following example illustrates the operation of Positive RLO Edge Detection, see figure 9:
4
Mechatronics Systems Design Lab
The edge memory bit M0.0 saves the old RLO state. When there is a signal change at the RLO
from "0" to "1", the program jumps to label CAS1.
The following example illustrates the operation of Negative RLO Edge Detection, see figure 11:
The edge memory bit M0.0 saves the old RLO state. When there is a signal change at the RLO
from "1" to "0", the program jumps to label CAS1.
5
Mechatronics Systems Design Lab
Up Counter (S_CU)
Figure 12 shows the symbol of S_CU up counter.
Description: S_CU (Up Counter) is preset with the value at input PV if there is a positive edge at
input S. The counter is reset if there is a "1" at input R and the count value is then set to zero.
The counter is incremented by one if the signal state at input CU changes from "0" to "1" and the
value of the counter is less than "999". If the counter is set and if RLO = 1 at the inputs CU, the
counter will count accordingly in the next scan cycle, even if there was no change from a
positive to a negative edge or vice versa. The signal state at output Q is "1" if the count is greater
than zero and "0" if the count is equal to zero.
Table 4 illustrates the function of each parameter of S_CU (Up Counter):
Table 4: S_CU (Up Counter) Parameters
Parameter Data type Description
C no. Counter Counter identification number; range depends of CPU
CU Bool Count up input
S Bool Start input for presetting counter
PV Word Value for presetting counter
Enter counter value as C#<value> in the range from 0 to 999
R Bool Reset input
CV Word Current counter value, hexadecimal number
CV_BCD Word Current counter value, BCD coded
Q Bool Status of the counter
The following example illustrates the operation of S_CU (Up Counter), see figure 13:
6
Mechatronics Systems Design Lab
If I0.2 changes from "0" to "1", the counter is preset with the value of MW10. If the signal state
of I0.0 changes from "0" to "1", the value of counter C10 will be incremented by one - unless the
value of C10 is equal to "999". Q4.0 is "1" if C10 is not equal to zero.
Description: CMP ? I (Compare Integer) can be used like a normal contact. It can be located at
any position where a normal contact could be placed. IN1 and IN2 are compared according to the
type of comparison you choose. If the comparison is true, the RLO of the function is "1". It is
linked to the RLO of the whole rung by AND if the box is used in series, or by OR if the box is
used in parallel.
IN1 and IN2 are compared according to the type of comparison you choose:
• ==: IN1 is equal to IN2
• <>: IN1 is not equal to IN2
• >: IN1 is greater than IN2
• <: IN1 is less than IN2
• >=: IN1 is greater than or equal to IN2
• <=: IN1 is less than or equal to IN2
Table 5 illustrates the function of each parameter of comparison instructions:
Table 5: Comparison instructions parameters
Parameter Data type Description
box input Bool Result of the previous logic operation
box output Bool Result of the comparison, is only processed further if the RLO at the box
input = 1
IN1 INT First value to compare
IN2 INT Second value to compare
The following example illustrates the operation of comparison instructions, see figure 15:
7
Mechatronics Systems Design Lab
Description: MOVE (Assign a Value) is activated by the Enable EN Input. The value specified
at the IN input is copied to the address specified at the OUT output. ENO has the same logic
state as EN. MOVE can copy only BYTE, WORD, or DWORD data objects.
Table 6 illustrates the function of each parameter of MOVE instruction:
Table 6: MOVE instruction parameters
Parameter Data type Description
EN Bool Enable input
ENO Bool Enable output
IN All elementary data types with a length of 8, 16, or 32 bits Source value
OUT All elementary data types with a length of 8, 16, or 32 bits Destination address
The following example illustrates the operation of MOVE instruction, see figure 17:
8
Mechatronics Systems Design Lab
Equipment
1- Computer with SIMATIC software.
2- Siemens S7-400 PLC
3- LEDs.
4- Switches.
5- Connecting wires.
Procedures
9
Mechatronics Systems Design Lab
In this example we have one button and a light. First time we press on the button the light will go
on and the second time we press the button; in other word we want this button to work exactly
like a toggle button.
1- Connect one switch to the digital input module.
2- Connect one LED to the digital output module.
3- Write down the ladder diagram to implement this function using SIMATIC Manager
software.
4- Download the program to the PLC.
Part 6: Traffic light
The following represents the sequence of operation of the traffic light:
• Red light on
Yellow light off
Green light off
Delay 20 seconds
• Red light off
Yellow light on
Green light off
Delay 5 seconds
• Red light off
Yellow light off
Green light on
Delay 20 seconds
• Red light off
Yellow light on
Green light off
Delay 5 seconds
• Repeat
1- Draw the hard wiring diagram then connect the required hardware (LEDs, Switches …).
2- Write down the ladder diagram to implement this function using SIMATIC Manager
software.
3- Download the program to the PLC.
10
Mechatronics Systems Design Lab
5) Refer to SIMATIC Ladder Logic (LAD) for S7-300 and S7-400 Programming Reference
Manual and illustrate the function of S_OFFDT Off-Delay S5 Timer? Compare it with
S_ODT On-Delay S5 Timer?
11