In digital electronics, a shift register is a type of
register that allows the contents of its bits to be moved (shifted) left or
right. This functionality is useful in various control systems, where data
needs to be moved or manipulated in a sequence. When we bring this concept into
the realm of Mitsubishi PLC programming, there are specialized
instructions such as SFR, SFL, BSFR, and BSFL that
can be used to shift bits according to the specific requirements of the control
process.
Let's explore these instructions and see how they are
applied in Mitsubishi PLCs.
1. SFR and SFL Instructions in Mitsubishi PLC
In Mitsubishi PLCs, the SFR (Shift Right) and SFL
(Shift Left) instructions are used to shift bits within a 16-bit word. These
instructions allow you to manipulate data in a register (such as D10) by
shifting bits either to the right or left.
- SFR
(Shift Right): This instruction shifts the bits of a 16-bit word to
the right by a specified number of bits. Each shift to the right results
in the least significant bit (rightmost bit) being shifted out, and the
leftmost bit being filled with zero.
- SFL
(Shift Left): Similarly, this instruction shifts the bits of a 16-bit
word to the left by a specified number of bits. Each shift to the left
moves the most significant bit (leftmost bit) out, and the rightmost bit
is filled with zero.
The number of bits to shift is specified by a constant
(denoted as K1, K2, etc.) in the ladder diagram.
Example of SFR and SFL in Ladder Logic
Consider a simple scenario where we use SFR and SFL
instructions with a 16-bit register like D10. Let’s break it down:
The SFR instruction will shift the contents of the D10 register to the right by the number of bits specified. For example, if we specify K1 as the number of bits to shift, the contents of D10 will move to the right by one position. Every time this instruction is executed, the data in D10 will be shifted to the right by the specified number of bits.
LD M0 // If M0 is ON, the shift will happen
SFR D10 K1 // Shift D10 to the right by K1 (1 bit).
The SFL instruction works similarly to the SFR instruction, but instead of shifting the bits to the right, it shifts the bits to the left.. If K1 is used to specify the number of bits to shift, each execution will move the contents of D10 to the left by one position.
LD M1 // If M1 is ON, the shift will happen
SFL D10 K1 // Shift D10 to the left by K1 (1 bit)\
Practical Example: Shifting Bits in Action
Let’s look at a practical example to better understand how
the SFR and SFL instructions work.
Imagine that we have a 16-bit register (D10) with the
following initial value:
Scenario 1: Using M0 to Shift Right
When you press M0 once, the SFR instruction
will shift the bits of D10 to the right by K1 (1 bit). Here’s
what happens:
- Initial
State of D10:
- 1000001000000000
- After
pressing M0 once (shift right by 1 bit):
- 0100000100000000
Scenario 2: Pressing M0 Multiple Times
If you press M0 four more times, the bits will
continue shifting to the right each time. The sequence would look like this:
- After
1st press (shift right by 1 bit):
- 0010000010000000
- After
2nd press (shift right by another bit):
- 0001000001000000
- After
3rd press (shift right by another bit):
- 0000100000100000
- After
4th press (shift right by another bit):
- 0000010000010000
As you can see, with each press of M0, the bits move
one position to the right.
Scenario 3: Using M1 to Shift Left
Now, let’s say we want to shift the bits of D10 back
to the left. If you press M1, the SFL instruction will shift the
bits of D10 to the left by K1 (1 bit) for each press.
- Initial
State of D10 (after shifting right):
- 0000010000010000
- After
pressing M1 once (shift left by 1 bit):
- 0000100000100000
BSFR and BSFL Instructions: Bit-Specific Shifting
Mitsubishi PLCs also provide BSFR and BSFL
instructions, which are similar to SFR and SFL, but operate on
specific bits rather than on entire 16-bit words. These instructions are used
to shift individual bits of a bit array, allowing for more granular control of
data.
- BSFR
(Bit Shift Right): Shifts individual bits in a bit array to the right.
- BSFL
(Bit Shift Left): Shifts individual bits in a bit array to the left.
These instructions are useful when you want to manipulate
individual bits in a more detailed manner, such as in a bit pattern or for
controlling specific outputs based on bit-level operations.
In Mitsubishi PLC programming, SFR, SFL, BSFR,
and BSFL are essential instructions for performing bit shifting
operations. Whether you're dealing with a 16-bit word or working with
individual bits, these instructions allow you to manipulate and control data
efficiently. Understanding how to use these shift register instructions in Mitsubishi
PLCs can greatly enhance your ability to develop complex and effective
control systems.
- SFR
and SFL are used for shifting entire 16-bit words to the right or
left.
- BSFR
and BSFL are used for bit-level shifting, offering more detailed
control.
By incorporating these instructions into your ladder logic,
you can achieve precise timing and control for a variety of industrial
automation applications.