User's Manual

PMAC User Manual
Closing the Servo Loop 113
On entry, the X register contains a 48-bit integer representing actual position (APOS) in units of
1/(Ix08*32) counts
On entry, the A accumulator contains a 48-bit integer representing desired velocity (DVEL) in units
of 1/(Ix08*32) counts/servo cycle.
On entry, the Y1 register contains the value of Ix08.On entry, the R1 register contains the address of
the servo status register for the motor whose loop is to be closed ($003D for Motor 1, $0079 for
Motor 2, etc.). This information can be used when servoing multiple motors to distinguish motor-
specific registers.
On exit, the upper 18 bits of A1 should contain the control effort for the motor. If the motor is not
commutated by PMAC (Ix01=0), this value will be loaded directly into the DAC register. If the
motor is commutated by PMAC, this value will be used by the phasing routines to create two DAC
outputs.
The user-written filter algorithm must end with a JMP instruction to location P:$0023.
Restrictions
The following restrictions must be observed in the user-written code:
Only one level of stack use is allowed.
Do not write to 56000 address registers R2, R3, R6, or R7; modifier registers M2, M3, M6, or M7; or
offset registers N2, N3, N6, or N7. Other R, M, and N registers may be written to, but must be
restored before exiting the user-written code.
Apart from the A, B, X, and Y registers, all other 56000 registers must be restored before exiting the
user-written code.
Alternative Uses for User-Written Servo
This calculation does not have to be used to close the servo loop for a motor or motors. It can be thought
of simply as a very fast software routine that executes every servo cycle without fail. As such, it can be
used as a super-fast PLC program (better by far in speed than PLC 0).
The most common use for this user-written non-servo is for the very fast setting and clearing of many
outputs based on position (when more is needed than just the hardware position-compare output). Using
this routine for such a function has several advantages over a PLC program. First, it is written in
assembly language, so there are no compilation inefficiencies or interpretation delays.
Second, it can use simple fixed-point arithmetic, rather than the floating-point arithmetic that the PLC
(and motion) programs use. Third, it is guaranteed to run at a fixed rate; even PLC 0 can be delayed by
motion programs.
To implement such a function, activate an extra motor (Ix00=1) and tell it to use the user-written servo
(Ix59=1). The motor must be in a closed-loop enabled state for the algorithm to execute; this will happen
automatically if Ix80=1, or it can be brought into this state with a J command. Do not worry about where
to pick up and leave off the servo information, but be careful not to disturb anything else.
Simple User-Written Servo Example
; ENTER: B=demand angle (integer),
; X=actual angle (integer).
;; EXIT: upper 18 bits of A1=DAC (integer),
;
;
; This servo routine executes a low pass filter of
; the form: uf(k)=a1*error(k)+a2*uf(k-1)
;
; Prior to enabling this routine a1 & a2 should be
; initialized in L:COEF_A cells. Also, Sampling