Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(EOD).Mechatronics.pdf
Скачиваний:
81
Добавлен:
23.08.2013
Размер:
5.07 Mб
Скачать

page 433

SQO

File B3:0

Mask 003F

Destination O:000

Control R6:0

Length 4

Position 0

B3:0

0

0

0

0

0

0

0

0

0

0

0

0

1

0

0

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

0

0

0

0

0

0

0

0

0

0

0

1

0

1

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

0

0

0

0

0

0

0

0

0

1

0

0

0

0

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

B3:4

0

0

0

0

0

0

0

0

0

0

0

1

0

0

0

1

 

 

 

 

 

 

 

 

 

 

 

green - EW

yellow - EW

red - EW

green - NS

yellow - NS

red - NS

24.2.8 Program Control Structures

• These change the flow of execution of the ladder logic.

24.2.8.1 - Branching and Looping

These functions allow control found in languages like Fortran IF-THEN is like MCR (Master Control Reset)

GOTO is like JMP (Jump) SUBROUTINES is like Program Files

MCR blocks have been used earlier, but they are worth mentioning again.

page 434

MCR

A

MCR

If A is true then the MCR will cause the ladder in between to be executed. If A is false it is skipped.

MCR

• Block of ladder logic can be bypassed using a jump statment.

JMP

A B

JMP 01

If A and B are true, the program will jump to LBL:01 to be executed. If A or B is false it is skipped.

LBL 01

• Subroutines allow reusable programs to be written and called as needed. They are different from jump statements because they are not part of the main program (they are other program files), and arguments can be passed and returned.

page 435

SUBROUTINES/PROGRAM FILES

 

 

 

 

A

JSR (Jump subroutine)

program file 2

 

 

Program File 3

 

 

 

 

 

 

 

Input par N7:0

 

 

 

 

 

 

 

 

Input par 123

 

 

 

 

Return par N7:1

 

 

 

 

 

A separate ladder logic program is stored in program file 3. This feature allows the user to create their own ‘functions’. In this case if A is true, then the program below will be executed and then when done the ladder scan will continue after the subroutine instruction. The number of data values passed and returned is variable.

SBR (subroutine arguments)

Input par N10:0

If B is true the subroutine will return and the values listed will be returned to the return par. For this example the value that is in

N10:1 will eventually end up in N7:1

program file 3

B

RET

 

Return par N10:1

 

 

 

• For next loops can also be done to repeat blocks of ladder logic inside a single scan. Care must be used for this instruction so that the ladder logic does not get caught in an infinite, or long loop - if this happens the PLC will experience a fault and halt.

page 436

A

FOR

label number 0 index N7:0 initial value 0 terminal value 9 step size 1

ADD

Source A 1

Source B N7:1

Dest N7:1

NXT

label number 0

Note: if A is true then the loop will repeat 10 times, and the value of N7:1 will be incresed by 10. If A is not true, then the ADD function will only be executed once and N7:1 will increase in value by 1.

• Ladder logic programs always have an end statement, but it is often taken for granted and ignored. Most modern software automatically inserts this. Some PLCs will experience faults if this is not present.

A B C

END

When the end (or End Of File) is encountered the PLC will stop scanning the ladder, and start updating the outputs. This will not be true if it is a subroutine or a step in an SFC.

There is also a temporary end (TND) that for a single ladder scan will skip the remaining portion of a program.

A one shot contact can be used to turn on a ladder run for a single scan. When the run has a pos-

Соседние файлы в предмете Электротехника