PLC Functions and Instructions
- Relay-type (Basic) instructions: I, O, OSR, SET, RES, T, C
- Data Handling Instructions:
- Data move Instructions: MOV, COP, FLL, TOD, FRD, DEG, RAD (degrees to radian).
- Comparison instructions: EQU (equal), NEQ (not equal), GEQ (greater than or equal), GRT (greater than).
- Mathematical instructions.
- Continuous Control Instructions ( PID instructions ).
- Program flow control instructions: MCR (master control reset), JMP, LBL, JSR, SBR, RET, SUS, REF
- Specific instructions:
- BSL, BSR (bit shift justify/right), SQO (sequencer output), SQC (sequencer compare), SQL (sequencer load).
- High speed counter instructions: HSC, HSL, RES, HSE
- Communication instructions: MSQ, SVC
- ASCII instructions: ABL, ACB, ACI, ACL, CAN
Study the different types of PLC Instructions and functions used in PLC programming.
Auxiliary relays, markers, flags, coils, bit storage.
Used to hold data, and behave like relays, being able to be switched on or off and switch other devices on or off. They do not exist as real-world switching devices but are merely bits in the storage memory.
Internal Relays Use
In programs with multiple input conditions or arrangements. For latching a circuit and for resetting a latch circuit. Giving special built-in functions with PLCs.
Retentive relays (battery-backed relays)
Such relays retain their state of activation, even when the power supply is off. They can be used in circuits to ensure a safe shutdown of plant in the event of a power failure and so enable it to restart in an appropriate manner.
Latch Instructions (Set and Reset)
The set instruction causes the relay to self-hold, i.e. latch. It then remains in that condition until the reset instruction is received.
The latch instruction is often called a SET or OTL (output latch).
The unlatch instruction is often called a RES (reset), OTU (output unlatch) or RST (reset).
Timer is an instruction that waits a set amount of time before doing something (control time). Timers count fractions of seconds or seconds using the internal CPU clock. The time duration for which a timer has been set is termed the preset and is set in multiples of the time base used.
Most manufacturers consider timers to behave like relays with coils which when energized result in the closure or opening of contacts after some preset time. The timer is thus treated as an output for a rung with control being exercised over pairs of contacts elsewhere. Others treat a timer as a delay block which when inserted in a rung delays signals in that rung reaching the output.
- On-Delay timer- simply “delays turning on”. It is called TON, TIM or TMR.
- Off-Delay timer- simply “delays turning off”. It is called TOF and is less common than the on-dellay type.
- The on/off delay timers above would be reset if the input sensor wasn’t on/off for the complete timer duration.
- Retentive or Accumulating timer- holds or retains the current elapsed time when the sensor turns off in mid-stream. It is called RTO or TMRA.
This type of timer needs 2 inputs.
We need to know 2 things when using timers:
What will enable the timer?
Typically this is one of the inputs (a sensor connected to one input).
How long we want to delay before we react?
Wait x seconds before we turn on a load.
- When the instructions before the timer symbol are true the timer starts “ticking”.
- When the time elapses the timer will automatically close its contacts.
- When the program is running on the plc the program typically displays the current value.
- Typically timers can tick from 0 to 9999 (16-bit BCD) or 0 to 65535 times (16-bit binary).
There are software and Hardware Errors when using a timer.
- Input error depending upon when the timer input turns on during the scan cycle.
- Output error depending upon when in the ladder the timer actually “times out” and when the plc finishes executing the program to get to the part of the scan when it updates the outputs.
- Total software error is the sum of both the input and output errors…
There is a hardware input error as well as a hardware output error. The hardware input error is caused by the time it takes for the plc to actually realize that the input is on when it scans its inputs. Typically this duration is about 10ms (to eliminate noise or “bouncing” inputs).
The hardware output error is caused by the time it takes from when the plc tells its output to physically turn on until the moment it actually does. Typically a transistor takes about 0.5ms whereas a mechanical relay takes about 10ms.
A counter is set to some preset value and, when this value of input pulses has been received, it will operate its contacts.
The counter accumulated value ONLY changes at the off to on transition of the pulse input.
Typically counters can count from 0 tto 9999, -32,768 to +32,767 or 0 to 65535.
The normal counters are typically “software” counters – they don’t physically exist in the plc but rather they are simulated in software. A good rule of thumb is simply to always use the normal (software) counters unless the pulses you are counting will arive faster than 2X the scan time.
- Up-counters counts from zero up to the preset value. These are called CTU, CNT, C, or CTR.
- Down-counters count down from the preset value to zero. These are calllled CTD.
- Up-down counters count up and/or down. These are called CTUD.
- For CTU or CTD counter we need 2 inputs, but in CTUD we need 3 (up, down and preset).
To use counters we must know 3 things:
- Where the pulses that we want to count are coming from. Typically this is from one of the inputs.
- How many pulses we want to count before we react.
- When/how we will reset the counter so it can count again.
Some manufacturers consider the counter as a relay and consist of two basic elements:
One relay coil to count input pulses and one to reset the counter, and the associated contacts of the counter being used in other rungs.
Others (Siemens for example) treat the counter as an intermediate block in a rung from which signals emanate when the count is attained.
High Speed Counter
Most manufacturers also include a limited number of high-speed counters (HSC). Typically a high-speed counter is a “hardware” device. Hardware counters are not dependent on scan time.
The sequencer is a form of counter that is used for sequential control. It replaces the mechanical drum sequencer that was used to control machines that have a stepped sequence of repeatable operations.
The PLC sequencer consists of a master counter that has a range of presets counts corresponding to the different steps and so, as it progresses through the count, when each preset count is reached can be used to control outputs.
Data Handling Instructions
Timers, counters and individual relays are all concerned with the handling of individual bits, i.e. single on-off signal. PLC operations involve blocks of data representing a value, such blocks being termed words.
Data handling consists of operations involving moving or transferring numeric information stored in one memory word location to another word in a different location, comparing data values and carrying out simple arithmetic operations.
- A register is where data can be stored.
- Each data register can store a binary word of usually 8 or 16 bits.
- The number of bits determines the size of the number that can be stored (2n – 1).
- 4-bit register can store a positive number between 0 and +15.
- 8-bit: 0 and +255.
- 16-bit: 0 and +65535.
Data movement instructions
There are typically 2 common instruction “sets“:
The single instruction is commonly called MOV (move) copies a value from one address to another.
The MOV instruction needs to know 2 things:
- Source – where the data we want to move is located.
- Destination – the location where the data will be moved to.
We write an address here. Allso, the data can be moved to the physical outputs.
The data comparison instruction gets the PLC to compare two data values.
Thus it might be to compare a digital value read from some input device with a second value contained in a register.
PLCs generally can make comparisons for:
- less than (< or LESS),
- equal to (= or EQU),
- less than or equal to (<= or LEQ),
- greater than (> or GRT),
- greater than or equal to (>= or GEQ), and
- not equal to ( NEQ).
Arithmetic (mathematical) Instructions
PLCs almost always include math functions to carry out some arithmetic operations:
- Addition (ADD) – The capability to add one piece of data to another.
- Subtraction (SUB) – The capability to subtract one piece of data from another.
- Multiplication (MUL) – The capability to multiply one piece of data by another.
- Division (DIV) – The capability to divide one piece of data from another.
Typically the memory locations are 16-bit locations. If a result is greater than the value that could be stored in a memory location then we get an overflow. The plc turns on an internal relay that tells us an overflow has happened. We get an overflow if the number is greater than 65535
Depending on the plc, we would have different data in the destination location. Some use 32-bit math which solves the problem. If we’re doing division, and we divide by zero the overflow bit turns on.
Continuous control (PID Instruction)
Continuous control of some variable can be achieved by comparing the actual value of the variable with the desired set value and then giving an output depending on the control law required.
Many PLCs provide the PID calculation to determine the controller output as a standard routine. All that is then necessary is to pass the desired parameters, i.e. the values of Kp, Ki, and KD, and input/output locations to the routine via the PLC program.
Control instructions are used to enable or disable a block of logic program or to move execution of a program from one place to another place.
The control instructions include:
- Master Control instruction (MC/MCR)
- Jump to label instruction (JMP)
- Label instruction (LBL)
- Jump to Subroutine instruction (JSR)
- Subroutine instruction (SBR)
- Return from Subroutine instruction (RET)
- Shift Registers
Master Control/ Master Control Reset (MC/MCR)
When large numbers of outputs have to be controlled, it is sometimes necessary for whole sections of program to be turned on or off when certain criteria are realized. This could be achieved by including a MCR instruction. A MCR instruction is an output instruction.
The master control instruction typically is used in pairs with a master control reset. Different formats are used by different manufacturers:
- MC/MCR (master control/master control reset),
- MCS/MCR (master control set/master control reset) or
- MCR (master control reset).
The zone being controlled begins with a rung that has the first MC instruction, which status depends on its rung condition. This zone ends with a rung that has the second MCR instruction only.
When the rung with the first MCR instruction is true, the first MCR instruction is high and the outputs of the rung in the controlled zone can be energized or denergized acording to their rung conditions. When the this rung is false, all the outputs in the zone are denrgized, regardless their rung conditions.
Timers should not be used inside the MC/MCR block because some manufacturers will reset them to zero when the block is false whereas other manufacturers will have them retain the current time state. Counters typically retain their current counted value.
The JUMP instructions allow to break the rung sequence and move tthe program execution from one
rung to another or to a subroutine. The Jump is a controlled output instruction.
You can jump forward or backward.
You can use multiple jump to the same label.
Jumps within jumps are possible
- Jump to Label. 2.Jump to subroutine
RETURN / END
A Return from Subroutine instruction marks the end of Subroutine instruction. When the rung condition of this instruction is true, it causes the PLC to resume execution in the calling program file at the rung following the Jump to Subroutine instruction in the calling program.
When a Return from Subroutine instruction is not programmed in a subroutine file, the END instruction automatically causes the PLC to move execution back to the rung following the Jump to Subroutine instruction.
A Jump to Subroutine instruction can be used either in a main application program or a subroutine program to call another subroutine program.
The shift register is a number of internal relays grouped together (normally 8, 16, or 32) which allow stored bits to be shifted from one relay to another.
The grouping together of internal relays to form a shift register is done automatically by a PLC when the shift register function is selected. This is done by using the programming code against the internal relay number that is to be the first in the register array.
Shift registers can be used where a sequence of operations is required or to keep track of particular items in a production system. The shift register is most commonly used in conveyor systems, labeling or bottling applications, etc…