User's Manual

PMAC User Manual
238 Writing a PLC Program
Execution of Compiled PLCs
Of the 32 compiled PLC programs (PLCC 0 to PLCC 31) only PLCC 0 operates in the foreground,
triggered by the real-time interrupt (RTI). PLCCs 1 to 31 operate as background tasks.
At each real-time interrupt, PMAC checks to see whether several user tasks need to be done. The real-
time interrupt occurs every (I8+1) servo cycles. PMAC checks the tasks in the following order:
Motion program move planning: PMAC checks to see in each coordinate system whether it is time to
calculate the next move in the program.
Interpreted PLC 0: PMAC checks to see if I5=1 or 3 and if PLC 0 is enabled. If so, it executes one
scan of PLC 0.
Compiled PLC 0: PMAC checks to see if I5=1 or 3 and if PLCC 0 is enabled. If so, it executes one
scan of PLCC 0.
It is very important that the scan execution time of PLCC 0 and PLC 0 be kept less than one real-time
interrupt period. Otherwise, their repeated execution will starve the background for time, and probably
trip the watchdog timer.
In background, PMAC executes one scan of a single background interpreted PLC program uninterrupted by
any other background task (although higher-priority tasks will interrupt). In between each scan of each
individual background interpreted PLC program, PMAC will execute one scan of all active background
compiled PLCs. This means that the background compiled PLCs execute at a higher scan rate than the
background interpreted PLCs. For example, if there are seven active background interpreted PLCs, each
background compiled PLC will execute seven scans for each scan of a background interpreted PLC.
Preparing Compiled PLCs
Preparation of compiled PLCs is a multi-step process. The basic steps are as follows:
Write and debug the PLC programs in interpreted form.
Change all references to PLCs to be compiled from PLC to PLCC.
For integer arithmetic, define L-variables and substitute these for the old variable names in the
programs.
Combine all of the PLC programs to be compiled into one file on the PC, substituting true PMAC
code for the macro names.
With the Compile on Download feature of the Executive program active, download the files to
PMAC using the Download function.
Activate the compiled PLCs. If operation is not correct, return to step 1 or 2.
Each of the above steps is explained in detail below.
Preliminary Debugging
It is advisable to do most of the debugging of PLC program code in interpreted form. The ease of
repeated editing, downloading, and execution makes multiple trials fast and easy, using the PMAC
Executive program and the PMAC. Once debugging is substantially complete in interpreted form, it is
quite easy to change to compiled form.
Changing PLC References
All references to the PLC programs that are to be compiled must be changed from PLC to PLCC. Each
PLC program that is to be compiled must be headed with an OPEN PLCC n command. This is the
signal to the compiler that what follows (until the CLOSE command) is to be compiled. Any ENABLE
PLC and DISABLE PLC commands that refer to PLC programs to be compiled must be changed to
ENABLE PLCC and DISABLE PLCC commands, whether or not these commands themselves are in
PLC programs to be compiled.