PLC 5 Chapter Notes
PLC 5 Chapter Notes
Advanced Instructions
Program Control Instructions:
Program control refers to special instructions or features in a PLC that allow you to control
the flow or sequence of the program. Instead of simply running the instructions from top to
bottom, these instructions give the PLC the flexibility to:
These features allow the PLC to handle complex tasks and decision-making processes more
efficiently.
Imagine a factory automation system where a PLC controls a conveyor belt, and you want the
belt to stop if a sensor detects an obstacle. You could use program control instructions like
this:
• JMP: If the sensor detects no obstacle, the program jumps over the part of the code
that stops the belt.
• CALL: If an obstacle is detected, the program calls a subroutine to stop the belt and
send an alert.
• RET: Once the obstacle is cleared, the PLC returns to the main program and restarts
the belt.
Without program control, a PLC would just execute instructions in order, from start to finish,
with no flexibility. Program control gives it intelligence, making it possible to react to
changing conditions, skip unnecessary tasks, and handle more complex processes.
In summary, program control in a PLC allows you to manage the flow of your control
program, making it more efficient and responsive. It ensures that the PLC executes the right
instructions at the right time based on the current conditions of the system.
1. MCR Zones:
o The MCR instruction defines the beginning and the end of a control zone in
the ladder logic program. This zone is the section of the program that can be
enabled or disabled.
o The MCR zone begins with the MCR Start Instruction and ends with an
MCR End Instruction. Everything between these two instructions can be
conditionally controlled.
2. How MCR Works:
o When the MCR instruction is enabled, all the logic between the MCR start
and end operates normally, just like any other part of the PLC program.
o When the MCR instruction is disabled, the outputs within the MCR zone are
either de-energized (turned off) or remain in a previous state, depending on the
PLC's specific implementation and programming.
Think of MCR like a master switch that can cut off or allow power to a group of
circuits. If the MCR is turned on, those circuits (program rungs) function normally. If
the MCR is turned off, the circuits are disabled, and the outputs in that section will be
turned off or left in a safe state.
• MCR Start (Enable): When the conditions of the MCR start rung are met (true), the
PLC executes the logic within the MCR zone.
• MCR End (Disable): The MCR zone ends when the MCR End instruction is reached.
Any outputs in the zone will behave according to the current MCR status.
• Outputs in MCR Zone: When the MCR is disabled, most PLCs de-energize (turn
off) any outputs that are controlled by rungs within the MCR zone.
• Multiple MCR Zones: You can have multiple MCR zones within the same program.
Each one operates independently based on its own control logic.
1. Safety Control:
o One of the most common uses of MCR is for safety purposes. In many
applications, you may need to quickly disable an entire section of your control
logic if an emergency stop or fault condition is triggered.
o Example: If an emergency stop button is pressed, the MCR instruction can
disable all non-essential parts of the process, stopping the machinery and
placing it in a safe state.
2. Energy Conservation:
o In industrial applications, certain equipment may not need to run continuously.
An MCR can be used to disable entire sections of the program when they are
not needed to conserve energy.
o Example: In a factory with multiple production lines, an MCR zone might be
used to disable the logic controlling a conveyor belt when no products are on
the line.
3. Sequential Operations:
o MCR zones can be used to enable and disable different sections of the
program as needed in sequential operations. This ensures that only one part of
the system runs at a time, reducing the risk of interference between processes.
o Example: In a manufacturing process, an MCR could be used to run one phase
of production (like filling a container), and once it’s complete, the MCR
enables the next phase (like sealing the container).
4. Conditional Control:
o MCR can be used for conditional control of parts of the program, allowing
certain sections to execute only when specific conditions are met.
o Example: In a cooling system, an MCR could enable a section of the program
that controls additional fans only when the temperature exceeds a certain limit.
Special Considerations
• Outputs Handling: It’s important to understand how your particular PLC handles the
outputs in the MCR zone. In some PLCs, outputs will automatically turn off when the
MCR is disabled. In others, the outputs may retain their previous state (either on or
off) until the logic explicitly changes them.
• Fault Detection: MCR can also be useful in fault detection or error handling. If a
fault condition is detected, the MCR can shut down parts of the process safely.
• Scan Time: Using MCR zones can slightly increase the scan time of the PLC because
the processor has to evaluate whether the MCR zone should be enabled or disabled.
Example:
• Figure 9-3 shows the MCR (Master Control Relay) programmed to control an entire circuit.
• The MCR-controlled zone begins with the first MCR instruction and ends with the second
MCR.
• When the first MCR is false (disabled), all nonretentive rungs within the zone, such as
outputs M and PL1, will be de-energized even if their logic is true.
• Retentive rungs, such as SOL, remain in their last state even if the MCR is disabled.
• If motor M is running and the MCR becomes disabled, the motor will immediately stop,
and when the MCR is enabled again, the motor will not restart automatically. It must be
restarted via the start pushbutton.
• If the level switch is closed and the MCR becomes disabled, pilot light PL1 will be de-
energized, despite the level switch remaining true. When the MCR is re-enabled, PL1 will
energize automatically if the level switch is still closed.
• If solenoid SOL is latched energized and both limit switches LS1 and LS2 are open,
disabling the MCR will not affect SOL, which will stay energized. When the MCR is enabled
again, SOL will stay energized, provided LS1 and LS2 remain open.
• If solenoid SOL is latched de-energized and both limit switches LS1 and LS2 are open,
disabling the MCR will not affect SOL, which will stay de-energized. When the MCR is
enabled again, SOL will remain de-energized, provided LS1 and LS2 stay open.
• Retentive instructions should generally not be placed within an MCR zone, as the MCR
zone maintains the state of retentive instructions from when the MCR was last disabled.
When used, the PLC will bypass the instructions between the jump point and a designated
label, allowing it to jump directly to another part of the program.
• The JMP instruction specifies the label (LBL) it will jump to.
• The program will skip all the rungs and instructions between the JMP and LBL.
• The program execution will continue from the LBL point once the jump occurs.
1. Careful Labeling: Ensure that your labels are correctly placed and that the JMP and
LBL instructions are properly paired. Misplaced labels or jumps to non-existent labels
can cause the program to behave unexpectedly.
2. Program Flow: Overuse of jump instructions can make the program harder to follow
and debug. Try to use jumps sparingly and only when necessary.
3. No Condition: If you use an unconditional JMP instruction (without any condition),
the PLC will always jump, which can cause certain parts of the program to never
execute. Make sure conditions are clearly defined.
Example:
• Figure 9-7 shows the effect on input and output instructions of jumped rungs in a program.
• The label instruction (LBL) identifies the target rung but does not affect logic continuity; it
is always considered logically true.
• Rungs 1, 2, 3, 8, 9, and 10 are outside the jumped section and always executed as normal.
• If rung 4, which contains the JMP instruction, is false, the jump is not executed, and rungs
5, 6, and 7 are executed normally.
• When rung 4 is true, the processor jumps to the LBL target in rung 8, skipping rungs 5, 6,
and 7.
• Rungs 5, 6, and 7 are not scanned by the processor, and their input conditions are not
examined; outputs controlled by these rungs remain in their last state.
• Timers or counters in the jumped rungs stop functioning and do not update during the jump;
they should be placed outside the jump zone in the main program.
• The jump is a forward jump, continuing the program from rung 8 onwards.
• Instructions to the right of the LBL (e.g., rung 8) are outside the jump zone and are
executed normally.
In PLCs, subroutines are commonly used to handle recurring tasks, such as controlling a
motor or reading sensor data, without duplicating the same code in multiple places. Once
written, a subroutine can be called (or invoked) as many times as necessary from the main
program.
1. Definition:
o A subroutine is defined as a separate part of the PLC program. The code inside
the subroutine performs a task that can be reused at different points in the
main program.
o Subroutines are typically written as separate program blocks or functions in
the PLC software, such as Ladder Logic (LAD), Function Block Diagram
(FBD), or Structured Text (ST).
2. Calling a Subroutine:
o The main program or other subroutines can call (invoke) a subroutine when
needed using a Call (CALL) or Jump to Sub Routine (JSR) instruction.
o When a subroutine is called, the PLC temporarily suspends the main program
and executes the subroutine. After completing the subroutine, the program
returns to the point where the subroutine was called and continues executing
the remaining logic.
3. Return to Main Program:
o After the subroutine finishes its task, it uses a Return (RET) instruction to
return control to the main program at the point immediately after the CALL
instruction.
Defining Subroutines
A subroutine is defined by writing a block of code (often called a function or routine) that
performs a task. The definition usually includes the following elements:
1. Subroutine Name: Different PLC have different options some uses unique name
other uses unique file number from 3 to 255 with first rung having written SBR.
2. Input Parameters (Optional): Some subroutines accept input data to work with.
These are defined as part of the subroutine's declaration.
3. Output Parameters (Optional): Subroutines can return values or data to the calling
program, defined as output parameters.
4. Body: The body contains the actual logic that performs the subroutine’s task.
• Subroutine (SBR):
• This instruction is the first input on the first rung of a subroutine file.
• Identifies the program file as a subroutine, although its use is optional, it is
recommended.
• Always true, and the file number used here corresponds to the JSR instruction's target.
• Return (RET):
• Marks the end of the subroutine file and returns the scan to the main program at the
point following the JSR instruction.
• If no RET instruction is present, the scan returns at the end of the file.
• The RET instruction can be conditional, allowing the processor to skip the remaining
part of the subroutine only if the rung condition is true.
• Figure 9-11 illustrates a materials conveyor system with a flashing pilot light controlled by
a subroutine.
• If the weight on the conveyor exceeds a preset value, the solenoid is de-energized and pilot
light PL1 starts flashing.
• When the weight sensor switch closes, the JSR instruction is activated, directing the
processor to jump to the subroutine U:3.
• The subroutine is then scanned, causing pilot light PL1 to flash.
• When the weight sensor switch opens, the processor stops scanning the subroutine, and
pilot light PL1 returns to its normal "on" state.
1. Modularity:
o Subroutines break down large programs into smaller, modular sections. This
structure improves readability and simplifies the programming process,
making the program easier to follow and maintain.
2. Reusability:
o Once a subroutine is created, it can be called multiple times in the program
without rewriting the same code. This helps reduce code duplication and
ensures consistency, as the logic within the subroutine is centralized.
3. Parameter Passing:
o In some PLCs, subroutines can accept input parameters (data passed to the
subroutine) and produce output parameters (data returned from the
subroutine). This makes subroutines flexible, allowing them to work with
different data depending on the situation.
4. Separation of Concerns:
o Subroutines isolate specific functionality from the main program. This
approach helps in separating tasks or actions, reducing complexity in the
overall program.
5. Error Handling:
o Subroutines allow for better error handling, as errors can be contained and
addressed within a specific subroutine rather than affecting the entire program.
Types of Subroutines
1. Local Subroutines:
o These subroutines are only accessible within the program or module where
they are defined. They are not available to other parts of the program or other
programs in the PLC.
2. Global Subroutines:
o These subroutines can be called from any program or module within the PLC.
Global subroutines are useful for tasks that need to be performed across
different parts of the system.
Whether a subroutine is local or global depends on how and where the subroutine is declared
within the PLC programming environment. Different PLC platforms and programming
languages may have their own terminology, but the principles are generally similar.
1. Local Subroutines
• Definition: A local subroutine can only be accessed or called within the specific
program, function, or module where it is defined.
• Scope: The subroutine is private to the program it is declared in. This helps isolate
functionality and prevents unintended use of the subroutine from other parts of the
system.
2. Global Subroutines
• Definition: A global subroutine can be accessed or called from any part of the overall
PLC system, including other programs, tasks, or modules.
• Scope: The subroutine is public and can be invoked from different parts of the PLC
program or even from other programs running on the same PLC.
Global subroutines are useful when you need to reuse functionality across different programs
or parts of the system.
Math Instructions
Math instructions in PLCs enhance their functionality by enabling arithmetic operations on
values stored in memory or registers. This capability allows the PLC to perform tasks similar
to a conventional computer. For instance, a counter tracking manufactured parts can be used
to calculate how many more parts need to be produced to reach a specific quota.
Instruction Overview
Math instructions use two registers or memory locations to perform the desired function. The
key math instructions for PLCs include:
Instruction Parameters
• Source A: Can be an input location, file address, instruction field, or a fixed value.
Examples:
Input Location:
o This represents a physical input on the PLC, such as a sensor or switch.
o Example: I:1 refers to the input at slot 1 of the input module. If a sensor
connected to input 1 detects a value, that value can be used as Source A.
File Address:
o A file address is a memory location within the PLC where data is stored, such
as counters, timers, or numeric data.
o Example: N7:5 refers to the 5th element in the N7 data file, which stores
integer values. The value stored in N7:5 is used as Source A.
Instruction Field:
o This refers to data generated by other instructions or operations in the PLC
program, such as accumulated values from counters or timers.
o Example: C5:2.ACC refers to the accumulated value (ACC) of Counter 5,
instance 2. This value is dynamically changing as the counter operates and can
be used as Source A.
Fixed Value:
o A fixed value is a constant number that doesn’t change during program
execution.
o Example: 30 would be a constant value used as Source A in a calculation,
meaning it will always provide the number 30 for the operation.
• Source B: Similar to Source A and can also include the same types of inputs.
• Destination: Where the result is stored; can be an output location, file address, or
instruction field.
Examples:
o Output Location: O:2
o File Address: N7:8
o Instruction Field: T4:1.PRE
The Compute (CPT) instruction is a powerful math instruction in PLC programming that
allows you to perform complex mathematical operations using a single command. Unlike
basic arithmetic instructions (like ADD, SUB, etc.), which only perform one operation at a
time, the CPT instruction can combine multiple operations into a single expression.
Purpose
The CPT instruction evaluates a mathematical or logical expression and stores the result in a
specified destination. It can handle operations like addition, subtraction, multiplication,
division, and more complex calculations such as exponents, square roots, and parentheses-
based expressions.
Structure
1. Expression: This is the formula or calculation you want the PLC to perform.
2. Destination: This is where the result of the expression will be stored.
• Multiple Operations: You can include multiple operations (e.g., adding, multiplying,
subtracting) in a single expression, making it more efficient than using multiple
individual instructions.
• Use of Parentheses: You can group parts of the expression using parentheses to
ensure certain operations are carried out first (just like in normal math).
• Logical Operations: You can also include logical operators, like AND, OR, and
comparisons (e.g., greater than, less than) in the expression.
Example:
Let’s say you want to convert a Fahrenheit temperature to Celsius using the following
formula:
5
°𝐶 = (°𝐹 − 32) ×
9
Here’s how the CPT instruction would work:
1. Expression: You’ll write the formula in the CPT instruction, like this:
5
(𝑆𝑜𝑢𝑟𝑐𝑒 − 32) ×
9
In this case, the Source is the Fahrenheit temperature stored in a memory location
(e.g., N7:5).
2. Destination: You’ll specify where to store the result of the calculation, such as in a
destination file (e.g., N7:6).
Operation Breakdown:
• When the rung that contains the CPT instruction is true, the PLC will:
o Retrieve the value stored in Source (e.g., N7:5 for Fahrenheit).
o Perform the subtraction: °F−32°F.
o Multiply the result by 5/9.
o Store the final Celsius result in the Destination (e.g., N7:6).
For example, if N7:5 holds the value 140 (°F), the calculation would be:
5
°𝐶 = (140 − 32) × = 60
9
• Efficiency: You can combine multiple mathematical steps into a single instruction
instead of using separate ADD, SUB, MUL, or DIV instructions.
• Complex Calculations: The CPT instruction allows for more advanced operations,
like exponents or nested calculations, which cannot be easily performed using basic
math instructions.
• Flexible Expressions: You can adjust the expression to include many different types
of math functions, logical conditions, or even conversions.
Considerations:
• Execution Time: Since the CPT instruction can involve multiple operations, it takes
longer to execute than basic math instructions (like ADD or SUB).
• Order of Operations: Just like in normal math, the CPT instruction follows the order
of operations (parentheses first, then multiplication/division, then
addition/subtraction). Parentheses can be used to control the order of execution.
ADD Instructions:
Key Features:
• Functionality: The ADD instruction adds two values from referenced memory
locations (source A and source B) and stores the result in a designated destination.
• Memory Locations: The values involved can be constants or addresses that hold
values, but both inputs (A and B) cannot be constants simultaneously.
• Operation of the Logic Rung:
o The rung becomes true when the input condition (e.g., input switch SW) is
satisfied.
o Source A and Source B values are retrieved from specific memory addresses.
o The result of the addition is stored at a destination memory address.
In an application where a pilot light must turn on when the sum of the accumulated counts of
two up-counters reaches 350:
After a math instruction is executed, the arithmetic status bits in the processor status file
(S2) are updated to indicate the result's condition:
• Carry Bit (C) (S2:0/0): Set to 1 when there is a carry in an ADD instruction or a
borrow in a SUB instruction.
• Overflow Bit (O) (S2:0/1): Set to 1 if the result is too large to fit in the destination
register.
• Zero Bit (Z) (S2:0/2): Set to 1 when the result of a subtraction is zero.
• Sign Bit (S) (S2:0/3): Set to 1 when the result is negative.
Subtraction Instruction
The SUB (Subtract) instruction in PLC programming is used to subtract one value from
another and store the result in a specified destination address. This instruction is executed
when the rung conditions are true.
• Functionality: It subtracts the value of Source B from Source A and stores the result
at the destination address.
• Memory Locations: Similar to the ADD instruction, Source A and Source B can be
addresses containing values or constants, but both inputs cannot be constants
simultaneously.
Example of SUB Instruction (SLC 500 Controller):
A subtraction instruction can be used to indicate a vessel overfill condition. In this scenario,
an alarm sounds if the vessel overfills by 5 lb or more after reaching a preset weight of 500
lb. Here's how the logic works:
• Start Button Pressed: Activates the fill solenoid, allowing raw material to flow into
the vessel.
• Weight Monitoring: The vessel’s weight is continuously monitored by the PLC
program.
• Fill Cut-Off: Once the vessel reaches a weight of 500 lb, the PLC:
o De-energizes the fill solenoid, cutting off the flow of material.
o Turns off the "filling" pilot light.
o Turns on the "full" pilot light.
• Overfill Alarm: If the fill solenoid leaks and 5 lb or more of raw material enters the
vessel, the alarm is triggered. The alarm stays on until the vessel's weight drops below
the 5-lb overflow limit.
Multiplication Instruction
The MUL (Multiply) instruction in PLC programming is used to multiply two values and
store the result in a designated destination memory address. This instruction is executed when
the rung conditions are true.
In the program shown in Figure 11-10, the MUL instruction calculates the product of two
source values:
• Source A: Address N7:1, containing the value 123.
• Source B: Address N7:2, containing the value 61.
• Destination: The product of the multiplication (123 * 61 = 7503) is stored in memory
location N7:3.
• Equal Instruction: After the MUL instruction executes, the EQU (Equal) instruction
checks if the product matches a specific value. When true, output PL1 is turned on.
The MUL instruction is also useful for temperature control in an oven system, as shown in
the program of Figure 11-11. The program calculates the deadband around a set-point
temperature, which defines the range where the heaters should be turned on or off.
Operation Summary:
Important Considerations:
• Similar to other math instructions, care must be taken to ensure the result fits within
the valid range of the destination register.
• Monitor the arithmetic status bits for errors like overflow when working with large
numbers or high precision values.
Division Instruction
The DIV (Division) instruction in PLC programming is used to divide the value in Source
A by the value in Source B and store the result in a specified destination address. It also
updates the math register with the quotient and the remainder. This instruction is executed
when the rung conditions are true.
• Functionality: The value of Source A is divided by Source B, and the result is stored
in the destination address. The result consists of both the integer quotient and the
remainder.
• Rounding: If the remainder is 0.5 or greater, the result is rounded up in the
destination when dealing with integer values.
• Math Register: The unrounded quotient is placed in the most significant word, and
the remainder is placed in the least significant word of the math register.
• Division by Zero: A minor fault bit is set if a division by zero is attempted.
If the remainder is 0.5 or greater, the value in N7:3 will be rounded up.
Example Application 1: Basic Division
The program in Figure 11-13 calculates the quotient of dividing two source values:
9
𝐹 = ( × 𝐶) + 32
5
• Set-Point Temperature: A thumbwheel switch provides the Celsius temperature
input, and the PLC converts it to Fahrenheit using this formula.
• Program Operation:
1. The MUL (Multiply) instruction multiplies the Celsius temperature (e.g.,
60°C) by 9.
2. The DIV instruction divides the result by 5.
3. The ADD instruction adds 32 to the result.
o For example, if the Celsius temperature is 60°C:
▪ The product of 60 × 9 = 540 is calculated.
▪ 540 ÷ 5 = 108 is computed by the DIV instruction.
▪ Finally, 108 + 32 = 140°F is the Fahrenheit temperature.
• Result Storage: The Fahrenheit temperature is displayed, and the final result is stored
in memory locations such as N7:0 and N7:3.
Sequencer:
A sequencer in a Programmable Logic Controller (PLC) is a control tool used to manage
a series of operations or events that need to occur in a specific order, one after the other. It
allows a system to move through predefined steps or actions based on certain conditions. In
essence, it helps automate processes that have a defined sequence of tasks.
Key Concept:
Imagine a process where different tasks need to happen in a specific order (like in a
production line or a packaging machine). The sequencer will make sure that one task happens
only after the previous one is finished, ensuring the correct flow of operations.
• Sequence Steps: The process is divided into steps. Each step represents a specific
task or set of tasks.
• Triggers: The sequencer moves from one step to the next based on certain triggers,
like input signals from sensors, timers, or external commands.
• Control of Outputs: Each step can control multiple outputs, like turning on or off
motors, conveyors, valves, etc.
Example Application:
Consider a bottling plant, where bottles are filled, capped, and labeled in a specific order. A
sequencer would control this process as follows:
The sequencer ensures that each step happens in the right order and only when certain
conditions (like bottle in place, cap is on) are met. This prevents errors and makes the process
more efficient.
1. File:
o The starting address for the sequencer file, denoted with an indexed file
indicator (#). Each word in the file corresponds to a step, starting from
position 0.
2. Mask:
o A bit pattern that filters data. A bit set to 1 allows data to pass; a bit set to 0
blocks data flow but keeps the existing value. The mask can be a hexadecimal
(indicated by 'h') or binary number (indicated by 'B').
3. Source:
o The input address from which data is compared or loaded into the sequencer
file (for SQC and SQL instructions).
4. Destination:
o The address where data from the sequencer file is transferred to, controlled by
the SQO instruction.
5. Control:
o A control register that stores parameters, like:
▪ Enable bit (EN): Set when the rung transitions from false to true.
▪ Done bit (DN): Set when the last word is transferred; resets on the
next false-to-true transition.
▪ Error bit (ER): Set if a negative position or length is detected.
6. Length:
o The number of steps in the sequencer file. The actual length is 1 plus the value
entered.
7. Position:
o The step the sequencer instruction is currently at. After completing the
sequence, the instruction resets to step 1 on the next cycle.
1. Output Control:
o Six outputs (traffic lights) are controlled by one 16-point output module. Each
light is represented by one bit of output word O:2.
2. Step Sequence:
o Step 1: Red light (O:2/0) and green light (O:2/5) on.
o Step 2: Red light (O:2/0) and yellow light (O:2/4) on.
o Step 3: Green light (O:2/2) and red light (O:2/3) on.
o Step 4: Yellow light (O:2/1) and red light (O:2/3) on.
3. Sequencer File:
o Words B3:0 to B3:4 store the desired binary data for each step.
4. Neutral Starting Point:
o Position 0 is used as a neutral start point, with all outputs turned off.
Key Points:
• Retentive Function:
o Sequencer instructions typically remember the current position even after a
power cycle or stop/start.
• Output Limits:
o Sequencer instructions can operate a limited number of outputs and steps.
• Automatic Reset:
o After the last sequence step is completed, the sequencer usually resets to step 1
automatically.
o Some sequencers may have a manual reset option in addition to the automatic
reset.
An example of a time-driven sequencer with variable timed steps is shown in Figure 12-14,
used for automatic traffic light control at a four-way intersection.
• The system requires two SQO instructions: one for the light outputs and the other for the
timed steps.
• The timing steps have variable durations: the first step lasts 25 seconds, the second for 5
seconds, the third for 25 seconds, and the fourth for 5 seconds.
• The bits controlling the traffic light outputs are stored in integer file #N7:0 of the first SQO
instruction, as shown in Figure 12-15.
• The settings for the output bits for each position are entered and stored in binary format in
the #N7:0 file.
• Each word of the #N7:0 file is moved by the program to the destination output word O:2,
controlling the traffic lights sequentially.
• The second SQO instruction contains the preset timer values in #N7:10, which stores the
times (25, 5, 25, 5 seconds) for each step.
• These values are stored in words N7:11, N7:12, N7:13, and N7:15, as illustrated in Figure
12-16.
• Each word of the #N7:10 file is moved by the program to the timer's preset value address
T4:1.PRE.
• The mask ensures that only the necessary data passes through to the timer's preset value.
• The timer cycles both SQO instructions through their four steps.
• Since both SQO instructions use R6:0 for control and have the same length, they are
stepped in unison to provide a sequentially timed output for the traffic light system.
Bit Shift Registers
What is a Bit Shift Register?
• A Bit Shift Register is a special type of register in a PLC that allows you to move
bits (0s and 1s) through a series of positions in an orderly fashion.
• It can shift bits either to the left or to the right, enabling the PLC to track the flow of
information or parts in a system.
• When a shift pulse (like a clock signal) is activated, the bits in the register move one
position in the specified direction:
o Bit Shift Left (BSL): Moves bits from lower-numbered positions to higher-
numbered positions.
o Bit Shift Right (BSR): Moves bits from higher-numbered positions to lower-
numbered positions.
• As bits are shifted, the first bits that enter the register can be lost if the register is full.
Applications of Bit Shift Registers
The data stored in a shift register can represent various information, such as:
• Each bit in the shift register is identified by its position. This means you don’t need to
worry about traditional word and bit addressing; instead, you can focus on the
position of each bit.
• Shift registers often use binary format, making it easier to interpret the data.
• Function: Loads a bit into a register and shifts all bits in the register to the left.
• Behavior: The leftmost bit is discarded, and a new bit enters from the right.
• Function: Loads a bit into a register and shifts all bits in the register to the right.
• Behavior: The rightmost bit is discarded, and a new bit enters from the left.
When programming shift registers, you need to understand the following bits:
• Enable Bit (EN): Indicates when the shift instruction is active (set to 1 when true).
• Done Bit (DN): Signals that the shift operation has completed (set to 1 when done).
• Error Bit (ER): Indicates an error, such as when a negative length is specified for the
shift operation.
• Unload Bit (UL): Contains the last bit shifted out of the register. This bit will be lost
unless you take additional steps to retain it.
To program a bit shift instruction, you need to provide the following information:
• File: The address of the bit array you want to manipulate. It must start with the # sign.
• Control: This includes a status word, length, and position for tracking.
• Bit Address: The address of the source bit being loaded into the register.
• Length: Indicates how many bits to shift.
Example: Bit Shift Left (BSL) Operation
1. When the limit switch (LS) is activated, the BSR instruction executes.
2. The source bit (e.g., I:3/5) is inserted into the last position of the register.
3. All bits in the register shift one position to the right.
4. The rightmost bit is sent to the unload bit (R6:1/UL), and that status is lost.
Components Used
Initial Setup
Program Steps
1. PLC Run Mode: When the PLC is placed in run mode, the bit B3:0/0 is set to Logic
1, turning PL1 on.
2. Input Switch Activation: When the input switch SW is closed, it starts the timer
T4:0. The timer is set to 3 seconds.
3. Timer Completion:
o After 3 seconds, the timer's done bit (T4:0/DN) is set.
o This causes the accumulated time of the timer to reset to zero.
o The BSL instruction shifts the logic bit 1 to the left:
▪ B3:0/0 (PL1) turns off.
▪ B3:0/1 (PL2) turns on.
4. Repeat Process:
o After another 3 seconds, the timer done bit is set again.
o The BSL instruction shifts the bits once more:
▪ B3:0/1 (PL2) turns off.
▪ B3:0/2 (PL3) turns on.
5. Wraparound Behavior:
o If the timer continues to cycle, the BSL will shift the logic bit back to B3:0/0
after the logic bit has shifted through B3:0/2, causing the sequence to repeat:
▪ PL3 turns off.
▪ PL1 turns on again.
Word Shift Registers
What are Word Shift Registers?
• Word Shift Registers are operations that facilitate loading and unloading data into a
file (often referred to as a stack) within a PLC.
• Unlike bit shift registers, which manipulate bits, word shift registers operate on entire
words (groups of bits).
• Commonly used for tracking parts through an assembly line, where parts are
represented by unique identifiers such as part numbers or assembly codes.
Overview
• FIFO is a method of data handling where the first piece of data entered is the first to
be retrieved. This is akin to a queue in real life (e.g., people lining up at a ticket
counter).
• FIFO operations use two separate shift pulses:
o Load Pulse: To load data into the stack.
o Unload Pulse: To retrieve data from the stack.
• The two operations are asynchronous, meaning they operate independently of one
another.
• Purpose: Loads logic words into a user-created file known as a FIFO stack.
• Parameters:
o Source: The word address from which data is loaded.
o FIFO: The address of the FIFO file, starting with a # sign.
o Control: R data-table type containing the status, stack length, and position.
o Length: Specifies the maximum number of words in the stack.
o Position: Indicates where the next word will be loaded (starting at position 0).
• Purpose: Unloads logic words from the FIFO stack in the same order they were
entered.
• Parameters:
o FIFO: The address of the FIFO file, same as for the FFL instruction.
o Destination: The address to which the FFU unloads the data.
o Control: Similar to the FFL, it contains status information.
o Length: Specifies the maximum number of words in the stack.
o Position: Indicates where the next word will be unloaded.
1. Setup:
o The FFL and FFU instructions share the same control element, such as R6:0.
o For example, the FIFO stack may be defined at #N7:12.
2. Data Loading:
o Data enters the FIFO file from a source address (e.g., N7:10) on a false-to-true
transition of input A.
o The data is placed in the FIFO at the specified position upon activation of the
FFL instruction.
3. Data Unloading:
o A false-to-true transition of input B causes data in the FIFO to shift towards
the starting address, with the first word being transferred to the destination
address (e.g., N7:11).
Overview
• LIFO operates in the opposite manner to FIFO; the last piece of data entered is the
first to be retrieved. This can be likened to a stack of plates where you remove the top
plate first.
Data manipulation instructions are critical in programmable logic controllers (PLCs) as they
enable numerical data stored in memory to be processed within control programs. This
capability extends the functionality of a PLC beyond simple on/off control to more complex
operations involving:
• Data comparisons
• Arithmetic calculations
• Data format conversions
Terminology
Data transfer instructions facilitate the movement of data from one memory location to
another. This is essential for modifying and storing operational values within the control
program.
Key Instructions
1. MOV (Move):
o Moves the value from a source address to a destination address.
o Operation Example:
▪ If N7:30 contains the value 50, and the MOV instruction is executed to
move this value to N7:20, after execution, N7:20 will also contain 50.
▪ The original value at N7:30 remains unchanged.
2. MVM (Masked Move):
o Similar to the MOV instruction but allows filtering of data through a mask.
o Operation Summary:
▪ The mask determines which bits of the source data are transferred to
the destination.
▪ Bits in the mask that are 0 do not pass data, while those that are 1 do.
Data comparison instructions assess and compare numerical values stored in registers. These
comparisons inform decision-making processes within the control logic.
Key Instructions