User`s manual

6.0 - PLC Programs
Page - 61
If you need more timers, probably the best technique to use is in memory address X:0. This 24-bit register counts up once
per servo cycle. We will store a starting value for this, then each scan subtract the starting value from the current value and
compare the difference to the amount of time we wish to wait.
Example: M0->X:$0,24 ; Servo counter register
M85->X:$07F0,24 ; Free 24-bit register
M86->X:$07F1,24 ; Free 24-bit register
OPEN PLC 3 CLEAR
M1=0 ; Reset Output1 before start
M85=M0 ; Initialize timer
M86=0
WHILE(M86<1000) ; Time elapsed less than specified time?
M86=M0-M85
M86=M86*I10/8388608 ; Time elapsed so far in milliseconds
ENDWHILE
M1=1 ; Set Output 1 after time elapsed
DISABLEPLC3 ; disables PLC3 execution (needed in this example)
CLOSE
Even if the servo cycle counter rollovers (start from zero again after the counter is saturated), by subtracting into another 24-
bit register, we handle rollover gracefully.
Rollover example: M0 = 1000
M85 = 16777000
M86 = 1216
Bit 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
M0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 0
M85 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0
M86 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0
6.8 - Compiled PLC Programs
PLCCs are compiled by PEWIN in the downloading process. Only the compiled code gets downloaded to PMAC.
Therefore it is suggested to save the ASCII source code in the host computer separately since it cannot be retrieved from
PMAC. Compiled PLCs are firmware dependent and so they must be recompiled when the firmware is changed in PMAC.
If more than one PLCC is programmed, all the PLCCs code must belong to the same ASCII text file. PEWIN will compile
all the PLCC code present on the file and place it in the appropriate buffer in PMAC. If a single PLCC code is downloaded,
all the rest PLCCs that might have been present in memory will be erased, remaining only the last compiled code.
The multiple-file download feature of the PEWIN File menu allows having the PLCC codes in different files. They will be
combined by PEWIN in the downloading process.
The use of L-variables in a PLC program statement is the sign to the compiler that the statement is to be executed using
integer operations instead of floating-point operations.
To implement integer arithmetic in a compiled PLC, the user must both define any L-variables to be used and substitute
them in the programs for the variables that were used in the interpreted form (usually M-variables). The compiler will
interpret statements containing only L-variables (properly defined) and integer constants as operations to be executed using
integer arithmetic in compiled PLCs. Preparation of compiled PLCs is a multi-step process, the basic steps are as follows:
1) Write and debug the PLC programs in interpreted form (simple PLCs programs).
2) Change all references to PLCs to be compiled from PLC to PLCC.
3) For integer arithmetic, define L-variables and substitute these for the old variable names in the programs.
4) Combine all of the PLC programs to be compiled into one file on the PC.
5) Make sure the “Support MACRO’s/PLCCs” option is checked before downloading.
6) Activate the compiled PLCs. If operation is not correct, return to step 1 or 2.
7) PLCCs could be deleted using the DELETE PLCCn command (replace n by the appropriate number).
Carry-out bit