5.4.3 How to organize the program
Basic elements of a control program
CPU PR - X control program consists of the following program types:
main program
The main body of the program is where you place the control
application instructions.The instructions in the main program are executed in
sequence, and each scan cycle is executed once.
subroutine
Subroutine stored in a separate block, when the main program,
interrupt routine or another subroutine call subroutine, the subroutine will be
executed.
interrupt routine
The interrupt routine is stored in a separate block, which is
executed only when the interrupt event occurs.
How to terminate POU
The compiler uses unconditional END, MEND, RET, or RETI to terminate each POU.If
you put the unconditional END, MEND, RET, or RETI into the program, the compiler
will return an error message.
subroutine
Subroutine is particularly useful when you want to perform a function repeatedly ; You just need to write a logic in the subroutine , then you can call the subroutine
every time when you need it in the main program.
Advantages:
1. Your program size becomes smaller.
2.Because you remove the code from the main program, the scan time will be
reduced.
Subroutine can be scanned only when it is called.The main program is constantly
scanned.
3.Subroutine is easy to be moved ; You can select a function and copy it to another
program.You don't need or need a little repetitive operation.
Attention: V memory usage limits the portability of the subroutine.Because a
program's V memory address assignment may be in conflict with the assignment in
another program.Instead, the subroutine which only use local variables is easy to
56
Made with FlippingBook - Online magazine maker