13.07.2015 Views

[Instruction] Contents

[Instruction] Contents

[Instruction] Contents

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advanced Function <strong>Instruction</strong>FUN 70FORLadder symbolFORFUN 70FOR70.FORNN : Number of times of loop executionRangeWX WY WM WS TMR CTR HR IR OR SR ROR DR KOperandWX0∣WX240WY0∣WY240WM0∣WM1896WS0∣WS984T0∣T255C0∣C255R0∣R3839R3840∣R3903R3904∣R3967R3968∣R4167R5000∣R8071D0∣D4095N ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○1∣16383• This instruction has no input control, is connected directly to the power line, and cannot be in series withany conditions.• The programs within the FOR and NEXT instructions form a program loop (the start of the loop program isthe next instruction after FOR, and the last is the instruction before NEXT). When PLC executes the FORinstruction, it first records the N value after that instruction (loop execution number), then for N timessuccessively execution from start to last of the programs in the loop. Then it jumps out of the loop, andcontinues executes the instruction immediately after the NEXT instruction.• The loop can have a nested structure, i.e. the loop includes other loops, like an onion. 1 loop is called alevel, and there can be a maximum of 5 levels. The FOR and NEXT instructions must be used in pairs. Thefirst FOR instruction and the last NEXT instruction are the outermost (first) level of a nested loop. Thesecond FOR instruction and the second last NEXT instruction are the second level, the last FOR instructionand the first NEXT instruction form the loop's innermost level.70FOR 270FOR 370FOR 4717171NEXTNEXTNEXT12 3˙In the example in the diagram at left, loop will beexecuted 4 ×3 ×2 = 24 times, loop will beexecuted 3 ×2 = 6 times, and loop will beexecuted 2 times.˙If there is a FOR instruction and no corresponding NEXTinstruction, or the FOR and NEXT instructions in thenested loop have not been used in pairs, or the sequenceof FOR and NEXT has been misplaced, then a syntaxerror will be generated and this program may not beexecuted.˙In the loop, the JMP instruction may be used to jump outof the loop. However, care must be taken that once theloop has been entered (and executed to the FORinstruction), no matter how the program flow jumps, itmust be able to reach the NEXT instruction beforereaching the END instruction or the bottom of theprogram. Otherwise FBs-PLC will halt the operation andshow an error message.˙The effective range of N is 1~16383 times. Beyond thisrange FBs-PLC will treat it as 1. Care should be taken , ifthe amount of N is too large and the loop program is toobig, a WDT may occur.7-53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!