0% found this document useful (0 votes)
38 views43 pages

PLC 5 Chapter Notes

Uploaded by

Pranil Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views43 pages

PLC 5 Chapter Notes

Uploaded by

Pranil Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Unit V

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:

1. Jump to another part of the program and continue from there.


2. Skip certain instructions based on specific conditions.
3. Repeat certain instructions (loops).
4. Pause or stop the program when needed.

These features allow the PLC to handle complex tasks and decision-making processes more
efficiently.

Common Program Control Instructions in PLCs

1. Jump Instruction (JMP):


o This instruction allows the PLC to "jump" over certain parts of the program.
o Example: If a sensor detects a specific condition, the program might jump
over certain steps to save time and resources.
2. Label Instruction (LBL):
o Used in combination with the Jump instruction. It marks the point in the
program to which the PLC should jump.
o Example: The PLC jumps to a specific label, skipping irrelevant instructions.
3. Subroutines (CALL):
o Subroutines are separate blocks of code that perform a specific task. The PLC
can "call" or execute these subroutines as needed.
o Example: Instead of writing the same set of instructions multiple times, you
put them in a subroutine and call it when needed.
4. Return Instruction (RET):
o This is used to return the PLC to the main program after it has completed a
subroutine.
5. Conditional Instructions:
o These instructions only execute a certain part of the program if a specific
condition is true.
o Example: IF a sensor detects high temperature, THEN start the cooling
system.
6. Looping (FOR, WHILE):
o Looping instructions allow the PLC to repeat a set of instructions multiple
times.
o Example: A loop could be used to repeatedly check a sensor's status every
second.
7. Master Control Reset (MCR):
o This instruction allows you to enable or disable certain sections of the
program, controlling whether those sections run or not.
Example Scenario

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.

Why Is Program Control Important?

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.

Master Control Reset (MCR):

The Master Control Reset (MCR) is an important program control instruction in


Programmable Logic Controllers (PLCs). It is used to enable or disable a section of the
program, controlling which parts of the logic are active or inactive during the PLC's
operation. The MCR essentially acts as a "master switch" for specific rungs in a PLC
program, allowing sections of the program to be turned on or off based on certain conditions.

Detailed Explanation of MCR

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.

Key Points about MCR

• 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.

Uses of MCR in PLC Programs

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.

Jump Instruction (JMP):

The Jump (JMP) instruction in a Programmable Logic Controller (PLC) is a control


instruction that allows the PLC to "jump" over certain sections of the program, effectively
skipping rungs or instructions, and continue executing from a different point in the program.
This can be useful when certain logic or operations are not needed under specific conditions,
allowing for more efficient program execution.

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.

Key Components of the Jump Instruction

1. Jump (JMP) Instruction:


o The JMP instruction acts as the starting point for the jump. When the
conditions for the JMP instruction are met, the program will skip over the
following rungs or instructions.
o Conditional Jump: The jump can be triggered if the condition specified in the
JMP instruction is true. This condition can be based on sensor input, switches,
or internal logic.
2. Label (LBL) Instruction:
o The LBL instruction marks the destination point where the program will
resume execution after the jump.
o Each LBL instruction is assigned a unique label name or number, which
matches the JMP instruction that points to it. This ensures that the PLC knows
where to continue the execution after the jump.

Working of JMP and LBL Instructions

• 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.

Uses of Jump Instructions

1. Skipping Unnecessary Operations:


o Efficiency: By using the jump instruction, you can skip sections of the
program that don't need to be executed under certain conditions. This
increases the efficiency of the PLC by reducing scan time and saving
processing resources.
o Example: If certain machines are not operating in a multi-stage production
line, the program can jump over the control logic for those machines, avoiding
unnecessary actions.
2. Conditional Logic Execution:
o Simplification: Sometimes, you may want to avoid writing complicated
conditions within multiple rungs. A jump instruction allows you to skip large
sections of the program if a particular condition is true.
o Example: If a specific mode is selected on a machine (e.g., manual vs.
automatic), you can jump over the automatic control logic when the system is
in manual mode.
3. Fault Handling:
o Bypass Faulty Sections: If a fault occurs in one section of a system, you may
want to skip the normal operating instructions and jump directly to the fault-
handling logic. This can allow the system to respond quickly and efficiently to
the fault condition.
o Example: If a safety sensor detects an issue, the program can jump past
normal operations and go directly to the section that shuts down the machinery
or activates alarms.
4. Looping:
o Iterative Execution: Though not always ideal for creating loops (where FOR
or WHILE instructions are more common), jumps can be used to create simple
loops by jumping back to an earlier section of the program. This can be useful
for repeating certain tasks until a condition is met.
o Example: A jump could be used to create a loop that checks a sensor every
few seconds until it detects the required condition.

Benefits of Using Jump Instructions

• Simplifies Complex Logic: Jump instructions make it easier to manage complex


control systems by skipping irrelevant sections of code, which simplifies the overall
program structure.
• Reduces Scan Time: By skipping over unnecessary logic, the program can execute
faster, improving the system's overall efficiency and response time.
• Flexibility in Program Flow: Jump instructions allow for flexible, conditional
control over which sections of the program are executed, making the control system
more adaptable to changing conditions.

Important Considerations for Using Jump Instructions

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.

Key Differences Between Jump (JMP) and MCR:

Feature Jump (JMP) MCR


Skips over a section of code Enables or disables a block of code and its
Main Function
conditionally. outputs.
Effect on Skips execution of rungs, but does not Deactivates rungs and resets/de-energizes outputs
Program Logic affect the state of outputs. in the MCR zone.
Yes. Outputs are de-energized when MCR is
Reset of Outputs No. Outputs are unaffected by the jump.
false.
Pairing Requires a corresponding Label (LBL) Requires a paired MCR Start and MCR End to
Instructions instruction to mark the destination. define the control zone.
Used to temporarily disable or deactivate large
Used to conditionally bypass or skip over
Use Case sections of code, especially for safety or reset
sections of code.
purposes.
The logic between JMP and LBL is The logic in the MCR zone is either executed or
Effect on Rung
skipped entirely if the JMP condition is ignored depending on the state of the MCR
Evaluation
true. condition.

Subroutines Instructions (CALL/JSR):

A subroutine in PLC programming is a separate block of code designed to perform a


specific task. It can be called from various places in the main program whenever that task is
needed. Subroutines allow for the modular organization of complex programs, improving
readability, efficiency, and reusability of code. They also make it easier to maintain and
troubleshoot large programs.

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.

How Subroutines Work in PLCs

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.

• Jump to Subroutine (JSR):


• Redirects logic execution from the current ladder file to a specific subroutine file.
• When rung conditions for this instruction are true, the processor jumps to the targeted
subroutine.
• Each subroutine must have a unique file number (ranging from decimal 3 to 255).

• 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.

Key Features of Subroutines

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.

Declaring Subroutines as Local or Global

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.

Example in Ladder Logic: In some PLC programming environments like Rockwell


Automation's RSLogix 5000, subroutines can be local to the program in which they are
defined. This means they can only be called from within that program or task.

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.

Example in Ladder Logic: In RSLogix 5000, a subroutine can be declared globally by


defining it in a way that it is accessible from any part of the program. This allows you to use
the same logic across multiple programs or tasks.

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.

Basic Arithmetic Functions

The four fundamental mathematical operations performed by PLCs include:

• Addition: Adds one piece of data to another.


• Subtraction: Subtracts one piece of data from another.
• Multiplication: Multiplies one piece of data by another.
• Division: Divides one piece of data by another.

Instruction Overview

Math instructions use two registers or memory locations to perform the desired function. The
key math instructions for PLCs include:

• CPT (Compute): Evaluates a mathematical expression and stores the result in a


designated destination.
• ADD (Add): Adds Source A to Source B and stores the result in the destination.
• SUB (Subtract): Subtracts Source B from Source A and stores the result in the
destination.
• MUL (Multiply): Multiplies Source A by Source B and stores the result in the
destination.
• DIV (Divide): Divides Source A by Source B and stores the result in a specified math
register and destination.
• SQR (Square Root): Calculates the square root of the source and places the integer
result in the destination.
• NEG (Negate): Changes the sign of the source and places it in the destination.
• TOD (To BCD): Converts a 16-bit integer source value to Binary Coded Decimal
(BCD) and stores it.
• FRD (From BCD): Converts a BCD value to an integer and stores it in the
destination.

Instruction Parameters

Each basic math instruction has three parameter fields:

• 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

Compute Instruction (CPT)

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

The CPT instruction has two key components:

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.

Key Features of the CPT Instruction:

• 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

The result, 60, is then stored in N7:6.

Advantages of the CPT Instruction:

• 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.

Example of ADD Instruction (SLC 500 Controller):

• Source A: Addressed at memory location N7:0, containing a value (e.g., 25).


• Source B: Addressed at memory location N7:1, containing another value (e.g., 50).
• Destination: The result (e.g., 75) is stored at memory location N7:2.

Application Example with Counters:

In an application where a pilot light must turn on when the sum of the accumulated counts of
two up-counters reaches 350:

• Source A: The accumulated value of counter C5:0.


• Source B: The accumulated value of counter C5:1.
• Destination: The result is stored in memory location N7:1.
• GEQ Instruction:
o Source A (N7:1) is compared to Source B (a constant value of 350).
o If the sum of the two counters is equal to or greater than 350, the rung
becomes true, and the pilot light (PL1) turns on.
• Reset Button: Resets the accumulated counts of both counters to zero.
Arithmetic Status Bits (SLC 500 Controller):

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.

Key Features of the SUB Instruction:

• 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):

• Source A: Address N7:10, storing a value (e.g., 520).


• Source B: Address N7:05, storing another value (e.g., 322).
• Destination: The result of the subtraction (520 - 322 = 198) is stored in memory
location N7:20.

Application Example: Vessel Overfill Condition

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.

Operation Summary of the Logic Rung:

• Rung 1: Detects overfill condition and activates the alarm if necessary.


• Rung 2: Controls the filling indicating light.
• Rung 3: Monitors the weight of the vessel and controls the "full" indicator light.
• Rung 5: Energizes the alarm when the vessel is overfilled by 5 lb or more.

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.

Key Features of the MUL Instruction:

• Functionality: It multiplies Source A by Source B and stores the result in the


destination memory address.
• Memory Locations: Similar to other math instructions, Source A and Source B can
be constants or addresses that contain values, but both inputs cannot be constants at
the same time.

Example of MUL Instruction (SLC 500 Controller):

• Source A: Constant value (e.g., 20).


• Source B: Accumulated value from counter C5:10.
• Destination: The result of the multiplication is stored at memory location N7:2.

Example Application 1: Basic Multiplication

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.

Example Application 2: Oven Temperature Control

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:

• The set-point temperature is set via a thumbwheel switch (e.g., 400°F).


• The deadband is defined as ±1% of the set-point, so:
o For a 400°F set-point, the upper limit is 404°F and the lower limit is 396°F.
o For a 100°F set-point, the upper limit is 101°F and the lower limit is 99°F.
• Temperature Monitoring: An analog thermocouple interface monitors the oven's
temperature.
• MUL Instruction: The deadband is calculated by multiplying the set-point by the
percentage factor to define the on/off limits.
• Control Logic:
o The electric heaters are turned on when the temperature drops below the lower
limit (396°F).
o The heaters remain on until the temperature exceeds the upper limit (404°F).
• The upper temperature limit is stored in memory location N7:1, and the lower
temperature limit is stored in N7:2.

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.

Key Features of the DIV Instruction:

• 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.

Example of DIV Instruction (SLC 500 Controller):

• Source A: Accumulated value from counter C5:10.


• Source B: Constant value of 2.
• Destination: The quotient is stored in N7:3.

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:

• Source A: Address N7:0, containing 120.


• Source B: Address N7:1, containing 4.
• Destination: The result of the division (120 ÷ 4 = 30) is stored in N7:5.
• Equal Instruction: After the division, the EQU (Equal) instruction checks if the
result matches a specific value. When true, output PL1 is turned on.

Example Application 2: Celsius to Fahrenheit Conversion

The DIV instruction is part of a program used to convert Celsius temperature to


Fahrenheit. The conversion formula is:

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.

Key Points to Consider:


• Data Type Support: Some PLCs support both floating-point and integer values. For
example, dividing 10 by 3 can either result in a floating-point value 3.333333 or an
integer quotient of 3 with a remainder of 1.
• Division by Zero: Ensure that Source B is not zero to avoid a division by zero error,
which triggers a minor fault bit in the PLC system.

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.

How Sequencers Work:

• 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:

1. Step 1: Turn on the conveyor to move empty bottles into position.


2. Step 2: Start the filling machine when the bottles are in place (detected by a sensor).
3. Step 3: Cap the bottles after filling is complete.
4. Step 4: Label the bottles once the caps are on.
5. Step 5: Send the filled bottles out for packaging.

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.

Common Uses of Sequencers:

• Manufacturing Automation: Where processes need to follow a strict sequence (e.g.,


painting, welding, drilling).
• Conveyor Systems: Managing the movement of materials in a production line.
• Batch Processes: In industries like pharmaceuticals or food production, where steps
must happen in a specific order.

Sequencer Instructions in PLCs:

Depending on the PLC manufacturer, different sequencer instructions can be programmed.


The Allen-Bradley SLC 500 PLC, for instance, offers a range of sequencer commands
accessible through its RSLogix software.

Common Sequencer Instructions in Allen-Bradley Controllers:

1. SQO (Sequencer Output):


o An output instruction.
o Uses a predefined file to control multiple output devices.
2. SQI (Sequencer Input):
o An input instruction.
o Compares bits from an input file to corresponding bits from a source address.
o The instruction is true if all pairs of bits match.
3. SQC (Sequencer Compare):
o An output instruction.
o Compares bits from an input source file to corresponding bits in a sequence
file.
o If all pairs of bits match, a specific bit in the control register is set to 1.
4. SQL (Sequencer Load):
o An output instruction.
o Used to manually capture reference conditions by stepping the machine
through its operating sequences.
o Transfers data from the input source to the sequencer file, functioning
similarly to a file-to-word transfer instruction.

SQO (Sequencer Output) Instruction:

1. Placement in Ladder Logic:


o The SQO instruction is placed on the right side of the rung as an output in the
PLC program.
2. Step Progression:
o Each time the rung goes from a false-to-true state, the position moves to the
next step in the sequencer file.
3. Data Transfer:
o Data from the sequencer file is transferred through a mask to the specified
destination address. This happens each scan while the rung is true.
4. Completion of Sequence:
o When the last word in the file is transferred, the done bit is set.
o On the next false-to-true transition, the destination data is cleared, and the
position pointer resets to step one.
5. Start-Up Behavior:
o When the PLC switches from program mode to run mode:
▪ If the rung is true, the value in step zero is transferred.
▪ If false, the first false-to-true transition transfers the value in step one.
6. Mask Bits:
o Mask bits control data transfer:
▪ A 1 in the mask allows the data to pass.
▪ A 0 blocks the data and keeps the existing bit value.

Sequencer Parameters Overview:

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.

Programming the Sequencer:


1. Initial Setup:
o Binary data is entered into a sequencer file (typically a bit file). Each word in
the file represents a specific step in the sequence.
2. Data Transfer During Execution:
o The sequencer advances through its steps, transferring binary data from the
file to the output word, controlling devices like lights or motors.

Traffic Light Example (Figure 12-8):

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.

Masking in Sequencers (Figure 12-9):


1. Mask Function:
o The mask word filters which bits of the output word are controlled by the
sequencer.
o In this example, the hex value 003Fh is used, allowing the first six bits to be
controlled by the sequencer while the rest remain unchanged.
2. Selective Control:
o Bits passed through the mask control the outputs.
o Unmasked bits remain unaffected, allowing them to be used for other program
functions.

Sequencer Output Instruction Operation:

1. Triggering the Sequencer:


o The sequencer output instruction requires logic before it on the rung.
o When this preceding logic goes from false to true, the sequencer performs its
function.
o This function includes:
▪ Reading the data file.
▪ Applying the mask.
▪ Transferring the masked data to the output destination.
2. Cycle of Operation:
o After each false-to-true transition, the sequencer moves to the next step.
o It waits for another false-to-true signal to increment to the next position in the
sequence.

Example of Sequencer Operation (Figure 12-10):


1. Pushbutton Trigger:
o A pushbutton (PB) is used to send false-to-true signals to trigger the
sequencer.
o Each time the pushbutton is momentarily pressed (closed), the sequencer is
enabled and moves to the next step.
2. Step-by-Step Operation:
o Step 1:
▪ The binary data in word B3:1 (100001) is transferred to output word
O:2.
▪ As a result, outputs O:2/0 and O:2/5 are turned on, while all others
are off.
o Step 2:
▪ Data in word B3:2 (010001) is transferred to O:2.
▪ Outputs O:2/0 and O:2/4 are on, while the rest are off.
o Step 3:
▪ Data in word B3:3 (001100) is transferred to O:2.
▪ Outputs O:2/2 and O:2/3 are on, and the rest are off.
o Step 4:
▪ Data in word B3:4 (001010) is transferred to O:2.
▪ Outputs O:2/1 and O:2/3 are on, while the rest are off.
3. Completion of Sequence:
o When the position reaches the value set in the length parameter (in this case,
4), the done bit (DN) is set to 1.
o On the next false-to-true transition, the position pointer is automatically reset
to step 1.

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.

• Both SQOs use R6:0 for control and have a length of 4.

• 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.

How Do Bit Shift Registers Work?

• 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

Bit shift registers are useful in various applications, including:

• Tracking Parts: Monitor parts as they move through an assembly line.


• Control Operations: Manage machine or process operations efficiently.
• Inventory Control: Keep track of stock and inventory levels.
• System Diagnostics: Diagnose system issues by monitoring the status of components.

Data Representation in Shift Registers

The data stored in a shift register can represent various information, such as:

• Types, quality, and size of parts.


• Presence or absence of parts.
• Order of events.
• Identification numbers or locations.
• Fault conditions that may cause a shutdown.
Structure of Shift Registers

• 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.

Shift Instructions: BSL and BSR

Bit Shift Left (BSL)

• 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.

Bit Shift Right (BSR)

• 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.

Important Bits in Shift Instructions

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.

Programming a Bit Shift Instruction

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 a limit switch (LS) is activated, the BSL instruction executes.


2. Data in the register shifts one bit position to the left.
3. The specified source bit (e.g., I:1/1) is inserted into the first position (B3:10/0).
4. The last bit of the array is sent to the unload bit (R6:0/UL), and that status is lost.
5. Any bits in the last word of the file that are not used become invalid.
Example: Bit Shift Right (BSR) 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.

BSL with Wraparound Operation


Use a BSL instruction to shift a logic '1' through a series of bits, activating pilot lights (PL1,
PL2, PL3) in sequence, each for 3 seconds.

Components Used

• Data Table: B3:0 (Bit Array)


• Unload Bit: R6:0/UL
• Input Switch: SW (to start the process)
• On-Delay Timer: T4:0 (3-second timing)
• Pilot Lights: PL1, PL2, PL3 (output devices)

Initial Setup

1. Set initial conditions:


o Bit addresses B3:0/0, B3:0/1, and B3:0/2 to Logic 0.
o Bit address R6:0/UL to Logic 1.

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.

FIFO (First In, First Out)

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.

FFL (FIFO Load) Instruction

• 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).

FFU (FIFO Unload) Instruction

• 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.

Status Bits in FIFO

1. Enable Bit (EN): Set to 1 when the instruction is active.


2. Done Bit (DN): Set to 1 when the FIFO stack is full.
3. Empty Bit (EM): Set to 1 when all data has been unloaded from the FIFO.

Example FIFO Operation

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).

LIFO (Last In, First Out)

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.

LIFO Load (LFL) and Unload (LFU) Instructions


• Operation: Works similarly to FIFO but removes data in the reverse order (last in,
first out).
• Characteristics:
o Words can be added to the LIFO stack without disturbing the existing words.
o The last word added is the first word to be removed.

Key Differences Between FIFO and LIFO

Feature FIFO LIFO


Order of Operation First In, First Out Last In, First Out
Access Method Data removed in order they were added Data removed in reverse order
Analogy Queue (people lining up) Stack (like plates in a pile)

Data Manipulation in PLCs


Overview of Data Manipulation

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

This allows for quantitative decision-making applicable to various control scenarios,


including analog and positioning control.

Types of Data Manipulation Instructions


Data manipulation instructions can be divided into two primary classes:

1. Instructions Operating on Word Data: These involve operations on individual


words (registers).
2. Instructions Operating on File (Block) Data: These involve operations on multiple
words, often in consecutive memory locations.

Terminology

• Word: A single unit of data memory, often referred to as a register.


• File: A group of consecutive words or registers.

Categories of Data Manipulation

Data manipulation can be broadly categorized into:

1. Data Transfer Operations


2. Data Comparison Operations

Data Transfer Operations

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.

Application Example: Timer Presets

• Two-position selector switch controls the preset value of a timer:


o When in the 10-second position, the value 10 from N7:1 is copied to
T4:1.PRE.
o In the 5-second position, the value 5 from N7:2 is copied to T4:1.PRE.
Data Comparison Operations

Data comparison instructions assess and compare numerical values stored in registers. These
comparisons inform decision-making processes within the control logic.

Key Instructions

1. LIM (Limit Test): Checks if a value falls within a specified range.


2. EQU (Equal): Tests if two values are equal.
3. NEQ (Not Equal): Tests if two values are not equal.
4. LES (Less Than): Tests if one value is less than another.
5. GRT (Greater Than): Tests if one value is greater than another.
6. LEQ (Less Than or Equal): Tests if one value is less than or equal to another.
7. GEQ (Greater Than or Equal): Tests if one value is greater than or equal to another.
8. MEQ (Masked Comparison for Equal): Compares specific bits of two values, using
a mask to filter which bits to compare.

You might also like