Mitsubishi Electronics FX2C Home Theater Server User Manual


 
FX Series Programmable Controlers Applied Instructions 5
5-13
5.1.7 FOR, NEXT
(FNC 08, 09)
Operation:
The FOR and NEXT instructions allow the
specification of an area of pro
g
ram, i.e. the pro
g
ram
enclosed b
y
the instructions, which is to be repeated
S number of times.
Points to note:
a) The FOR instruction operates in a 16 bit mode hence, the value of the operand S ma
y
be
within the ran
g
e of 1 to 32,767. If a number between the ran
g
e -32,768 and 0 (zero) is
specified it is automaticall
y
replaced b
y
the value 1, i.e. the FOR-NEXT loop would execute
once.
b) The NEXT instruction has NO operand.
c) The FOR-NEXT instructions must be pro
g
rammed as a pair e.
g
. for ever
y
FOR instruction
there
MUST
be an associated NEXT instruction. The same applies to the NEXT
instructions, there
MUST
be an associated FOR instruction. The FOR-NEXT instructions
must also be pro
g
rammed in the correct order. This means that pro
g
rammin
g
a loop as a
NEXT-FOR (the paired NEXT instruction proceeds the associated FOR instruction) is
NOT
allowed.
Insertin
g
an FEND instruction between the FOR-NEXT instructions, i.e. FOR-FEND- NEXT,
is NOT allowed. This would have the same effect as pro
g
rammin
g
a FOR without a NEXT
instruction, followed b
y
the FEND instruction and a loop with a NEXT and no associated
FOR instruction.
d) A FOR-NEXT loop operates for its set number of times
before
the main pro
g
ram is allowed
to finish the current pro
g
ram scan.
e) When usin
g
FOR-NEXT loops care should be taken not the exceed the PLC’s watchdo
g
timer settin
g
. The use of the WDT instruction and/or increasin
g
the watchdo
g
timer value is
recommended.
Mnemonic Function
Operands
Program steps
S
FOR
FNC 08
(Start of a
FOR-NEXT
loop)
Identifies the start
position and the
number of
repeats for the
loop
K, H,
KnX, KnY, KnM, KnS,
T, C, D, V, Z
FOR:
3 step
NEXT
FNC 09
(End of a
FOR-NEXT
loop)
Identifies the end
position for the
loop
N/A
Note:
The FOR-NEXT loop can be nested for 5 lev-
els,
i.e. 5 FOR-NEXT loops are pro
g
rammed within
each other.
NEXT:
1 step
FOR K1X0
NEXT
[ S ]