MP STUDIO 2 · Functions · V1.4.0 and later
MP STUDIO 2 · Bit Control Functions
The bit control functions are five functions (V1.4.0 and later): FF, BSFT, BRST and BSETN, which toggle bits, shift them one place at a time, or turn a range of them off or on at once, and the timer TFLK, which blinks with separately set ON and OFF times. Circuits that used to take several rungs, such as turning an output on and off with a single push button, tracking the position of products and rejects on a conveyor, or blinking a beacon, can be written with a single function.
| Functions | Categories | Execution | Version |
|---|---|---|---|
| 5 | Bit Logic, Timer | Edge, level, cycle | V1.4.0 and later |
- Toggles on each press
FFtoggles its bit only at the moment the condition turns ON, so you can connect it directly after a push button contact without a rising edge contact. - Shifts one place at a time
Each time the condition turns ON,BSFTshifts N bits by one place and puts a new value into the empty place. - A whole range at once
BRSTandBSETNturn off or turn on all N bits from the start bit. - Separate ON and OFF times
TFLKrepeatedly turns on for the ON time and off for the OFF time.
On this page
Finding and Inserting the Functions
FF, BSFT, BRST and BSETN are in the Bit Logic category of the Functions panel, and TFLK is in the Timer category. You insert them the same way as other functions: double-click a row in the Functions panel, or type the whole instruction on one line in the Insert Function window (Ctrl+E), as in FF P32. You can also find them by typing bit, flip, shift or flicker in the search box of the Functions panel.
| Function | Name in the Functions panel | Block cells (from the left) |
|---|---|---|
FF | FF: Flip-Flop (Toggle Bit) | OUT |
BSFT | BSFT: Bit Shift Register | BIT, N, IN, DIR |
BRST | BRST: Reset Bit Range | BIT, N |
BSETN | BSETN: Set Bit Range | BIT, N |
TFLK | TFLK: Flicker Timer (ON/OFF) | TIMER, ON, OFF |
- ① Bit Logic category: the number on the right is the number of functions in the category (4).
- ② FF, BSFT, BRST and BSETN: double-click to insert the function at the cursor cell.
- ③ TFLK: the last row of the Timer category.
In the Insert Function window, the argument order of TFLK is shown as [TFLK] [IN] [ON] [OFF], and the first argument (the timer address) goes into the TIMER cell of the block.
Common Behavior
All five functions run on the condition to the left of the block. When they act depends on the function.
| Function | When it acts |
|---|---|
FF, BSFT | Once, in the scan in which the condition goes from OFF to ON (the same timing as a rising edge contact) |
BRST, BSETN | In every scan in which the condition is ON |
TFLK | Repeats the ON time and the OFF time while the condition is ON |
FF,BSFT,BRSTandBSETNpass the condition on the left straight through to the right of the block, so you can put a coil after them. The right side ofTFLKis the blinking output.FFandBSFTremember the previous condition separately for each block.- If the condition is already ON in the first scan after power-on or a download, it is treated as a change from OFF to ON. In that case,
FFtoggles once andBSFTshifts one place. - Inside an
MCSsection, while the section is off, the block works as if its condition were OFF, and the right side of the block is off too (other function blocks run regardless ofMCS). If the condition is ON when the section turns back on, it is treated as a change from OFF to ON.
FF Flip-Flop
FF toggles the OUT bit (0 becomes 1, and 1 becomes 0) only in the scan in which the condition goes from OFF to ON. It does not toggle again while the condition stays ON. For example, FF P32 after a P0 contact turns P32 on and off each time P0 is pressed.
- OUT can be a
PorMbit, a bit inside a D word such asD10.5, or a#nameuser bit. - Two
FFfunctions can toggle the same bit. If you putFF P32after bothP0andP1, pressing either button changesP32. If both conditions turn ON in the same scan, the bit is toggled twice and stays as it was.
A coil on the same bit overwrites the FF result
If you also use the OUT bit ofFFin a normal coil, the coil writes that bit again in every scan, so the value thatFFtoggled does not stay. Like the bit of a SET coil, the OUT bit is not covered by the duplicate coil check, so the check does not report it either. Do not use the OUT bit ofFFin a normal coil as well.
BSFT Bit Shift Register
Each time the condition goes from OFF to ON, BSFT shifts the N bits from BIT by one place and puts the value of IN into the place that becomes empty. DIR sets the direction. Use it in circuits that move values along with a position, such as tracking and ejecting rejects on a conveyor, sequential lighting and process history.
| DIR | Shift direction | Where IN goes | Value shifted out and lost |
|---|---|---|---|
| 0 | Toward higher numbers | BIT | The value of BIT+N-1 |
| 1 | Toward lower numbers | BIT+N-1 | The value of BIT |
For example, each time the condition turns ON, BSFT M200 8 P2 0 moves the values of M200 to M206 up by one place (to M201 to M207) and puts the value of P2 at that moment into M200. The value that was in M207 is lost.
- BIT: the start bit. You can use a
PorMbit, or a bit inside a D word such asD10.0. Bits inside D words continue fromD10.15toD11.0. - N: the number of bits. Use a constant of 1 or more, or a byte or word address such as
D0orBD0. - IN: the value to put in. Use 0, 1 or a bit such as
M5orP1. - DIR: the shift direction. Use 0, 1 or a bit.
If IN or DIR is a bit, its value in the scan in which the condition turned ON is read.
- ① BSFT block: the BIT, N, IN and DIR cells.
- ② Data Table: shows the values shifted into
M200toM207. - ③ Eject rung:
M207is on, soP33is on.
BRST and BSETN Reset and Set Bit Range
BRST writes 0 to all N bits from BIT, and BSETN writes 1 to all of them. They write in every scan in which the condition is ON, and writing the same value again and again does no harm. BIT and N take the same values as in BSFT.
| Example | Action |
|---|---|
BRST M200 8 | Turns off M200 to M207. |
BSETN D20.0 8 | Turns on bits 0 to 7 of D20. |
BRST M0 D0 | Turns off as many bits from M0 as the value of D0. |
TFLK Flicker Timer
When the condition turns ON, TFLK starts with the output on and repeats the cycle: on for the ON time, then off for the OFF time. The output is the power that continues to the right of the block, and the contact of the timer in the TIMER cell (for example T5) turns on and off with the same value, so other rungs can use the same blink.
- The current value of the timer in the TIMER cell is the time elapsed within one cycle. When it reaches the ON time plus the OFF time, it starts counting again from 0.
- When the condition turns OFF, the output turns off at once and the current value becomes 0. When the condition turns ON again, it starts again with the output on.
- If the ON time is 0, the output is always off. If the OFF time is 0, the output stays on while the condition is ON.
- The scan that turns the output on is counted too, so if the ON time is shorter than one scan, the output can turn off right after it turns on.
- A blink with equal ON and OFF times and a fixed period can also be made with the system bit
@Fn. UseTFLKwhen you want to set the ON time and the OFF time separately.
- ①
T5current value: the time elapsed within one cycle. - ② ON and OFF: the ON time (
20= 0.2 seconds) and the OFF time (180= 1.8 seconds). - ③
P34: the output ofTFLK. - ④
T5contact: turnsP35on and off with the same value as the output ofTFLK.
ON and OFF use the same units as the set value (SET VALUE) of TON. A number alone is in units of 10 ms (20 is 0.2 seconds), and a value with a unit, such as 200MS, 2S, 1M or 1H, is that time. A value shorter than 10 ms, such as 5MS, is entered as 50 ms, 10 times longer, and an orange warning is shown on the cell. You can also use byte, word and double word addresses such as BD0, D0 and DD0.
In a project whose timer base is set to 1 ms, numbers are in units of 1 ms. In the Change timer base window that appears when you change the timer base, the ON and OFF values of TFLK written as numbers are counted as set values too, and if you choose Adjust values too (keep the same time), they are also changed to match the new base.
As with TON, the TIMER cell can be BT5 (byte), T5 (word) or DT5 (double word), and the size of the timer sets the longest possible cycle (ON time+OFF time). The timer number must not be the same as that of another timer function. If it is, “Timer memory cannot be used more than once.” is shown when you compile.
| TIMER cell | Longest cycle (timer base 10 ms) | Longest cycle (timer base 1 ms) |
|---|---|---|
BT | 2.55 s | 0.255 s |
T | 655.35 s | 65.535 s |
DT | About 497 days | About 49.7 days |
Inputs That Do Not Compile
For the inputs below, the cell turns red and the program cannot be compiled. Select the cell to see the reason in the Inspector, or hover over it to see the reason in a tooltip.
| Cell | Inputs that do not compile |
|---|---|
OUT of FF | A system bit that the PLC sets in every scan, such as @BEGIN, a word address such as T0 or D10, or a comparison such as D0>3 |
BIT of BSFT, BRST and BSETN | A #name user bit, an @ system bit, a T, C or D word address, or a comparison |
N of BSFT, BRST and BSETN | A constant of 0 or less, a count that runs past the end of the area (for example BSETN M2040 9 when the M area ends at M2047), or a double word address such as DD0 |
IN and DIR of BSFT | A constant other than 0 or 1 (such as 2 or -1), or a byte or word address such as BD0 or D0 |
ON and OFF of TFLK | A negative value, or constants whose sum does not fit in the timer (for example 40000 and 40000 when TIMER is T1) |
TIMER of TFLK | A timer narrower than the value in ON (for example T1 when ON is DD0 or 70000) |
The cells of the five functions cannot take an indexed address (D100[D0]).
For example, if you enter TFLK T6 40000 40000, the OFF cell turns red and “The ON time plus the OFF time of TFLK (80000) is more than 65535, the largest value timer T6 can hold, so the program does not compile. Shorten the times or use a wider timer (DT).” is shown.
Out of Range and @IXERR
If you write an address such as D10 in N, the count is decided while the program runs. The end of the area is the size set in Data Memory for M and D. For P, it is the end of the whole P area, P55 or P127 depending on the model, not the last real I/O terminal. If, when the block runs, N is 0 or less or the N bits from BIT run past the end of their area, the PLC does the following.
- It skips only that block. It writes no bits, so no other memory is overwritten, and the right side of the block passes the condition through unchanged (unlike an indexed address that goes out of range, the power output does not turn off).
- The system bit
@IXERRturns on. - While the condition is OFF (for
BSFT, in any scan other than the one in which the condition turns ON), the range is not checked, so@IXERRdoes not turn on.
If you write addresses in ON and OFF of TFLK and one cycle exceeds the maximum in the table above when the block runs, @IXERR turns on, and the output stays off with the current value held at 0.
@IXERR is the same bit that turns on when an indexed address goes out of range, and it does not turn off by itself. You turn it off the same way as for indexed addresses. In a program that does not use indexed addresses, the notice during monitoring and simulation (“An index went out of range — …”) appears only when @IXERR is on the ladder screen or in the Data Table. To catch a bit control function going out of range, put an @IXERR contact in the ladder.
- ① N cell
D10: the value is 0, soBRST M300 D10was skipped. - ②
@IXERRrung:@IXERRis on, so the coilM1after it is on.
Monitoring and Simulation
The five functions work the same in simulation as on the PLC.
- When the condition is ON, the blocks of
FF,BSFT,BRSTandBSETNare shown in the power-flow color. A cell with an address shows the current value of that address, and a constant cell shows no value. - The value in the BIT cell is the value of the start bit alone. To see the whole range, add the addresses to the Data Table.
- The TIMER cell of
TFLKshows the current value of the timer. During the ON time, the block and the output are shown in the power-flow color. During the OFF time, they are shown without output, as while aTONis counting. - To see a single moment of the blink, use Pause and Step one scan on the simulation bar.
- In Run → Used Data, if N is a constant, the N bits from BIT are painted as used, and if N is an address, only the start bit is painted (
MandDareas).
Examples
You can write the three examples in order in a new MPA-8A8R(T) project (default data memory) and check them in simulation.
Example 1. Toggling a Lamp with a Single Push Button
In this example, each press of P0 turns the P32 lamp on or off.
- In Settings → Symbol, register LAMP_BTN for
P0and LAMP forP32. - Write the rung below.
| Rung | Input | Function | What it does |
|---|---|---|---|
| 0 | P0 | FF P32 | Toggles P32 each time P0 is pressed. |
Start Run → Simulation, and turn the P0 chip on the simulation bar on and off several times. Each time you turn P0 on, P32 switches between on and off (Figure 3), and it does not change while P0 stays on.
Example 2. Tracking Rejects on a Conveyor
In this example, each time the conveyor moves one place, the reject detection result is shifted into M200 to M207, and when a reject reaches the eject position at the eighth place (M207), it is ejected with P33.
- In Settings → Symbol, register MOVE_PULSE for
P1, NG_SENSOR forP2, CLEAR_BTN forP3, TRACK forM200and EJECT forP33. - Write the rungs below after the rung of Example 1.
| Rung | Input | Function or coil | What it does |
|---|---|---|---|
| 1 | P1 | BSFT M200 8 P2 0 | Each time the conveyor moves one place, puts the value of P2 into M200 and shifts M200 to M207 by one place. |
| 2 | M207 | Coil P33 | Ejects the reject that has reached the eject position. |
| 3 | P3 | BRST M200 8 | Clears all tracking records. |
During simulation, add M200 to M207 to the Data Table, and turn P1 on and off once with P2 on. Then turn P2 off and turn P1 on and off seven more times. The first reject reaches M207, and P33 turns on. Figure 4 shows the case in which the first and third products are rejects. Turning P3 on turns off all of M200 to M207, and because rung 2 comes before rung 3, P33 turns off in the next scan.
Example 3. Blinking a Beacon
In this example, while the alarm input P4 is ON, the beacon P34 repeatedly turns on for 0.2 seconds and off for 1.8 seconds (timer base 10 ms).
- In Settings → Symbol, register ALARM for
P4and BEACON forP34. - Write the rungs below after the rungs of Example 2.
| Rung | Input | Function or coil | What it does |
|---|---|---|---|
| 4 | P4 | TFLK T5 20 180 followed by coil P34 | Turns on for 0.2 seconds and off for 1.8 seconds. TFLK T5 200MS 1800MS works the same way. |
| 5 | T5 | Coil P35 | Gives the same blink on P35. |
During simulation, when you turn P4 on, P34 and P35 turn on for 0.2 seconds every 2 seconds, and the current value of T5 rises from 0 to 199 and then returns to 0 (Figure 5). When you turn P4 off, they turn off at once and T5 becomes 0.
Things to Check
- The bits that
FFandBSFTuse to remember the previous condition are set up automatically and do not appear in the symbol table, the Data Table or Used Data.
Cannot be opened in V1.3.0 and earlier
A.mpxproject that uses even one bit control function cannot be opened in V1.3.0 and earlier versions of the app.





