PLC -- Timers and Counters Programming



Home | Forum | DAQ Fundamentals | DAQ Hardware | DAQ Software

Input Devices
| Data Loggers + Recorders | Books | Links + Resources



AMAZON multi-meters discounts AMAZON oscilloscope discounts


This section will introduce common types of timers and counters used in PLC programming with an emphasis on the format used in the Siemens S7-1200 and other families of PLCs. Concepts will be enforced through the use of implemented real industrial application examples.

[Note: Figures and Tables to be added soon!]

Goals:

  • Understand timer types, operation, and implementation.
  • Understand counter types, operation, and implementation.
  • Understand core and special timing instructions.
  • Use timers and counters in industrial process control.

As stated in Section. 1, real-time system behavior is the core issue in most control applications. Timers and counters are critical elements used in programmable logic controllers (PLCs), hardwired controllers, and impeded systems to accommodate an application event and real-time constrains. This section will introduce common types of timers and counters used in PLC programming with emphasis on the format used in the Siemens S7-1200 and other families of PLCs. Concepts will be enforced through the use of implemented real industrial applications.

__1 Timer Fundamentals

Siemens S7-1200 timers are available in four different forms: generate ON DELAY (TON), generate OFF-DELAY (TOF), time accumulator (TONR), and generate pulse (TP). TBL. 1 shows the parameters for the TON, TOF, and TONR timers. Timer instruction preset/accumulated value uses the M (2 words, 16 bits), D (double words, 32 bits), or L (long, 64 bits) memory area, as shown in the data table. The same information for the TP timer is shown in TBL. 2.

__1.1 ON-DELAY Timers (TONs)

This timer's main function is to delay the rising edge of output Q by the pre defined period of the preset time (PT). The timer block is shown in Fig. 1 with appropriate tag names assigned.


AMAZON multi-meters discounts AMAZON oscilloscope discounts


In the figure, these tags are displayed between double quotes. All timer-required variables are displayed using the standard sys tem labels, which start with the percent (%) character. Timer preset-time (PT) input can be defined as displayed or as a constant value.

=== TBL. 1 TON, TOF, and TONR Parameters Start input Duration of the on delay The value of the PT parameter must be positive Output that is set when the time PT expires Current time value

===

TBL. 2 TP Parameters

Parameters | Declaration Data Type Memory Area Description Start input | Duration of the pulse | The value of the PT parameter must be positive

===

If rung input (IN) is TRUE, the timer accumulated value with tag name T_0_ACC will increment. When timer accumulated value is equal to the defined preset value with tag name T_0_PRE, the output Q will change status to ON, and the timer will stop timing. FIG. 2 illustrates the timer timing diagram. Notice that the delay action applies to timer output Q. It turns ON after the prespecified preset time from the point where the timer input is enabled. If the timer enable input is lost before the prespecified preset time, the Q output won’t turn ON. The timer input must stay ON during the entire preset time in order for the output to turn ON. The timer output will turn OFF once the input goes OFF. Please refer to the website …

www.mhprofessional.com/ProgrammableLogicControllers

…for an interactive simulator illustrating the operation of this timer.

FIG. 1 ON-DELAY timer (TON).

FIG. 2 ON-DELAY timing diagram.

FIG. 3 ON-DELAY ladder-logic diagram. Network 1:, Network 2:

FIG. 3 shows a ladder-logic diagram for the TON timer instruction. This diagram assumes a normally open START push button (PB), a normally open STOP push button, a timer preset (PT) value of 10 seconds, output MOTOR1 (Q0.0), and output MOTOR2 (Q0.1). The ladder diagram consists of two net works. The following are the critical events in the shown ladder-logic diagram:

• The first network initially during the first scan, I0.0, is TRUE because the STOP PB is wired high. Also, the START PB is FALSE because this switch is normally open.

• Once the START PB is pressed, I0.1 becomes TRUE; this, in turn, makes Q0.0 TRUE. Q0.0 is the output to MOTOR1 starter, which causes it to run. The next scan, Q0.0, will latch the START PB and maintain the Q0.0 TRUE status.

• The second network, Q0.0, is the input condition for the TON instruction, which is TRUE. This timer has a preset time value of 10 seconds.

• The timer (TON) will start timing. After 10 seconds of delay, Q0.1 will turn ON, causing MOTOR2 to run.

• Pressing the STOP PB at any time will cause MOTOR1 and MOTOR2 to stop.

It also will stop the timer and reset its accumulated time register (ET).

The following two ladder networks explain how the ON-DELAY timer works and how it follows other commonly used notations: TT (timer timing bit), DN (timer done bit), and ACC (timer accumulated value).

• Network 1: When INPUT (I0.0) is TRUE, Timer0 starts trimming. Outputs Timer0_ DN and OUTPUT are FALSE as long as Timer0_ACC did not reach 10.

• Network 2: When Timer0_DN is FALSE, the two compare instructions are executed. Timer0_TT is set, indicating that the timer is timing.

• When Timer0_ACC is greater than or equal to 10, the two outputs Timer0_ DN and OUTPUT are TRUE. Network 2 input will be FALSE, and Timer0_TT goes OFF, indicating that the timer stopped timing.

• The timer timing (TT) bit is not directly available with Siemens ON-DELAY timers (TONs), but it can be generated using Network 2, as shown in Fig. 4.

Other PLCs include the TT bit as part of the instruction for all supported timers.

Instead, Siemens provides pulse timers (TBs), which initiate timing on an input pulse.

FIG. 4 Timer timing (TT) bit.

FIG. 5 OFF-DELAY timer (TOF).

===

Input Time delay Output Start timing Reset timing FIG. 6 OFF-DELAY timing diagram.

===

FIG. 7 OFF-DELAY ladder-logic diagram.

====

__1.2 OFF-DELAY Timers (TOFs)

This timer's main function is to delay the falling edge of output Q by the pre defined period of the preset time (PT). If the input to the instruction (IN) is TRUE, the output Q is set true. When input turns OFF, the timer starts timing. It resets the output Q when the timer accumulated value ET with tag name T_0_ACC is equal to the timer preset value PT with assigned tag name T_0_PRE. FIG. 5 shows the timer, and Fig. 6 illustrates the TOF timing diagram. Please refer to the website for an interactive simulator illustrating the operation of this timer.

FIG. 7 shows a ladder-logic diagram for the TOF timer instruction. This diagram assumes a normally open START push button (PB), a normally closed STOP push button, a timer preset (PT) value of 10 seconds, output MOTOR1 (Q0.0), and output MOTOR2 (Q0.1). The ladder diagram consists of two net works. The following are the critical events in this timer example:

• The first network initially during the first scan, I0.1, is TRUE because the STOP PB is wired high. Also, the START PB is FALSE because the switch is not yet pressed.

• Once the START PB is pressed, I0.0 becomes TRUE; this, in turn, makes Q0.0 TRUE, and MOTOR1 runs. The next scan, Q0.0, will latch around the START PB and maintain Network 1 TRUE status.

• As shown in the second network, Q0.0 is the input condition for the TOF instruction, which is now TRUE.

• The timer (TOF) will set the output Q0.1 ON, causing MOTOR2 to turn ON. So far the two motors are running after pressing the START PB.

• Once the STOP PB is pressed, MOTOR1 loses power and goes OFF. This will cause the TOF timer to start timing.

• After the prespecified delay of 10 seconds is over, the timer output Q0.1 goes OFF. This will cause MOTOR2 to stop. Thus MOTOR2 stops 10 seconds after MOTOR1 is OFF.

• The timer preset value is cleared when TOF is TRUE.

• Pressing the STOP PB at any time while the two motors are running stops MOTOR1, and 10 seconds later MOTOR2 stops.

The network in Fig. 8 shows a simple process-control implementation using three OFF-DELAY timer (TOF) instructions. This network assumes a limit-switch tag name LS1 and three outputs: MOTOR1 Q1.0, MOTOR2 Q1.1, and MOTOR3 Q1.2. Timer preset values of 10, 20, and 30 seconds are used to sequence the operation of the three motors. When LS1 is TRUE, all three motors start running.

If LS1 changes from high to low (OFF state), MOTOR1 turns off after 10 seconds, MOTOR2 turns off after 20 seconds, and MOTOR3 turns off after 30 seconds.

Once LS1 returns back to the TRUE state, the accumulated values of all three timers are cleared.

FIG. 8 A simple process-control implementation using three OFF-DELAY timers.

FIG. 9 Retentive/time-accumulator timer (TONR).

===

FIG. 10 TONR delay timing diagram.

Stop timing hold ACC value Reset timing Time delay Input Output Pulse reset input Time left Continue timing Start timing Time left

===

FIG. 11 TONR delay timing diagram.

--------

Example 1 This application assumes four motors represented by four pilot lights on the trainer unit. A push-button START switch is used to start a sequence of motor operations that can be terminated at any time by pressing a push-button STOP switch. The sequence starts MOTOR1, then MOTOR2, then MOTOR3, and then MOTOR4.

The same sequence will repeat until the process is stopped. Each selected motor will run for a simulated abbreviated period of 5 seconds while the other motors are idle. This timer project was named by our students as the "Merry-Go-Round Project." FIG. 12 shows the implemented application Network 1. When the START PB is pressed, Network 1 turns TRUE, and the PLC processor performs the following steps:

• MOTOR1 coil is set; associated contact from MOTOR1 latches around the START PB and maintains input to Timer 0 and MOTOR1. The timer and MOTOR1 will stop once MOTOR2 turns ON.

• TON Timer 0 starts timing, 5 seconds later, as defined by the preset time (PT),

%M0.0 output tag name TMR0_DN is set.

• MOTOR4 timer's done bit (TMR3_DN) is used to latch the START PB in order for MOTOR1 to restart after MOTOR4 stops.

• This sequence continues as long as the STOP PB remains inactive. STOP PB, when activated, stops all outputs and associated motors.

FIG. 13 shows Network 2. TMR0_DN sets MOTOR2 and Timer 1. MOTOR2 contact latches around TMR0_DN to keep the input to Timer 1 and MOTOR2 TRUE while MOTOR3 is OFF. TON Timer 1 starts timing; 5 seconds later, it sets its output %M0.1 with tag name TMR1_DN. The STOP PB, when activated, stops all outputs and associated motors. MOTOR2 stops once MOTOR3 runs.

FIG. 14 shows Network 3. TMR1_DN sets MOTOR3. Contact from MOTOR3 latches around TMR1_DN to keep the input to Timer 2, and MOTOR3 status TRUE while MOTOR4 is OFF. TON Timer 2 starts timing; 5 seconds later, %M0.2 with tag name TMR2_DN output is set. The STOP PB, when activated, stops all outputs.

FIG. 15 shows Network 4. TMR2_DN sets MOTOR4. Contact from MOTOR4 latches around TMR2_DN to keep the input to the Timer 3 and MOTOR4 status TRUE while MOTOR1 is OFF. TON Timer 3 starts timing; 5 seconds later, TMR3_ DN (%M0.3) output is set. The TMR3_DN (%M0.3) latches around the START PB in Network 1 to restart MOTOR1 and repeat the cycle. The STOP PB, when activated, stops all outputs and associated motors.

FIG. 12 Merry-Go-Round Network 1.

FIG. 13 Merry-Go-Round Network 2.

FIG. 14 Merry-Go-Round Network 3.

FIG. 15 Merry-Go-Round Network 4.

----------

Example 2

This application flashes a pilot light (PL) ON/OFF using a duty cycle indicated by the timer's preset time (PT), tag name T_PRE. The PT value defines the duration of both the ON and OFF times, each set to 2 seconds. FIG. 16 shows Network 1, which uses an AUTO/MANUAL selector switch. When the switch is placed in the AUTO position while the timer done status T_1_DN is OFF, Network 1 status becomes TRUE. Timer 0 starts timing, and 2 seconds later, the pilot light (PL) turns on.

FIG. 16 Flash pilot light, Network 1.

FIG. 17 shows Network 2. PL is used as the input to TON Timer 1. Once PL turns ON, Timer 1 starts timing causing Network 2 output (T_1_DN) to turn ON after a 2-second delay. This, in turn, will cause Timer 0 in Network 1 to reset and restart timing. This logic will cause PL to flash, switching status ON/OFF every 2 seconds.

FIG. 17 Flash pilot light, Network 2.

----------

Example 3

This application uses two motors in a pumping-station facility. Both motors run on the activation of a START push-button switch. The activation of a STOP push-button switch stops Motor 1 immediately and then Motor 2 after 10 hours.

FIG. 18 shows a single network realizing this requirements using an OFF DELAY timer.

FIG. 18

----------

Example 4

Two immersed pumps are each driven by a constant-speed motor. One pump is located in the east wet well and the other in the west wet well. The two wells are connected through controlled piping. Each motor provides a discrete input signal indicating whether the motor is running or not. Motors can be started by activating the AUTO/MAN selector switch on the local panel to the AUTO mode.

The implemented ladder logic acts to alternate operation between the east and west pumps according to the user calendar. FIG. 19 shows Network 1, which recycles the time-accumulator (TONR) timer on an hourly basis. The COUNT_DN is a one-shot flag generated through counter logic, which will be discussed in the next two sections. This flag is TRUE when the calendar accumulated value is greater than or equal to the user calendar time.

FIG. 19 Pump alteration, Network 1.

FIG. 20 shows Network 2, which increments the register tag name (INCR) when the calendar accumulated value is greater than or equal to the user calendar time.

The positive edge instruction is used to prevent the INCR register from overflowing.

The ADD instruction is detailed in Chap. 4.

FIG. 20 Pump alteration, Network 2.

FIG. 21 shows Network 3, which toggles the east pump on the status of the least significant bit (M9.0) of the increment register (INCR) when the user calendar expires. (Notice that the processor swaps the two memory bytes.)

FIG. 21 Pump alteration, Network 3.

FIG. 22 shows Network 4, which toggles the west pump on the status of the least significant bit (M9.0) of the increment register (INCR) when the user calendar expires.

FIG. 22 Pump alteration, Network 4.

----------

__1.3 Retentive/Time-Accumulator Timers (TONRs)

The time-accumulator timer (TONR) works exactly the same as the ON-DELAY timer except that the accumulated value is retained while the timer instruction is inactive. To reset the accumulated value to zero, a positive pulse-input instruction is required at the reset input (R). FIG. 9 shows the timer, and Fig. 10 illustrates the timer timing diagram. Please refer to the website for an interactive simulator illustrating the operation of this timer.

FIG. 11 shows a ladder-logic diagram for the TONR timer instruction. The TONR ladder-logic diagram shown has an AUTO/MANUAL selector switch, and the timer preset value is set to 1 hour. Once the selector switch is placed in the AUTO mode, the network turns TRUE. The processor scans the ladder, and the following events are observed:

• The timer starts timing once the selector switch is placed in the AUTO mode. If the selector switch is placed in the MANUAL mode, the timer stops timing, and the timer accumulated value is retained.

• Once the switch is placed back in the AUTO mode, the timer starts timing from where it left off.

• Once the timer accumulated value ET (ONE_HR_ACC) equals the preset value PT (ONE_HR_PT), the timer output (ONE_HOUR_DN) is set to TRUE. The accumulated-value ET (ONE_HR_ACC) is reset to zero at any time by initiating the one scan pulse applied to the timer reset input (R).

• The TONR in this example continuously recycles on an hourly basis.

__2 Counters Fundamentals

Siemens S7-1200 Counters are available in three different forms: count up (CTU), count down (CTD), and count up and count down counter (CTUD). TBL. 3 shows the basic parameters for the CTU, CTD, and CTUD. Operation of the three types of counters will be detailed in the next three subsections. An implemented counter application will be analyzed in Sec. 3.2.4. The concepts covered in this section follows the Siemens notations but can be applied to other PLC brands with minor modification.

--------

TBL. 3 CTU, CTD, and CTD Parameters

Parameter Data Type Description CU, CD BOOL Count up or count down, by one count R(CTU, CTUD) BOOL Reset count value to zero LOAD (CTD, CTUD) BOOL Load control for preset value PV SINT, INT, DINT, USINT, UINT, UDINT Preset count value Q, QU BOOL True if CV >= PV QD BOOL True if CV <= 0 CV SINT, INT, DINT, USINT, UINT, UDINT Current count value

--------

__2.1 Count Up Counters (CTU)

The count up counter's main function is to increment the current value each time the input to the counter transitions from 0 to 1. If the current count value (CV) is equal to the preset value (PV), the output Q is set. When reset input (R) is TRUE, the accumulated value resets to 0. Counter preset input can be defined as a tag name or a constant value. The counter block is shown in Fig. 23 with appropriate tag names assigned. These tags are displayed between double quotes in the figure. All counter required variables are displayed using the standard system labels, which start with the percent (%) character. Counter preset input can be defined as a tag name or a constant value. FIG. 24 provides the timing diagram for this timer.

FIG. 23 Counter block.

FIG. 24 CTU timing diagram with PV = 4.

FIG. 25 CTU ladder-logic diagram.

FIG. 25 shows two networks to illustrate the CTU instruction. The first network assumes a normally open START push button (I0.0), a normally closed STOP push button (I0.1), an AUTO selector switch (I0.2), motor output (Q0.0), and an OFF-DELAY timer with a preset time (PT) of 3 seconds. The second net work uses an ON-DELAY timer with a preset time (PT) of 2 seconds, count up instruction with preset value (PV) of 100, positive edge instruction (M1.2), and an output pilot light (Q0.1). The START push button runs the motor immediately, which drives a conveyor system. Once the conveyor system runs, an input is received from the motor magnetic starter indicating successful system start (MOTOR_RUN). The motor runs for the duration to allow a preset number of parts to be transported over the conveyor system, which is set to 100 in our case. Below are the critical steps for this example:

• The first network initially is FALSE during the first scan because the STOP push button (I0.1) is wired high. Also, the START push button is FALSE because this switch is not pressed (normally open push button), and the AUTO mode (I0.2) is set.

• Once the START push button is pressed, I0.0 becomes TRUE, Timer 0 output will be TRUE, making Q0.0 TRUE (the output to Motor 1) and causing Motor 1 to run. During the next scan, Q0.0 will latch around the START push button and maintains the first network TRUE.

• The second network has I0.4 as an input, which becomes TRUE once the motor starts running and enables the CTU instruction.

• When the motor running input (MOTOR_RUN) is set, indicating that the conveyor is moving, a photoelectric cell will issue a positive narrow pulse as a part crosses its beam, which causes the CTU current value (CV) to increment.

CTUD instruction block and Fig. 30 provide the timing diagram for the up and down counter for a PV value stored in a tag named COUNT_PRE. The output QD tag named COUNT_DOWN_OUT is used to indicate that the current count value is less than or equal to 0. It’s set to 1 when the counter CV is less or equal to 0. A counter load does not affect the status of the QD output. The counter QU output is set once the current count value is equal to or larger than the pre-assigned preset value (PV). QU is reset once the CV falls below the PV. Load and reset have no effect on QU. This counter does not overflow. Once it reaches the maximum value for the assigned memory format, it does not increment. QD is used to indicate a counter underflow situation.

FIG. 31 shows a ladder-logic diagram for the CTUD counter instruction.

It has four inputs (PE1, PE2, RESET, and LOAD), two outputs (COUNT_UP and COUNT_DOWN), and two parameters (COUN_CV and COUNT_PV). The network representing this function has the following critical events:

• A photoelectric cell (PE1) counts the parts in a certain conveyor line. PE2 counts the rejected parts from the conveyor line. The RESET signal, when TRUE, resets the current count value (COUNT_CV) to 0. A TRUE LOAD signal sets the count value at the COUNT_CV output to the value of the COUNT_PV parameter. As long as the LOAD or RESET input signal is TRUE, the signal at the CU and CD inputs has no effect on the instruction.

• When the PE1 input signal transitions from 0 to 1, the current count value increments.

• When the PE2 input signal transitions from 0 to 1, the current count value decrements.

• The current count value represents the number of good parts processed by the photoelectric cells on the conveyor line.

• If the current count value is greater than or equal to the value of the PV parameter, the QU output is set.

• If the current count value is less than or equal to zero, the QD output is set.

FIG. 30 CTUD timing diagram with PV = 4.

FIG. 31 Ladder-logic diagram for the CTUD instruction.

__2.4 Implemented Counter Applications

This feed-flow application allows 32,000 gal of liquid to flow into an empty reactor tank ( Fig. 32). It uses a limit switch with tag name LS_VALVE mounted on a valve. This switch closes while the liquid feed valve is open. The counter PV represents thousands of gallons and is set to 32. Thus each count increment is equivalent to 1000 gal of flow. FEED_FLOW is memory register containing the accumulated flow amount in gallons. The following are the critical events for this application:

• Network1 limit switch input (LS_VALVE) is set when the valve is open. Once FEED_FLOW is greater than or equal to 1000, the counter increments the count current value (COUNT_CV). When COUNT_CV is greater than or equal to 32, which is equivalent to 32,000 gal, the counter output Q is set. The counter current count value resets to 0 during the next program scan.

• In Network 2, when the valve is open and FEED_FLOW is greater than or equal to 1000, its value is reduced by 1000.

FIG. 32 Feed flow control.

__3 Special Timing Instructions

Two commonly used special timing instructions will be discussed in this section: the pulse timer (generate pulse timer) and the positive-edge/negative-edge instructions. An implemented ladder-logic program also will show the application of such timers in real-time industrial-control situations.

__3.1 Pulse Generation/Pulse Timer (TP)

A pulse timer (TP) generates a pulse with a preset width time. If the rung input is TRUE, the output Q is set TRUE for the period identified by the preset value PT, tag name T_PRE. FIG. 33 shows the TP instruction block, and Fig. 34 pro vides the TP timing diagram.

FIG. 35 shows the ladder-logic diagram for the TP timer instruction.

This diagram assumes a normally open input M27.6 pulse signal, tag name VG1

_AUTO_START; a timer preset TP, tag name VG1_PRE, with a value of 15 seconds; and output Q0.0, tag name VG1_RAISE. When the START pulse (VG1_AUTO_START) is set, the network is TRUE, and the TP timer output Q is set for 15 seconds, causing vertical gate Motor 1 to run for 15 seconds, which raises the vertical gate.

FIG. 33 PT block.

FIG. 34 TP timing diagram.

FIG. 35 TP ladder-logic diagram.

__3.2 One-Shot Operations

The one-shot instruction (scan operand for positive or negative signal edge in Siemens PLCs) is designed to detect a positive or a negative signal edge. The two types are detailed below. The names one shot and positive edge/negative edge are used interchangeably in the literature.

--|P|--: Scan Operand for Positive Signal Edge

The scan operand for a positive signal edge instruction compares the current signal state of OPERAND_1 with the signal state of the previous scan stored in edge memory bit M17.0, tag named OPERAND_2. If the instruction detects a change between the two operands, a positive rising edge is produced for only one scan ( Fig. 36).

FIG. 36 Scan operand for a positive signal edge.

--|N|--: Scan Operand for Negative Signal Edge

The scan operand for a negative signal edge instruction compares the current signal state of OPERAND_1 with the signal state of the previous scan stored in edge memory bit M17.1, tag named OPERAND_2. If the instruction detects a change between the two operands, a negative fallen edge is produced for only one scan ( Fig. 37). TBL. 4 illustrates the parameters for the positive/negative signal edge instructions. If more than one edge instruction is used, the associated memory bit (Operand 2) must be unique for each instruction. These instructions are used commonly for initialization, data-block transfers, and event detection.

FIG. 37 Scan operand for a negative signal edge.

TBL. 4 Scan Operand for Positive/Negative Signal Edge Instructions: Parameter Declaration Data Type Memory Area Description

__3.3 Implemented One-Shot Application

FIG. 38 shows an organizational block (OB100) initialization. On power up, the program initializes a set of values. This action is achieved by placing the code in a startup organizational block (OB100), as shown in the figure, without the use of the ONS/positive-edge trigger instruction, as was done in Section. 2. All the code included in a startup OB executes one time when the operating mode of the CPU changes from STOP to RUN.

The startup program consists of one or more startup OBs ( OB numbers 100 or

=123). The startup program is executed one time when the PLC transitions from STOP mode to RUN mode. After complete execution of the startup OBs, the process image of the inputs is read in, and the cyclic program is started. FIG. 38 shows the configuration of startup OB100. The following are the steps needed to create a startup OB:

• Click "Add new block."

• Click "Organizational block."

• Click "Startup." Automatically, the number 100 will be assigned to the Startup OB.

The MOV instruction shown in Fig. 39 was implemented in Section. 2 (Example 2.3) using the scan operand for a positive signal edge, which is a one-shot (OS) logic used to reset the timers' preset values. In this example, the MOVE instruction is placed in the OB100 to clear all timer preset values when the PLC processor switches from STOP to RUN.

FIG. 38 Startup OB initiation.

FIG. 39 Startup OB trigger ladder-logic diagram initialization.

__3.4 Implemented Counter Applications

The PLC counters and timers instructions covered earlier in this section function in a similar way. The timer instructions will continually increment the assigned accumulated value at a rate determined by the time base when the contacts that power the instruction are enabled. On the other hand, the counter requires a complete enable-contact transition from open to close each time it increments/ decrements the accumulated value. This means that the contacts must return to their open state before they can transition for a second time. The counter does not care how long the contacts stay closed once they transition; it only looks for the transition. The transition must take place at a rate less than the PLC program scan rate; otherwise, some transitions can be lost.

----------

Example 5

FIG. 40 shows a tank flow process. This application uses counters in the implementation of tank process control. It assumes two solenoid valves, FILL (SV1) and DRAIN (SV2). The tank level sensor is simulated by a count up and down (CTUD) counter. If the tank level is greater than or equal to 10 m, drain the tank by activating SV2, and if tank level is less than or equal to 1 m, fill the tank by activating SV1.

===

FIG. 40 Tank level and flow control. Fill SV1 Flow in Tank level sensor Drain SV2 Flow out

===

The Siemens PLC S7 implementation detailed next uses a processor built-in flash bit to simulate the tank filling and draining actions. It assumes a 1-m level increase during filling per flash and a 1-m decrease in level during draining per flash. Three ladder networks are used to implement this part of the specification.

The ladder networks are listed below with brief details:

Network 1 ( Fig. 41). An up/down counter (CTUD) controls the liquid level in the tank, which is given the name TANK_LEVEL. The PLC %M100.5 bit flashes once every second, which simulates a 1-m change in tank level. Tank control is active when the AUTO/MANUAL selector switch is set to the AUTO position. The STOP push button, which is wired high, will reset the counter when activated.

FIG. 41

Network 2 ( Fig. 42). Stop tank filling and start draining when the tank is full; the tank level is equal to or greater than 10 m.

FIG. 42

Network 3 ( Fig. 43). Start tank filling and stop draining when the tank level is high; the tank level is less than or equal to 1 m.

FIG. 43

------------

Example 6

This control process counts the number of rejected parts on a conveyor line by monitoring the number of time a solenoid valve goes from OFF to ON. If the number of rejected parts reaches 100, the conveyor line motor is turned OFF. A RESET push button, when pressed, clears the counter accumulated value. The START and the STOP push buttons serve the normal functions of starting and stopping the PLC- control process/motor M1. The solenoid valve SV1 is activated at an inspection station once for every rejected part. Inspection and rejection of assembled/produced items are typical in manufacturing assembly. Excessive rejection is an alarming condition that warrants shutdown of production until necessary corrections are carried out by the operator. The two network ladder-logic diagrams in Figs. 3.44 and 3.45 implement the required control specification.

FIG. 44

FIG. 45

-----------

Homework Problems and Lab Projects

Problems

__1 Explain the difference between ON-DELAY timer (TON) and retentive timer (TONR) instructions.

__2 Complete the timing diagram for the ON-DELAY (TON) timer in Fig. 46. The input signal is the timer enabling input, whereas the output is derived by the timer done bit. Indicate when the timer accumulated value starts and stops timing.

__3 The ladder network shown in Fig. 47 was programmed to recycle a timer on an hourly basis. When the program was tested, it did not work correctly. Explain why.

__4 Examine the networks shown in Fig. 48 and answer the following questions:

a. What is the status of Motor 1 if LS1 is OFF?

b. What is the status of Motor 1 if LS1 is ON for 30 seconds?

c. What is the value of the timer accumulated value when LS1 is OFF?

d. What is the status of Motor 2 when LS1 is ON for 10 seconds?

e. What is the status of SOL1 and SOL2 if LS1 is OFF?

__5 Write a ladder-logic program to turn ON Motor 1 when the START push button is pressed.

Ten seconds later, Motor 2 turns ON. The STOP push button stops both motors.

__6 A motor is to be controlled from two different locations A and B. Each location has a START/STOP push button to control the motor. Draw a logic diagram to show how the motor can be controlled from either location.

__7 Write a ladder-logic program to turn Motor 1 and Motor 2 on when the START push button is pressed. The STOP push button stops Motor 1; 5 seconds later, Motor 2 stops.

__8 Examine the networks in Fig. 49 and answer the following questions:

a. What is the status of Motor 1 if LS1 is OFF?

b. What is the status of Motor 1 if LS1 is ON for 20 seconds?

c. What is the timer accumulated value when LS1 is OFF?

d. What is the status of Motor 2 when LS1 is ON after 10 seconds?

e. What is the status of SOL1 and SOL2 if LS1 is OFF?

FIG. 46 Time delay; Input, Output

FIG. 47

FIG. 48

FIG. 49

__9 Assume that PB1 is a normally open momentary switch. Examine the networks in Fig. 50 and answer the following questions:

a. What is the status of Motor 1 and Motor 2 if LS1 is ON for 40 seconds and PB1 is not pressed?

b. What is the status of Motor 1 if LS1 is ON for 60 seconds and then OFF for 40 seconds and PB1 is not pressed?

c. What is the status of the Motor 2 when LS1 is OFF?

d. What is the status of SOL1 and SOL2 if LS1 is ON for 50 seconds?

FIG. 50

__10 A fan is to be controlled from two locations A or B. A START A/START B push button starts the fan from either location. A STOP A/STOP B push button, when pressed, stops the fan from either location. Perform the following:

a. Write a ladder-logic program to control the fan.

b. Document the program using a logic diagram.

__11 A START push button is used to start a sequence of pilot lights (simulating real motors), which can be terminated at any time by pressing a STOP push button. The sequence starts PL1, then PL2, and then PL3. The same sequence will repeat until the process is stopped.

Each selected pilot light will turn ON for a period of 3 seconds while the other pilot lights are off. Perform the following tasks:

a. Write a ladder-logic program to sequence the pilot lights as specified.

b. Modify the ladder logic to stop the pilot lights if the sequence is repeated five times.

FIG. 53

FIG. 54

FIG. 55

__15 Study the networks in Fig. 53 for the down counter (CTD), and answer the following questions:

a. What condition(s) should be met for Motor 1 (M1) to run?

b. What condition(s) should be met for Pilot light 1 (PL1) to turn ON? 3.16 Study the network in Fig. 54 assuming that the counter preset value with tag name COUNT_PRE holds the value of 10. Answer the following questions:

a. What is the counter preset value when PB3 is pressed?

b. What is the counter preset value when PB3 is activated 12 times and PB2 is activated 15 times?

c. What is the counter preset value when PB4 is pressed?

d. Under what conditions PL1 will turn ON? 3.17 Write a ladder-logic program for the cooling-system control shown in Fig. 55. The temperature must be maintained below 0°C. Temperature fluctuations are monitored by means of a sensor. If the temperature rises above 0°C, the cooling system switches on for a predetermined time. The cooling-system-on lamp is lit during this time.

The cooling system and lamp are turned OFF if one of the following conditions is fulfilled:

• The sensor reports a temperature fall below 0°C.

• The preset cooling time has elapsed.

• The push-button switch STOP has been pressed.

If the preset cooling time has expired and the temperature in the cold room is still too high, the cooling system can be restarted by means of the push-button switch RESET. Hint: Use TP (generate pulse instruction).

__18 Write a PLC program to flash a pilot light (PL) ON/OFF. The pilot light (PL) is ON for 5 seconds and OFF for 3 seconds. Hint: Use two TON timers.

__19 Write a PLC program to allow the operator to run the conveyor line for luggage transportation by pushing a START push button. The START push button is a normally open momentary switch, and the STOP push button is normally closed and wired high. The following is a brief process description:

a. When the operator pushes START, flash a pilot light (PL) every 2 seconds to warn people that the conveyor belt is about to start.

b. After 80 seconds, start the conveyor motor, and turn off the pilot light.

c. The operator stops the conveyor line by pushing the STOP push button.

__20 Modify Problem 19 to count the number of bags on the conveyor line, and stop the motor after 100 bags have passed. Add sensors as needed.

__21 A parking lot has two momentary action sensors to count the number of cars entering or exiting the garage. One sensor is placed at the entrance, and the other is placed at the exit.

Two messages should be displayed to customers indicating the status of the parking lot ("Parking is Full" or "Parking is Empty"). Parking full is simulated by PL1, and parking empty is represented by PL2. Write and document a ladder-logic program to implement this process.

Projects

Lab 1: Machine Tool Operation

The objective of this Lab is to get the reader familiar with basic timing and counting instructions used to control a machine tool operation.

Machine Tool Process Descriptions

A machine tool consists of five stations: robot pickup and placement of parts (Station 1), pallet feed (Station 2), stationary paint (Station 3), inspection (Station 4), and rejection (Station 5). Station 1 operation starts by a robot unloading the finished parts and placing the unfinished parts. Station 2 regulates the feed rate of the pallets that carry the parts on the conveyor line. Station 3 is a paint workstation. Its function is to spray-paint the edge of a printed circuit, the unfinished part. Station 4 is the inspection station, which has 10 piano fingers, five up and five down. Its function is to check on the sprayed paint by closing the up and down piano fingers on the edge of the printed circuit and reporting 1 or 0 based on the paint status. For good paint, a 1 should be reported. Station 5's main function is to reject the badly painted parts after receiving a signal from Station 4. Station 3 is the focus of this Lab and is described next.

Station 3 (Spray Paint) Operations

A part in place limit switch (LS1) is located at the station to indicate that a part exists at the paint work area.

• A solenoid valve (SV1), when energized, will raise the pallet to the level of the spray paint chamber.

• A limit switch (LS2) is placed in the upper location, and when closed, it indicates that the part is up at the level of the spray-paint chamber.

• The spraying time is 5 seconds.

• When the spray-paint cycle is done, the solenoid valve (SV1) should deenergize to lower the pallet to the conveyor-belt level.

• Conveyor-belt and feed-rate control are not part of this Lab.

Lab Requirements Write a ladder-logic program for Station 3 (paint workstation) to raise the pallet that carries the printed circuit, maintain it in the paint chamber for 5 seconds, and lower the painted part to return the conveyor belt.

a. Assign the I/O addresses.

b. Assign the bit addresses.

c. Assume and use any sensors required to control the spray-paint process.

d. Apply the concept of what-if scenarios to check on and resolve any unusual conditions.

e. Check out the program and document the ladder-logic program using logic diagrams.

Lab 2: Conveyor System Control

The objective of this Lab is to familiarize users with the basic timing and counting instructions used in conveyor-system control. A part is moving on a conveyor line crossing a photoelectric cell. The photoelectric cell function is primarily to count parts. The conveyor line stops after 100 parts are counted.

Design Specs:

Design and implement a documented ladder-logic program to satisfy the following sequence of operations:

a. The START push button starts the conveyor motor after a 5-second delay. The motor must start only if the AUTO/MANUAL switch is placed in the AUTO position. The photoelectric cell should count only when the motor is running.

b. When the count reaches 3, stop the conveyor after a 2-second delay.

c. The ON pilot light indicates the end of the sequence.

d. The STOP switch, when activated, takes the system to initial conditions.

e. The operator can restart the same sequence by activating the START switch.

NOTE Use SS1 for the photoelectric cell input signal, SS2 for the motor running input indication signal, PL1 for the motor starting output signal, and PL2 for the pilot light output signal.

Lab Requirements:

a. Assign the system inputs and outputs.

b. Enter the networks shown in Fig. 56.

c. Add comments to each network.

d. Download the program and go online.

e. Simulate the program using the training unit's I/O or the Siemens simulator, and verify that the program is running according to the process description.

f. Modify this Lab such that the part count is retained if the operator activates a new switch HALT while the motor is running. The HALT switch stops the motor and halts the counter operation. Reactivation of the HALT switch will start the motor and resume the part count.

Lab 3: Pump Fail-to-Start Alarm

The objective of this Lab is to get users familiar with the methods used to trigger an alarm if a motor fails to start using the timer TON instruction. For each of the following pump start/pump stop digital outputs, search the program listed in Fig. 57 for the following:

a. List the conditions for successful pump start/pump stop.

b. Change the timer preset value for fail to start, fail to stop, start, and stop operation.

c. Use large values of preset time, and monitor the program operation in the PLC.

d. Simulate and monitor the pump fail alarms.

FIG. 56

FIG. 57 .

NEXT

PREV.

All related articles   Top of Page   Home



Updated: Friday, February 18, 2022 12:47 PST