en-us_products:mp_studio:bit_control

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en-us_products:mp_studio:bit_control [2026/11/12 20:37] – external edit 127.0.0.1en-us_products:mp_studio:bit_control [2026/11/13 13:42] (current) – external edit 127.0.0.1
Line 3: Line 3:
 ====== MP STUDIO 2 · Bit Control Functions ====== ====== 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.+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. In V1.5.0 and later, eleven more functions are available. ''BMOV'' and ''BSUM'' copy a range of bits or count the bits that are on, ''ROL'' and ''ROR'' rotate a word, ''LOADB'', ''LOADBN'', ''BOUT'', ''BSET'' and ''BRESET'' read or write a bit whose number is given as a value, and ''SSET'' and ''SOUT'' move a process forward by step number. 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, blinking a beacon, or running a process in sequence, can be written with a single function.
  
 [[#examples|View examples]] [[#finding_and_inserting_the_functions|How to insert]] [[#examples|View examples]] [[#finding_and_inserting_the_functions|How to insert]]
  
-{{ :en-us_products:mp_studio:bf-hero.png?1600 |The whole MP STUDIO 2 window while an example program runs in simulation, with the Bit Logic category of the Functions panel and the values of the FF, BSFT and TFLK blocks shown }}+{{ :en-us_products:mp_studio:bf-hero.png?1600 |The whole MP STUDIO 2 window while an example program runs in simulation, with the Bit Logic category of the Functions panel and the values of the FF, BSFT, TFLK, BSUM, LOADB and ROL blocks shown }}
  
 ^ Functions ^ Categories ^ Execution ^ Version ^ ^ Functions ^ Categories ^ Execution ^ Version ^
-| 5 | Bit Logic, Timer | Edge, level, cycle | V1.4.0 and later |+| 16 | Bit Logic and 3 others | Edge, level, cycle, every scan | V1.4.0 and later (11 in V1.5.0 and later) |
  
   * **Toggles on each press**\\ ''FF'' toggles 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.   * **Toggles on each press**\\ ''FF'' toggles 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.
Line 16: Line 16:
   * **A whole range at once**\\ ''BRST'' and ''BSETN'' turn off or turn on all N bits from the start bit.   * **A whole range at once**\\ ''BRST'' and ''BSETN'' turn off or turn on all N bits from the start bit.
   * **Separate ON and OFF times**\\ ''TFLK'' repeatedly turns on for the ON time and off for the OFF time.   * **Separate ON and OFF times**\\ ''TFLK'' repeatedly turns on for the ON time and off for the OFF time.
 +  * **Bit number as a value**\\ ''LOADB'', ''BOUT'', ''BSET'', ''BRESET'' and the others read and write the bit of a word whose number you give as a constant or an address (V1.5.0 and later).
 +  * **Processes run in steps**\\ ''SSET'' and ''SOUT'' treat the value of one address as the current step number and run a process in order (V1.5.0 and later).
  
 **On this page** **On this page**
Line 24: Line 26:
   * [[#brst_and_bsetn_reset_and_set_bit_range|BRST and BSETN Reset and Set Bit Range]]   * [[#brst_and_bsetn_reset_and_set_bit_range|BRST and BSETN Reset and Set Bit Range]]
   * [[#tflk_flicker_timer|TFLK Flicker Timer]]   * [[#tflk_flicker_timer|TFLK Flicker Timer]]
 +  * [[#bmov_and_bsum_copy_bit_range_and_count_on_bits|BMOV and BSUM Copy Bit Range and Count ON Bits]]
 +  * [[#rol_and_ror_rotate_left_and_right|ROL and ROR Rotate Left and Right]]
 +  * [[#loadb_loadbn_bout_bset_and_breset_bit_n_contacts_and_outputs|LOADB, LOADBN, BOUT, BSET and BRESET Bit N Contacts and Outputs]]
 +  * [[#sset_and_sout_step_control|SSET and SOUT Step Control]]
   * [[#inputs_that_do_not_compile|Inputs That Do Not Compile]]   * [[#inputs_that_do_not_compile|Inputs That Do Not Compile]]
   * [[#out_of_range_and_ixerr|Out of Range and @IXERR]]   * [[#out_of_range_and_ixerr|Out of Range and @IXERR]]
Line 34: Line 40:
 ===== Finding and Inserting the Functions ===== ===== 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 [[:en-us_products:mp_studio:functions#insert_function_window|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.+''FF'', ''BSFT'', ''BRST'' and ''BSETN'' are in the **Bit Logic** category of the Functions panel, and ''TFLK'' is in the **Timer** category. Of the functions added in V1.5.0, ''ROL'' and ''ROR'' are in the **Word Logic** category, ''SSET'' and ''SOUT'' are in the **Program Control** category, and the rest are in the **Bit Logic** 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 [[:en-us_products:mp_studio:functions#insert_function_window|Insert Function window]] (''Ctrl+E''), as in ''FF P32''. You can also find them by typing ''bit'', ''flip'', ''shift'', ''flicker'', ''rotate'' or ''step'' in the search box of the Functions panel.
  
 ^ Function ^ Name in the Functions panel ^ Block cells (from the left) ^ ^ Function ^ Name in the Functions panel ^ Block cells (from the left) ^
Line 42: Line 48:
 | ''BSETN'' | BSETN: Set Bit Range | BIT, N | | ''BSETN'' | BSETN: Set Bit Range | BIT, N |
 | ''TFLK'' | TFLK: Flicker Timer (ON/OFF) | TIMER, ON, OFF | | ''TFLK'' | TFLK: Flicker Timer (ON/OFF) | TIMER, ON, OFF |
 +| ''LOADB'' | LOADB: Bit N Contact | IN, N |
 +| ''LOADBN'' | LOADBN: Bit N Contact (Inverted) | IN, N |
 +| ''BOUT'' | BOUT: Bit N Output | OUT, N |
 +| ''BSET'' | BSET: Set Bit N | OUT, N |
 +| ''BRESET'' | BRESET: Reset Bit N | OUT, N |
 +| ''BMOV'' | BMOV: Copy Bit Range | IN, SB, OUT, DB, N |
 +| ''BSUM'' | BSUM: Count ON Bits | IN, OUT |
 +| ''ROL'' | ROL: Rotate Left | IN, N, OUT |
 +| ''ROR'' | ROR: Rotate Right | IN, N, OUT |
 +| ''SSET'' | SSET: Set Step (Sequential) | GROUP, STEP |
 +| ''SOUT'' | SOUT: Step Output (Last Wins) | GROUP, STEP |
  
 {{ :en-us_products:mp_studio:bf-palette-marked.svg?300 |Figure 1. The Functions panel with the Bit Logic and Timer categories expanded }} {{ :en-us_products:mp_studio:bf-palette-marked.svg?300 |Figure 1. The Functions panel with the Bit Logic and Timer categories expanded }}
  
-  * **① Bit Logic category:** the number on the right is the number of functions in the category (4).+  * **① Bit Logic category:** the number on the right is the number of functions in the category (11).
   * **② FF, BSFT, BRST and BSETN:** double-click to insert the function at the cursor cell.   * **② FF, BSFT, BRST and BSETN:** double-click to insert the function at the cursor cell.
-  * **③ TFLK:** the last row of the Timer category.+  * **③ LOADB to BSUM:** the Bit Logic functions added in V1.5.0. 
 +  * **④ 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.+{{ :en-us_products:mp_studio:bf-palette2-marked.svg?300 |Figure 2. The Functions panel with the Word Logic and Program Control categories expanded }}
  
-{{ :en-us_products:mp_studio:bf-insert.png?470 |Figure 2. The Insert Function window with TFLK T5 20 180 entered, showing the argument order and description }}+  * **① ROL and ROR:** the last two rows of the Word Logic category. 
 +  * **② SSET and SOUT:** the last two rows of the Program Control 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. For the functions added in V1.5.0, the argument order is the same as the order of the block cells, as in ''[BMOV] [IN] [SB] [OUT] [DB] [N]''. 
 + 
 +{{ :en-us_products:mp_studio:bf-insert.png?470 |Figure 3. The Insert Function window with TFLK T5 20 180 entered, showing the argument order and description }}
  
 ===== Common Behavior ===== ===== Common Behavior =====
  
-All five functions run on the condition to the left of the block. When they act depends on the function.+All bit control functions run on the condition to the left of the block. When they act depends on the function.
  
 ^ Function ^ When it acts ^ ^ 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) | | ''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 |+| ''BRST'', ''BSETN'', ''BMOV'', ''BSUM'', ''ROL'', ''ROR'', ''BSET'', ''BRESET'', ''SSET'', ''SOUT'' | In every scan in which the condition is ON |
 | ''TFLK'' | Repeats the ON time and the OFF time while the condition is ON | | ''TFLK'' | Repeats the ON time and the OFF time while the condition is ON |
 +| ''BOUT'' | In every scan (writes 1 when the condition is ON and 0 when it is OFF) |
 +| ''LOADB'', ''LOADBN'' | Checks the bit in every scan, like a contact |
  
-  * ''FF'', ''BSFT'', ''BRST'' and ''BSETN'' pass the condition on the left straight through to the right of the block, so you can put a coil after them. The right side of ''TFLK'' is the blinking output.+  * Except for ''TFLK'', ''LOADB'' and ''LOADBN'', the functions pass the condition on the left straight through to the right of the block, so you can put a coil after them. The right side of ''TFLK'' is the blinking output, and the right side of ''LOADB'' and ''LOADBN'' is the result of checking the bit, as with a contact.
   * ''FF'' and ''BSFT'' remember the previous condition separately for each block.   * ''FF'' and ''BSFT'' remember 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, ''FF'' toggles once and ''BSFT'' shifts one place.   * 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, ''FF'' toggles once and ''BSFT'' shifts one place.
-  * Inside an ''MCS'' section, 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 of ''MCS''). If the condition is ON when the section turns back on, it is treated as a change from OFF to ON.+  * Inside an ''MCS'' section, 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 of ''MCS''). In that case, ''BOUT'' writes 0 to its bit, and ''LOADB'' and ''LOADBN'' are false. 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 Flip-Flop =====
Line 71: Line 96:
 ''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. ''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.
  
-{{ :en-us_products:mp_studio:bf-ff-sim.png?1022 |Figure 3. FF turning P32 on after P0 was turned on in simulation }}+{{ :en-us_products:mp_studio:bf-ff-sim.png?1022 |Figure 4. FF turning P32 on after P0 was turned on in simulation }}
  
   * OUT can be a ''P'' or ''M'' bit, a bit inside a D word such as ''D10.5'', or a ''#name'' user bit.   * OUT can be a ''P'' or ''M'' bit, a bit inside a D word such as ''D10.5'', or a ''#name'' user bit.
Line 90: Line 115:
  
   * **BIT:** the start bit. You can use a ''P'' or ''M'' bit, or a bit inside a D word such as ''D10.0''. Bits inside D words continue from ''D10.15'' to ''D11.0''.   * **BIT:** the start bit. You can use a ''P'' or ''M'' bit, or a bit inside a D word such as ''D10.0''. Bits inside D words continue from ''D10.15'' to ''D11.0''.
-  * **N:** the number of bits. Use a constant of 1 or more, or a byte or word address such as ''D0'' or ''BD0''. +  * **N:** the number of bits. Use a constant of 1 or more, or a byte or word address such as ''D0'' or ''BD0''. In V1.5.0 and later, you can also use a double word address such as ''DD0''. 
-  * **IN:** the value to put in. Use 0, 1 or a bit such as ''M5'' or ''P1''. +  * **IN:** the value to put in. Use 0, 1 or a bit such as ''M5'' or ''P1''. In V1.5.0 and later, you can also use byte, word and double word addresses such as ''BD0'', ''D0'' and ''DD0'', and any integer. A value of 0 puts in 0, and any other value puts in 1. 
-  * **DIR:** the shift direction. Use 0, 1 or a bit.+  * **DIR:** the shift direction. Use 0, 1 or a bit. In V1.5.0 and later, you can also use addresses and integers, as with IN, and any value other than 0 is treated as 1.
  
-If IN or DIR is a bit, its value in the scan in which the condition turned ON is read.+If IN or DIR is a bit or an address, its value in the scan in which the condition turned ON is read.
  
-{{ :en-us_products:mp_studio:bf-bsft-sim-marked.svg?857 |Figure 4. BSFT in simulation, with the reject detection results shifted into M200 to M207 }}+{{ :en-us_products:mp_studio:bf-bsft-sim-marked.svg?857 |Figure 5. BSFT in simulation, with the reject detection results shifted into M200 to M207 }}
  
   * **① BSFT block:** the BIT, N, IN and DIR cells.   * **① BSFT block:** the BIT, N, IN and DIR cells.
Line 121: Line 146:
   * A blink with equal ON and OFF times and a fixed period can also be made with the [[:en-us_products:mp_studio:memory_symbols#system_bits_and_user_variables|system bit]] ''@Fn''. Use ''TFLK'' when you want to set the ON time and the OFF time separately.   * A blink with equal ON and OFF times and a fixed period can also be made with the [[:en-us_products:mp_studio:memory_symbols#system_bits_and_user_variables|system bit]] ''@Fn''. Use ''TFLK'' when you want to set the ON time and the OFF time separately.
  
-{{ :en-us_products:mp_studio:bf-tflk-sim-marked.svg?1022 |Figure 5. TFLK during its OFF time in simulation }}+{{ :en-us_products:mp_studio:bf-tflk-sim-marked.svg?1022 |Figure 6. TFLK during its OFF time in simulation }}
  
   * **① ''T5'' current value:** the time elapsed within one cycle.   * **① ''T5'' current value:** the time elapsed within one cycle.
Line 138: Line 163:
 | ''T'' | 655.35 s | 65.535 s | | ''T'' | 655.35 s | 65.535 s |
 | ''DT'' | About 497 days | About 49.7 days | | ''DT'' | About 497 days | About 49.7 days |
 +
 +===== BMOV and BSUM Copy Bit Range and Count ON Bits =====
 +
 +In every scan in which the condition is ON, ''BMOV'' copies N bits of IN, starting at bit SB, to OUT in order, starting at bit DB (V1.5.0 and later). The bits of OUT outside the copied range keep their values. In every scan in which the condition is ON, ''BSUM'' writes the number of bits that are 1 in IN to OUT.
 +
 +  * **IN:** the value to read bits from. Use a constant or a byte, word or double word address such as ''BD0'', ''D0'' or ''DD0''.
 +  * **SB:** the bit number in IN to start reading from (counting from 0).
 +  * **OUT:** the byte, word or double word address to write the bits to.
 +  * **DB:** the bit number in OUT to start writing at (counting from 0).
 +  * **N:** the number of bits to copy (1 or more).
 +
 +Bit numbers are counted within the size of the address in the cell. A byte has bits 0 to 7, a word has bits 0 to 15, and a double word or a constant has bits 0 to 31. SB+N must not exceed the number of bits of IN, and DB+N must not exceed that of OUT. IN and OUT can be different sizes and can even be the same address. If you write an address in SB, DB or N, the value is decided while the program runs ([[#out_of_range_and_ixerr|Out of Range and @IXERR]]).
 +
 +^ Example ^ Action ^
 +| ''BMOV D1 3 D5 0 4'' | Copies bits 3 to 6 of ''D1'' to bits 0 to 3 of ''D5''. The other bits of ''D5'' keep their values. |
 +| ''BSUM D10 D20'' | Writes the number of bits that are 1 in ''D10'' (0 to 16) to ''D20''. |
 +
 +The result of ''BSUM'' depends on the size of IN: 0 to 8 for a byte, 0 to 16 for a word, and 0 to 32 for a double word or a constant. To check whether the result is 0, use a comparison contact such as ''D20=0''.
 +
 +===== ROL and ROR Rotate Left and Right =====
 +
 +''ROL'' writes IN rotated N bits to the left to OUT, and ''ROR'' writes IN rotated N bits to the right (V1.5.0 and later). Unlike with ''SHL'' and ''SHR'', the bits shifted out of one end come back in at the other end. With ''ROL'', the top bit moves to bit 0, and with ''ROR'', bit 0 moves to the top bit.
 +
 +  * The rotation width is the size of OUT (8 bits for a byte, 16 bits for a word and 32 bits for a double word). If IN is smaller than OUT, the upper bits are filled with 0. If IN is larger, only the lower bits that fit in OUT are read.
 +  * If N is equal to or larger than the width, the value is rotated by the remainder of N divided by the width (4 bits when N is 20 for a word). If N is 0, IN is written to OUT unchanged.
 +  * To rotate a value in place, write the same address in IN and OUT.
 +  * The value is rotated in every scan in which the condition is ON. To rotate it only once when the condition turns ON, put a rising edge contact in front of the block.
 +
 +^ Example ^ Action ^
 +| ''ROL D10 1 D10'' | Rotates ''D10'' one bit to the left. Bit 15 moves to bit 0. |
 +| ''ROR D10 4 D11'' | Writes ''D10'' rotated four bits to the right to ''D11''. ''D10'' does not change. |
 +
 +Figure 7 shows a rung in which a rising edge contact after ''P5'' is followed by ''ROL D40 1 D40''. ''D40'' was 1, and ''P5'' was turned on and off three times, so ''D40'' changed to 2, 4 and then 8.
 +
 +{{ :en-us_products:mp_studio:bf-rotate-sim.png?991 |Figure 7. ROL in simulation after rotating the 1 in D40 three times to 8, with the value shown in binary in the Data Table }}
 +
 +===== LOADB, LOADBN, BOUT, BSET and BRESET Bit N Contacts and Outputs =====
 +
 +These five functions read or write a single bit, the one whose number is in N (V1.5.0 and later). If you write an address such as ''D0'' in N, you can change the bit number while the program runs.
 +
 +^ Function ^ What it does ^
 +| ''LOADB'' | A contact that is ON when bit N of IN is 1. |
 +| ''LOADBN'' | A contact that is ON when bit N of IN is 0. |
 +| ''BOUT'' | Writes the condition to bit N of OUT in every scan (0 when the condition is OFF). Works like an OUT coil. |
 +| ''BSET'' | Writes 1 to bit N of OUT when the condition is ON. The bit keeps its value when the condition is OFF. Works like a SET coil. |
 +| ''BRESET'' | Writes 0 to bit N of OUT when the condition is ON. Works like a RESET coil. |
 +
 +  * Use a constant or a byte, word or double word address in IN, and a byte, word or double word address in OUT. ''BOUT'', ''BSET'' and ''BRESET'' do not change the other bits of OUT.
 +  * N counts from 0 and must be smaller than the number of bits of the address in the cell (0 to 7 for a byte, 0 to 15 for a word and 0 to 31 for a double word). If IN is a constant, N is 0 to 31.
 +  * ''LOADB'' and ''LOADBN'' are blocks, but like contacts they can go anywhere in a rung. Connected in series with other contacts they work as AND, and in parallel as OR. The head of the block shows a contact symbol instead of the category abbreviation (┤ ├ for ''LOADB'' and ┤/├ for ''LOADBN'').
 +  * If N of ''BOUT'' is a constant, that bit (for example ''D10.3'' in ''BOUT D10 3'') is covered by the duplicate coil check, like a coil. In a project with the duplicate coil check turned on, using the same bit in another coil or ''BOUT'' as well shows "A double coil of the same name was used." when you compile. ''BOUT'' with an address in N, ''BSET'' and ''BRESET'' are not covered by the check.
 +
 +^ Example ^ Action ^
 +| ''LOADB D10 D0'' followed by coil ''P32'' | Turns on ''P32'' when the bit of ''D10'' numbered by the value of ''D0'' is 1. |
 +| ''BSET D20 5'' | Turns on bit 5 of ''D20'' when the condition is ON. |
 +
 +===== SSET and SOUT Step Control =====
 +
 +''SSET'' and ''SOUT'' use the one address in the GROUP cell as a step group and move a process forward in step number order (V1.5.0 and later). The value of that address is the current step number, and 0 means that no step is active. Because one address holds one value, only one step of a group is on at a time, and moving to another step turns off the previous step without a separate instruction.
 +
 +^ Function ^ What it does in a scan in which the condition is ON ^
 +| ''SSET'' | Writes STEP to GROUP only when the value of GROUP is one less than STEP (it moves to the next step only from the step just before it). If STEP is 0, it writes 0 to GROUP. |
 +| ''SOUT'' | Writes STEP to GROUP regardless of the current step. If the conditions of several ''SOUT'' functions are ON in the same scan, the value from the later rung remains. |
 +
 +  * In GROUP, use a byte, word or double word address such as ''BD100'', ''D100'' or ''DD100'', or a ''##name'' or ''###name'' user variable. In STEP, use a constant or an address, up to the largest number that GROUP can hold (255 for a byte, 65535 for a word and 4294967295 for a double word).
 +  * GROUP keeps its value after the condition turns OFF. Write the work for each step as a coil after a comparison contact such as ''D100=2''.
 +  * If GROUP is an address outside the retentive range, the process starts at step 0 after power-on or a download.
 +  * Several ''SSET'' and ''SOUT'' functions in the same group are not covered by the duplicate coil check.
 +
 +> **Steps can advance more than once in a scan**
 +> If the conditions of ''SSET D100 1'' and ''SSET D100 2'' are ON in the same scan, the step moves from 0 to 1 and then to 2 within that scan, in rung order. To advance only one step per scan, place the ''SSET'' functions in descending order of step number, with the highest step number in the earliest rung.
  
 ===== Inputs That Do Not Compile ===== ===== Inputs That Do Not Compile =====
Line 146: Line 242:
 | 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'' | | 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 | | 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'' | +| 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, in V1.4.0, 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'' |+| IN and DIR of ''BSFT'' | A real number such as ''1.5'', a real number address such as ''R0'', a comparison, or, in V1.4.0, also a constant other than 0 or 1 and a byte or word address |
 | 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'') | | 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'') | | TIMER of ''TFLK'' | A timer narrower than the value in ON (for example ''T1'' when ON is ''DD0'' or ''70000'') |
 +| SB, DB and N of ''BMOV'' | A negative value, an N less than 1, or an SB+N or DB+N that exceeds the number of bits of IN or OUT (for example ''BMOV D1 13 D5 0 4'') |
 +| N of ''LOADB'', ''LOADBN'', ''BOUT'', ''BSET'' and ''BRESET'' | A negative value, or a bit number equal to or larger than the number of bits of the address in the cell (for example ''LOADB BM25 8'' or ''BOUT D10 16'') |
 +| N of ''ROL'' and ''ROR'' | A negative value |
 +| STEP of ''SSET'' and ''SOUT'' | A negative value, or a number that does not fit in GROUP (for example ''SSET BD100 256'') |
 +| OUT and GROUP of the functions added in V1.5.0 | A constant |
 +| All cells of the functions added in V1.5.0 | A bit address such as ''M0'', a real number address such as ''R0'', a real number such as ''1.5'', or a comparison |
  
-The cells of the five functions cannot take an [[:en-us_products:mp_studio:indexed_address|indexed address]] (''D100[D0]'').+The cells of the bit control functions cannot take an [[:en-us_products:mp_studio:indexed_address|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. 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.
  
-{{ :en-us_products:mp_studio:bf-red-reason.png?1000 |Figure 6. The OFF cell shown in red because the sum of ON and OFF does not fit in timer T6, and the reason in the Inspector }}+{{ :en-us_products:mp_studio:bf-red-reason.png?1000 |Figure 8. The OFF cell shown in red because the sum of ON and OFF does not fit in timer T6, and the reason in the Inspector }} 
 + 
 +If you enter ''LOADB BM25 8'', the N cell turns red and "Bit number 8 of LOADB is outside bits 0 to 7 of BM25 (8 bits), so the program does not compile. Enter a number from 0 to 7." is shown. 
 + 
 +{{ :en-us_products:mp_studio:bf-bitno-red.png?1000 |Figure 9. The N cell of LOADB shown in red because the bit number is outside the bits of BM25, and the reason in the Inspector }}
  
 ===== Out of Range and @IXERR ===== ===== 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 [[:en-us_products:mp_studio:memory_symbols#data_memory|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.+If you write an address such as ''D10'' in N of ''BSFT'', ''BRST'' and ''BSETN'', or in the bit number, count or step number of the functions added in V1.5.0, the value is decided while the program runs. If it becomes one of the values below when the block runs, the PLC turns on the system bit ''@IXERR'' and handles the block as shown in the table.
  
-  * 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). +^ Function ^ Value treated as out of range ^ What happens ^ 
-  * The system bit ''@IXERR'' turns on. +| ''BSFT'', ''BRST'', ''BSETN'' | N is 0 or less, or the N bits from BIT run past the end of their area (for ''M'' and ''D'', the size set in [[:en-us_products:mp_studio:memory_symbols#data_memory|Data Memory]]; for ''P'', the end of the whole P area, ''P55'' or ''P127'' depending on the model, not the last real I/O terminal) | Skips the block and writes no bits. | 
-  * 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 ''@IXERR'' does not turn on.+| ''BMOV'' | N is 0, or SB+N or DB+N exceeds the number of bits of IN or OUT | Copies no bits. | 
 +| ''LOADB'', ''LOADBN'' | N is equal to or larger than the number of bits of IN | The contact is false. | 
 +| ''BOUT'', ''BSET'', ''BRESET'' | N is equal to or larger than the number of bits of OUT | Does not write the bit. | 
 +| ''SSET'', ''SOUT'' | STEP does not fit in GROUP | Does not change GROUP. |
  
-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.+  * No bit is written to the wrong place, so no other memory is overwritten. Except for ''LOADB'' and ''LOADBN'', 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). 
 +  * Except for ''BOUT'', the range is not checked while the condition is OFF (for ''BSFT'', in any scan other than the one in which the condition turns ON), so ''@IXERR'' does not turn on. ''BOUT'' writes its bit in every scan even while the condition is OFF, so it checks the range then too. 
 +  * ''BSUM'', ''ROL'' and ''ROR'' cannot go out of range.
  
-''@IXERR'' is the same bit that turns on when an [[:en-us_products:mp_studio:indexed_address#out_of_range_and_ixerr|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.+If you write addresses in ON and OFF of ''TFLK'' and one cycle exceeds the maximum in the table in [[#tflk_flicker_timer|TFLK Flicker Timer]] when the block runs, ''@IXERR'' turns on, and the output stays off with the current value held at 0.
  
-{{ :en-us_products:mp_studio:bf-ixerr-notice.png?591 |Figure 7. The notice shown in a program that has @IXERR in the Data Table }}+''@IXERR'' is the same bit that turns on when an [[:en-us_products:mp_studio:indexed_address#out_of_range_and_ixerr|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. During monitoring or simulation, a notice appears when ''@IXERR'' turns on ("A value was out of range (such as an index, bit number, or count), so @IXERR turned ON and the instruction was skipped."). In V1.5.0 and later, the notice appears even if ''@IXERR'' is not on the ladder screen or in the Data Table.
  
-{{ :en-us_products:mp_studio:bf-ixerr-sim-marked.svg?793 |Figure 8. @IXERR turned on in simulation because the count of BRST went out of range }}+{{ :en-us_products:mp_studio:bf-ixerr-notice.png?820 |Figure 10. The notice shown in a program that has no @IXERR on the ladder screen or in the Data Table }} 
 + 
 +{{ :en-us_products:mp_studio:bf-ixerr-sim-marked.svg?793 |Figure 11. @IXERR turned on in simulation because the count of BRST went out of range }}
  
   * **① N cell ''D10'':** the value is 0, so ''BRST M300 D10'' was skipped.   * **① N cell ''D10'':** the value is 0, so ''BRST M300 D10'' was skipped.
Line 178: Line 291:
 ===== Monitoring and Simulation ===== ===== Monitoring and Simulation =====
  
-The five functions work the same in simulation as on the PLC.+All bit control functions work the same in simulation as on the PLC.
  
-  * When the condition is ON, the blocks of ''FF'', ''BSFT'', ''BRST'' and ''BSETN'' are 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.+  * When the condition is ON, the blocks of all functions except ''TFLK'', ''LOADB'' and ''LOADBN'' are 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 [[:en-us_products:mp_studio:monitoring#data_table|Data Table]].   * The value in the BIT cell is the value of the start bit alone. To see the whole range, add the addresses to the [[:en-us_products:mp_studio:monitoring#data_table|Data Table]].
   * The TIMER cell of ''TFLK'' shows 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 a ''TON'' is counting.   * The TIMER cell of ''TFLK'' shows 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 a ''TON'' is counting.
 +  * Like a contact, ''LOADB'' and ''LOADBN'' show the block and its right side in the power-flow color only when the condition on the left is ON and the bit check is true.
 +  * For ''SSET'' and ''SOUT'', when the value of GROUP equals the STEP of the block, "▶ Now N" appears in the head of the block and the head border changes to the power-flow color. If two or more blocks have the same STEP, all of them show it, and when the value is 0, "▶ Now 0" appears on the block whose STEP is 0.
   * To see a single moment of the blink, use **Pause** and **Step one scan** on the [[:en-us_products:mp_studio:simulation#simulation_bar|simulation bar]].   * To see a single moment of the blink, use **Pause** and **Step one scan** on the [[:en-us_products:mp_studio:simulation#simulation_bar|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 (''M'' and ''D'' areas).+  * 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 (''M'' and ''D'' areas). For the functions added in V1.5.0, the addresses written in the cells are painted, regardless of bit ranges.
  
 ===== Examples ===== ===== Examples =====
  
-You can write the three examples in order in a new ''MPA-8A8R(T)'' project (default data memory) and check them in simulation.+You can write Examples 1 to 4 in order in a new ''MPA-8A8R(T)'' project (default data memory) and check them in simulation. Example 5 uses ''P0'' to ''P4'' and ''P32'' to ''P34'' again, so create a separate new ''MPA-8A8R(T)'' project for it.
  
 ==== Example 1. Toggling a Lamp with a Single Push Button ==== ==== Example 1. Toggling a Lamp with a Single Push Button ====
Line 200: Line 315:
 | 0 | ''P0'' | ''FF P32'' | Toggles ''P32'' each time ''P0'' is pressed. | | 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.+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 4), and it does not change while ''P0'' stays on.
  
 ==== Example 2. Tracking Rejects on a Conveyor ==== ==== Example 2. Tracking Rejects on a Conveyor ====
Line 214: Line 329:
 | 3 | ''P3'' | ''BRST M200 8'' | Clears all tracking records. | | 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.+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 5 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 ==== ==== Example 3. Blinking a Beacon ====
Line 227: Line 342:
 | 5 | ''T5'' | Coil ''P35'' | Gives the same blink on ''P35''. | | 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.+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 6). When you turn ''P4'' off, they turn off at once and ''T5'' becomes 0. 
 + 
 +==== Example 4. Counting Rejects on a Conveyor and Checking a Position ==== 
 + 
 +In this example, the tracking records shifted into ''M200'' to ''M207'' in Example 2 are used to count the rejects on the conveyor and to check whether there is a reject at a given position. The byte address ''BM25'' holds the eight bits ''M200'' to ''M207''. 
 + 
 +  - In **Settings → Symbol**, register NG_COUNT for ''D30'', CHECK_POS for ''D31'' and NG_LAMP for ''P36''. 
 +  - Write the rungs below after the rungs of Example 3. 
 + 
 +^ Rung ^ Input ^ Function or coil ^ What it does ^ 
 +| 6 | ''@ON'' | ''BSUM BM25 D30'' | Writes the number of bits that are on in ''M200'' to ''M207'' (the number of rejects on the conveyor) to ''D30''. | 
 +| 7 | ''@ON'' | ''LOADB BM25 D31'' followed by coil ''P36'' | Turns on ''P36'' if there is a reject at the position that ''D31'' points to (''M200'' for 0, ''M207'' for 7). | 
 + 
 +During simulation, turn ''P1'' on and off eight times, with ''P2'' on only for the first and third times. Those two rejects reach ''M207'' and ''M205'', and ''D30'' becomes 2. When you add ''D30'' and ''D31'' to the Data Table and write 5 to ''D31'', ''P36'' turns on (Figure 12), and when you write 4, it turns off. If you write 8 to ''D31'', the bit number is outside bits 0 to 7 of ''BM25'', so ''P36'' turns off, ''@IXERR'' turns on and the notice appears (Figure 10). ''@IXERR'' stays on even after you change ''D31'' back. 
 + 
 +{{ :en-us_products:mp_studio:bf-count-sim-marked.svg?793 |Figure 12. BSUM counting 2 rejects and LOADB turning on P36 for the reject at position D31 in simulation }} 
 + 
 +  * **① OUT of ''BSUM'':** ''D30'' shows 2, the number of bits that are on. 
 +  * **② ''LOADB'' block head:** shows the contact symbol. 
 +  * **③ N cell ''D31'':** shows the value 5. ''M205'' is on, so the contact is ON. 
 +  * **④ Coil ''P36'':** is on. 
 + 
 +==== Example 5. Running Three Processes in Order with Steps ==== 
 + 
 +In this example, the start signal ''P0'' starts process 1, each process moves on to the next one when its end signal comes in, and the sequence returns to process 1 when process 3 ends. The value of ''D100'' is the current step number. 
 + 
 +  - Create a new ''MPA-8A8R(T)'' project, and in **Settings → Symbol**, register START for ''P0'', END1 for ''P1'', END2 for ''P2'', END3 for ''P3'', STOP for ''P4'', STEP_NO for ''D100'', PROC1 for ''P32'', PROC2 for ''P33'' and PROC3 for ''P34''. 
 +  - Write the rungs below. 
 + 
 +^ Rung ^ Input ^ Function or coil ^ What it does ^ 
 +| 0 | ''P0'' | ''SSET D100 1'' | Moves from step 0 to step 1 on start. | 
 +| 1 | ''P1'' | ''SSET D100 2'' | Moves from step 1 to step 2 when process 1 ends. | 
 +| 2 | ''P2'' | ''SSET D100 3'' | Moves from step 2 to step 3 when process 2 ends. | 
 +| 3 | ''P3'' | ''SOUT D100 1'' | Returns to step 1 when process 3 ends, regardless of the current step. | 
 +| 4 | ''P4'' | ''SSET D100 0'' | Stops (step 0). | 
 +| 5 | ''D100=1'' | Coil ''P32'' | Turns on process 1 during step 1. | 
 +| 6 | ''D100=2'' | Coil ''P33'' | Turns on process 2 during step 2. | 
 +| 7 | ''D100=3'' | Coil ''P34'' | Turns on process 3 during step 3. | 
 + 
 +During simulation, turning ''P0'' on and off makes ''D100'' 1, and ''P32'' turns on. Then turning ''P1'' on and off moves to step 2 (''P33''), and turning ''P2'' on and off moves to step 3 (''P34''). An end signal does not advance the step unless the current step is the one just before, so turning ''P2'' on during step 1, for example, does nothing. Turning ''P3'' on and off returns to step 1, and turning ''P4'' on and off goes to step 0 and turns all the outputs off. 
 + 
 +{{ :en-us_products:mp_studio:bf-step-sim-marked.svg?1000 |Figure 13. Simulation after moving to step 2, with the current step shown on the SSET D100 2 block }} 
 + 
 +  * **① "▶ Now 2":** appears in the head of the block of the current step, and the head border changes to the power-flow color. 
 +  * **② GROUP cell ''D100'':** shows the current step number, 2. 
 +  * **③ Comparison contact ''D100=2'':** ON because the step is 2. 
 +  * **④ Coil ''P33'':** process 2 is on.
  
 ===== Things to Check ===== ===== Things to Check =====
Line 233: Line 394:
   * The bits that ''FF'' and ''BSFT'' use to remember the previous condition are set up automatically and do not appear in the symbol table, the Data Table or Used Data.   * The bits that ''FF'' and ''BSFT'' use 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** +> **Cannot be opened or shows red cells in earlier versions** 
-> A ''.mpx'' project that uses even one bit control function cannot be opened in V1.3.0 and earlier versions of the app.+> A ''.mpx'' project that uses even one bit control function cannot be opened in V1.3.0 and earlier versions of the app. A project that uses even one of the eleven functions added in V1.5.0 cannot be opened in V1.4.0 and earlier. Some values in the cells of ''BSFT'', ''BRST'' and ''BSETN'' are accepted only in V1.5.0 and later: a double word address such as ''DD0'' in N, and an address or an integer other than 0 or 1 in IN and DIR of ''BSFT''. A project that uses these values but none of the eleven functions opens in V1.4.0 with those cells shown in red.
  
 ===== Related Pages ===== ===== Related Pages =====
en-us_products/mp_studio/bit_control.1794483454.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki