Mitsubishi Electric R16MTCPU Programming Manual page 201

Hide thumbs Also See for R16MTCPU:
Table of Contents

Advertisement

Program example
■Program which repeats to substitute #0 data to Motion register (#) that is indirectly specified
with the device No. "#0+100" when #0 is between 1 and 10 (Incremental value is 1.)
When the program is ended, 1 to 10 is substituted to #101 to #110.
FOR #0 = K1 TO K10
#(#0 + K100) = #0
NEXT
When the incremental value is positive number, the device value specified with (D) is larger than the final value specified with
(S2) after FOR to NEXT repeat is completed. In the above example, #0 set in (D) is 11.
■Program which repeats to subtract #0 from #100 when #0 is between 100 to 10 (Incremental
value is -10.).
FOR #0 = K100 TO K10 STEP K-10
#100 = #100 - #0
NEXT
When the incremental value is negative number, the device value specified with (D) is smaller than the final value specified
with (S2) after FOR to NEXT repeat is completed. In the above example, #0 set in (D) is 0.
Since the incremental value continues to be added to the loop control counter specified with (D) until it
reaches the final value, set the data type which the value can handle. When the data range exceeds the loop
control counter range, an unintended repeat operation may occur as the value is considered to be wrong. In
the following program, the data type of loop control counter #0 is 16-bit integer type, and the data range is
from -32768 to 32767.
FOR #0 = K0 TO K30000 STEP K10000
NEXT
When this program is executed, #0 changes as follows and exceeds the 16-bit integer type data range in the
middle. Therefore, the program is not ended with four executions of the loop.
• First execution of the loop: #0 is 0.
• Second execution of the loop: #0 is 10000.
• Third execution of the loop: #0 is 20000.
• Forth execution of the loop: #0 is 30000.
• Fifth execution of the loop: #0 is -25536. (#0 is 40000, but overflow will occur as it is outside the data range.)
• Sixth execution of the loop: #0 is -15536.
#1 = #1 + K1
4 OPERATION CONTROL PROGRAMS
4.14 Program Control
4
199

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

R64mtcpuMelsec iq-r seriesR32mtcpu

Table of Contents