Electronica - Servo Control of A Dc-Brush Motor An532
Electronica - Servo Control of A Dc-Brush Motor An532
Electronica - Servo Control of A Dc-Brush Motor An532
AN532
Servo Control of a DC-Brush Motor
Author: Tim Bucella, Teknic Inc.
INTRODUCTION
The PIC17C42 microcontroller is an excellent choice for cost-effective servo control in embedded applications. Due to its Harvard architecture and RISC-like features, the PIC17C42 offers excellent computation speed needed for real time closed loop servo control. This application note examines the use of the PIC17C42 as a DC brush motor servo controller. It is shown that a PID (Proportional, Integral, Differential) control calculation can be performed in less than 200 S (@16 MHz) allowing control loop sample times in the 2 KHz range. Encoder rates up to 3 MHz are easily handled by the PIC17C42's high speed peripherals. Further, the on-chip peripherals of the PIC17C42 allow an absolute minimum cost system to be constructed. Closed-loop servo motor control is usually handled by 16-bit, high-end microcontrollers and external logic. In an attempt to increase performance many applications are upgrading to DSPs. However, the very high performance of the PIC17C42 makes it possible to implement these servo control applications at a significant reduction in overall system cost. The servo system uses a PIC17C42 microcontroller, a programmable logic device (PLD), and a single-chip H-bridge driver. Such a system might be used as a positioning controller in a printer, plotter, or scanner. The low cost of implementing a servo control system using the PIC17C42 allows this system to compete favorably with stepper motor systems offering a number of advantages: Increased Acceleration, Velocity Improved Efficiency Reduced Audible Noise True Disturbance Rejection
E Encoder
The PIC17C42 implements both the servo compensator algorithm and the trajectory profile (trapezoidal) generation. A trajectory generation algorithm is necessary for optimum motion and its implementation is as important as the servo compensator itself. The servo compensator can be implemented as a traditional digital filter, a fuzzy logic algorithm, or the simple PID algorithm (implemented in this application note). The combination of servo compensator and trajectory calculations can place significant demands on the processor. The digital-to-analog conversion can be handled by a conventional DAC or by using pulse-width modulation (PWM). In either case the output signal is fed to a power stage which translates the analog signal(s) into usable voltages and currents to drive the motor. PWM output can be a duty-cycle signal in combination with a direction signal or a single signal which carries both pieces of information. In the latter case a 50% duty cycle commands a null output, a 0% duty cycle commands maximum negative output, and 100% maximum positive output. The amplifier can be configured to supply a controlled voltage or current to the motor. Most embedded systems use voltage output because of its simplicity and reduced cost. Sequential encoders produce quadrature pulse trains, from which position, speed, and direction of the motor rotation can be derived. The frequency is proportional to speed and each transition of 1 and 2 represents an increment of position. The phase of the signals is used to determine direction of rotation.
SYSTEM OVERVIEW
DC Servo Control Modern digital servo systems are formed as shown in Figure 1. These systems control a motor with an incremental feedback device known as a sequential encoder. They consist of an encoder counter, a processor, some form of digital-to-analog converter, and a power amplifier, which delivers current or voltage to the motor.
DS00532B-page 1
4-185
Rx Tx
LMD18201
PWM1 PWM2 TCLK12 Dir +5 Out1 PWM Out2 Brake GND
M
RTCC TCLK3 TCLK12 RX, TX = = = = 16-bit timer input 16-bit timer input 8-bit timer input serial port receive and transmit pins
PIC17C42
RTCC TCLK3
CountUp CountDn
16R8 PLD
1 2
16MHz Osc.
CLKIN CLKOUT
Z -1
I
+ +
P
+
Y(k)
Saturation
To PWM
Z -1 Z
DS00532B-page 2
4-186
MOTOR ACTUATION
The PIC17C42 contains a high-resolution pulse width modulation (PWM) subsystem. This forms a very efficient power D/A converter when coupled to a simple switching power stage. The resolution of the PIC17C42 PWM subsystem is 62.5nS (at 16 MHz). This translates into 10-bit resolution at a 15.6KHz rate or 1 part in 800 (9 1/2-bit) resolution at 20KHz. This allows effective voltage control while still maintaining the modulation frequency at or above the limit of human hearing. This is especially relevant in office automation equipment where minimizing noise is a design goal. The motor responds to a PWM output stage by time averaging the duty cycle of the output. Most motors react slowly, having an electrical time constant of 0.5mS or more and a mechanical time constant of 20.0mS or more. A 15KHz PWM output is effectively equivalent to that of a linear amplifier. In the system shown in Figure 2, the H-bridges direction input is wired directly to the PIC17C42s PWM output. The H-bridge is powered by a DC supply voltage, Vm. In this configuration 0 volts is presented to the motor when the PWM signal is at a 50% duty cycle, -Vm volts at 0% duty cycle and +Vm volts at 100% duty cycle.
ENCODER FEEDBACK
Position feedback for the example system is derived from a quadrature encoder mounted on the motor shaft. Both incremental position and direction can be derived from this inexpensive device. The quadrature encoder signals are processed by a 16R8-type PLD device as shown in Figure 2. The PLD converts the quadrature pulses into two pulse streams: Count Up and Count Down (Figure 5). These signals are then fed to two 16-bit timers of the PIC17C42 (TMR3 and RTCC). A logic description for the PLD decoder is shown in Appendix B. The PIC17C42 keeps track of the motor shafts incremental position by differencing these two 16-bit timers. This operation is performed each servo sample time and the current position is calculated by adding the incremental position to the previous position. Since both timers are 16-bits deep, keeping track of the overflow is unnecessary, unless the encoder signals frequency is greater than 32767 times the sample frequency. For example, at a servo sample time of 1mS, the maximum encoder rate would be 3.2767 MHz. Counter wrap-around is not a concern because only the difference between the two counters is used. Twoscomplement subtraction takes care of this automatically. Position is maintained as a three-byte, 24-bit quantity in the example program shown in Appendix F. However, there is no limit to the size of the internal position register. By adding the 16-bit incremental position each sample time to an N-byte software register, an N-byte position may be maintained.
THE COMPENSATOR
PID is the most widely used algorithm for servo motor control. Although it may not be the most optimum controller for all applications, however it is easy to understand and tune. The standard digital PID algorithms form is shown in Figure 4. U(k) is the position or velocity error and Y(k) is the output. This algorithm has been implemented using the PIC17C42 math library. Only 800 instruction cycles are required resulting in a 0.2mS PID execution time at 16 MHz. Integrator wind-up is a condition which occurs in PID controllers when a large following error is present in the system, for instance when a large step disturbance is encountered. The integrator continually builds up during this following error condition even though the output is saturated. The integrator then unwinds when the servo system reaches its final destination causing excessive oscillation. The PID implementation shown above avoids this problem by stopping the action of the integrator during output saturation.
DS00532B-page 3
4-187
down_count
RTCC up-count RA1/RT 16-bit counter PLD 16R8 TMR3 down-count RB5/TCLK3 16-bit counter PIC17C42 19 5 2 18 4 1
1 1x/4x select
TRAJECTORY GENERATION
A trajectory generation algorithm is essential for optimum motion control. A linear piecewise velocity trajectory is implemented in this application. For a position move, the velocity is incremented by a constant acceleration value until a specified maximum velocity is reached. The maximum velocity is maintained for a required amount of time and then decremented by the same acceleration (deceleration) value until zero velocity is attained. The velocity trajectory is therefore trapezoidal for a long move and triangular short move where maximum velocity was not reached (Figure 8). The doPreMove subroutine is invoked once at the beginning of a move to calculate the trajectory limits. The doMove routine is then invoked at every sample time to calculate new "desired" velocity and position values as follows: VK = VK-1 + A (A = Acceleration) PK = PK-1 + VK-1 + A/2 For more details on trajectory generation, see Appendix E.
DS00532B-page 4
IMPLEMENTATION DETAILS
The program structure is straightforward: An interrupt service routine (ISR) processes the servo control and trajectory generation calculations, and a foreground loop is used to implement the user interface, serial communication and any exception processing (i.e. limit switches, watchdog timer, etc.). The ISR has a simple structure. In order to effect servo control we need to read the encoder, calculate the new trajectory point and PID values, and set the output of the PWM, all at a constant, predefined rate. The ISR is initiated by a hardware timer (TMR2) on the PIC17C42. To make sure that the servo calculation always occurs synchronously with the PWM subsystem, the PWM2 output is wired to the input pin of TMR12 (TMR1 in internally-clocked, 8-bit timer mode; TMR2 in externallyclocked, 8-bit counter mode). N is loaded into the PR2 register. The sample rate then becomes the PWM rate divided by N. In this implementation N=16 (Figure 7).
4-188
4
16 PWM cycles
Time
DS00532B-page 5
4-189
DCMOTOR.ASM
IntPoll
Program Setup
Save Registers
IdleFunction
GetChk
Move Running? No Yes
Got a char?
No
New Move ?
doPreMove
Get Command
Trajectory in Progress?
Yes
doMove
No
In list?
Yes
Servo On ? Yes doServo Compute PID Compute PWM value Write PWM value
Next Command
No
CAPFLAG ?
Yes
doCapture Regs For PICMASTER based debug Output position, velocity, etc. info.
Restore Registers
RETURN
DS00532B-page 6
4-190
COMMAND INTERFACE
The following commands are implemented and recognized by the user interface in the foreground loop. Move (Value): M, [-8,388,60810 to 8,388,60710] Commands the axis to move to a new position or velocity. Position data is relative, velocity data is absolute. Position data is in encoder counts. Velocity data is given in encoder counts per sample time multiplied by 256. All moves are performed by the controller such that velocity and acceleration limits set into parameter memory will not be violated. All move commands are kept in a one deep FIFO buffer. The command in the buffer is executed as soon as the executing command is complete. If no move is currently executing the commanded move will start immediately. Mode: O, (Type), [P,V, T] An argument of P will cause all subsequent move commands to be incremental position moves. A V argument will cause all subsequent moves to be absolute velocity moves. A "T" argument sets a "Torque mode" where all subsequent M commands directly write to the PWM. This is useful for debug purposes. Set Parameter: S, (#,Value) [00h to FFh, -8,388,60810 to 8,388,60710] Sets controller parameters to the value given. Parameters are shown in Table 1.
Move Status: Y
TABLE 1 - PARAMETERS
Parameter Velocity Limit Acceleration Limit Kp: Proportional Gain Kd: Differential Gain Ki: Integral Gain #h 00 01 02 03 04 Range 0 to 8,388,60710 * 0 to 8,388,60710 ** -3276810 to 3276710 -3276810 to 3276710 -3276810 to 3276710
Returns a two-digit hex number which defines the state of the bits in the move status register. Issuing this command will clear all the bits in the move status register unless the event which set the bit is still true. The bits are defined in Table 3.
* (counts per sample time multiplied by 256) ** (counts per sample time per sample time multiplied by 256)
DS00532B-page 7
4-191
Position Response
Position
100
150
Time (mSec)
POSITION ERROR
15 10
Position Error
Disable Servo: s
This command disables servo actuation. The servo will activate again with the execution of the next M (move) command. This is useful for debug purposes. Examples: Z OV ;Reset software (No <CR> required) ;Set velocity servo mode (No <CR> ;required)
Error
20
40
60
80
100
120
140
160
Time (mSec)
M 1000<CR> ;Set velocity to 1000 M-1000<CR> ;Set velocity to 1000 in reverse ;direction
DESIRED/ACTUAL VELOCITY
20 16
Velocity Response
12 8 4 0 -4 20 40 60 80 100
120
140
160
Time (mSec)
Velocity = counts/sample
VELOCITY ERROR
4 2
Velocity Error
Error
Time (mSec)
Velocity = counts/sample
DS00532B-page 8
4-192
CONCLUSIONS
Using a high-performance 8-bit microcontroller as the heart of a servo control system is a cost-effective solution which requires very few external components. A comparison with a popular dedicated servo-control chip, is presented in Table 4.
Also apparent in the comparison table is the additional processing power available when using the microcontroller. This processing can be used to provide a user interface, handle other I/O, etc. Alternatively, the additional processing time might be used to improve the performance of compensator and trajectory generation algorithms. A further advantage is that for many embedded applications using motor control the microcontroller proves to be a complete, minimum cost solution.
Credit
This application note and a working demo board has been developed by Teknic Inc. Teknic (Rochester, N.Y.) specializes in Motor Control Systems.
References
1. Thomas Bucella, Comparing DSPs to Microprocessors in Motion Control Systems-Some Real World Data, PCIM conference proceedings 1990 Intertec Communications, Inc. 2. David M. Auslander, Cheng H. Tham, Real-Time Software for Control 1990 Prentice-Hall, Inc., Englewood Cliffs, NJ 3. DC Motors, Speed Controls, Servo Systems Fifth Edition 1980 Electro-Craft Corporation, Hopkins, MN Windows is a trademark of Microsoft Corporation.
DS00532B-page 9
4-193
A
MAX232 14 Tx1 DO1 11 13 Rx1 DI1 12 +24V TxD RxD +5V 2 +1 Address 2 C8 10E16R IO +5V 1 En OSC GND 1 C4 .1R +5V Address ~RS R2 12KPA 2 27 4 MHz 2-D1 2 7 20 RP1 Vcc 14 2 1 8 OSC1 16 MHz 19 Index CountUp GPO~ LED RxD TxD 26 25 24 23 22 21 +1 C7 10E16R -10V 7 8 2 Tx2 Rx2 +10V C2+ C1- 3 C1+ 1 PIC17C42 30 RE0/ALE 29 RE1/~OE 28 RE2/~WR ALE ~OE~ ~WR 4 +1 C2U2 MAX232 DO2 10 DI2 9 -10V 6 IDrive 3-D1
B C D E F
DS00532B-page 10
1
C5 2 5 10E16R
6 7 4 2 3 8 9 1 5
P1 !DB9Mini
U3 X2402
2 1 3
RD7/AD15 RD6/AD14 RD5/AD13 RA0/INT RD4/AD12 RA1/RT RD3/AD11 RA2 RD2/AD10 RA3 RD1/AD9 RA4/RX/DT RD0/AD8 RA5/TX/CK RC7/AD7 RC6/AD6 OSC1 RC5/AD5 RC4/AD4 RC3/AD3 OSC2/CLKOUT RC2/AD2 RC1/AD1 RC0/AD0
33 34 35 36 37 38 39 40 9 8 7 6 5 4 3 2
AD15 AD14 AD13 AD12 AD11 AD10 AD9 AD8 AD7 AD6 AD5 AD4 AD3 AD2 AD1 AD0
4-194
5 AD14 AD15 +5V +5V 1 3 2 2 IO +5V 1 1 1 C2 10TR 2 C1 .1R +5V U3 V 8 1 2 C9 .1R U2 +5V V G 16 15 G 4 1 2 C10 .1R 1 2 10 31 R14 12KPA LED Vdd 1 R1 12KPA 2 RB7 RB6 RB5/TCLK3 TEST RB4/TCLK12 RB3/PWM2 32 RB2/PWM1 ~MCLR/Vpp RB1/CAP2 RB0/CAP1 Vss Vss
~WR ~OE ALE AD15 AD14 AD13 AD12 AD11 AD10 AD9 AD8 AD7 AD6 AD5 AD4 AD3 AD2 AD1 AD0 18 -Limit~ 17 +Limit~ 16 CountDn 15 14 PWM2 13 PWM1 12 GPI~ 11 CAP1 GPO~ +Limit~ CountDn -Limit~ PWM2 PWM1 GPI~ ExtCAP
SDA
Q1 2N3904
34 33 1 2 5 24 23 22 21 19 17 15 13 11 9 7 20 18 16 14 12 10 8 6 32 31 30 29 28 27 26 25 3 4
R3 360PA
U1 PIC17C42
P2 HDR17x2-M
LED1 !LN26RP
4
IO 3-A1, 2-E1
A
+5V 1 1 1 1 2 4X 1X 4 U4 2 CountDn CountUp U4 1 SCALE 10 9 4 MHz 1-C2 2 RP1 RP1 IO 1-F4, 3-A1 1 RP1 2.7Kx9CP 3 1 14 RP2 C13 56PR 2 1 2 5 1 C15 +5V RP2 7 R15 12KPA 2 1 GPO~ HW1 PWB_MCEVM1.0 HW2 socDIP_40.6M 3 2 1 +5V 2 56PR Q2 2N3904 +24V 2 2 +5V Q3 ZTX451 IO 1 PWB 11 +Limit~ 1 2 5 1 2 6 RP2 2.7Kx7ID 1 2 C28 56PR U4 74HC14 9 13 12 C27 56PR GPI~ U4 +5V U4 V G 14 7 1 2 C11 .1R +5V U5 V G 20 10 1 2 C12 .1R RP2 10 -Limit~ 11 10 C26 56PR U4 HW3 JMP.1 9 8 HW4 socDIP_20.3M 1 1 360PA 2 3 R4 U4 6 Index RP2 C14 56PR 12 13 3 P5 HDR3X2-M 3
B C D E F
+5V
RP1 5
RP1 4
4 3 5 2 1
P3 MOLEX5-M
RP2
GPO
3 2 1
CR1 2 1N4001
4-195
1
P9 !WTB3x.1
P8 HDR2-M
+Limit
-Limit
6 5 4 3 2 1
GPI
P4 !WTB6x.1
DS00532B-page 11
B
4
3
A
+24V +5V 3 5 1 4 Brake 7 P7 !Minifit-4 2 C18 +5V R8 11 1 10NR BS2 Ground 12KPA 2 1 TFlag 9 ISense 8 R9 ISense 2.21K%1PA IDrive 2 1 1 + 2 3 U8 R6 12KPA 1 -10V +24V 1 2 +1 C24 820E50R 2 P6 !Minifit-2 +24V R12 0.47RPB 2 1 L1 120H +5V 1 2 4 GND -Ref 5 CR2 1 1N5819 2 R11 56.2K%1PA 1 +10V U8 V 8 C16 .1R 1 2 G 4 2 C25 1 .1R U6 MC34063 2 1 R10 18.7K%1PA C23 2 680E6.3R +1 2 CR5 2 1N4689 2 1 +5V 2 R7 12KPA 1 2 2 CR4 1 1N4148 CR3 1 1N4148 OC IO 2 C19 .1R Motor+ 1 Motor- 2 3 4 6
B C D E F
IO 1-F4, 2-E1
DS00532B-page 12
U7 LMD18200 LMD18200 1 BS1 Vs 2 C17 Dir 1 10NR Out1 2 PWM Out2 10
PWM1
_ +
5 6
2 C20 68T10R 1
+ _
U8 LF412 7
4-196
MC34063 6 Vcc ISense 7 3 Ct 1 2 DriveC 8 SwC 1 SwE 2
+24V
C21 .1R
C22 150PR
4
-10V
{ Phi0 } { Phi90 }
C1 C2 C3 C4 C5 C6 C7 C8
} } } } } } } }
DS00532B-page 13
4-197
Enter doServo
Compute Error Value U0 Limit exceeded No Convert YPWM from unipolar to bipolar bipolar to unipolar Set YPWM = 0
YPWM = 0? Compute differential Y = Y + Kd. (U0 - U1) YPWM = 100% Scale Y Y = Y.2 SHIFTNUM Zero lowest 6 bits of YPWM
Yes
Set YPWM 1%
Yes
Yes
Write YPWM high byte PW1DCH Write YPWM high byte PW1DCL Yes Set Y to max neg value = FF800000h
Return
DS00532B-page 14
4-198
4
; Y=KP*U0+KI*INTEGRAL+KV*(U0-U1) ; scale Y by SHIFTNUM ; Y = Y * (2**SHIFTNUM) Scale Y
; if not, zero 6 bits ; if so, set Y=0x007FFFFF ; clear for debug purposes
DS00532B-page 15
4-199
; saturate to max
; saturate to min
DS00532B-page 16
4-200
; Skip next if HI hasnt changed ; HI changed, re-read LO ; OK to store HI now ; clear bits below binary point ; compute upcount increment
4
3
; Skip next if HI hasnt changed ; HI changed, re-read LO ; OK to store HI now ; compute downcount increment
; compute new measured velocity ; sign extend measured velocity for ; 24 bit addition to measured posi-
ADD24
RETURN ;*****************************************************************************
DS00532B-page 17
4-201
where A is the signed acceleration limit calculated in doPreMove. The inverse equations of this iteration, necessary for undoing an unwanted step, are contained in undoPosVel and given by P(k-1) = P(k) - V(K-1) - A/2, V(K-1) = V(k) - A. In position mode, the actual shape of the velocity profile depends on the values of V, A and the size of the move. Either the velocity limit is reached before half the move is completed, resulting in a trapezoidal velocity profile, or half the move is completed before the velocity limit is realized, resulting in a triangular velocity profile. In the algorithm employed here, the velocity limit is treated as a bound on the actual velocity limit, thereby permitting exactly the same number of steps during the speedup and speed down sections of the move. Phase 1 is defined as the section of the move where the commanded position is less than half the move, and phase 2 is the remaining portion of the move. T1 is time when the actual velocity limit is reached and T2 is the time at the end of phase 1.
doMove:
Move generation is based on a piecewise constant acceleration model. During constant acceleration, this results in the standard equations for position and velocity given by x(t) = x0 + v0*t + a*(t**2)/2,v(t) = v0 + a*t
half move
T1
initial velocity
DS00532B-page 18
4-202
4
3
DS00532B-page 19
4-203
SubTitle
Revision:
2.0, 27 June 93
;************************************************************************* ; ; Revised: 8/5/92 ; CREDIT: Developed by Teknic Inc. 1992 ; ; Assembled using MPASM. Users with ASM17 are suggested to get Microchips ; new universal assembler (MPASM). To assemble with ASM17, all if, else ; endif directives must be replaced by #if, #else and #endif ; respectively. ;************************************************************************* PROCESSOR LIST PIC17C42 COLUMNS=120, XREF=YES, NOWRAP,LINES=255, R=DEC
;************************************************************************* ; 00F4 2400 03E8 07D0 1770 2580 MASTER_CLOCK _SAMPLE_RATE _ENCODER_RATE _RATED_SPEED _BAUDRATE_ set set set set set 16000000 1000 2000 6000 9600 ; Input Clock Freq in Hz ; Sample rate in Hz ; 2000 Pulses/rev ; in RPM
;****************************************************************************
include 17c42.h
include 17c42.mac
; Enable PIC-MASTER TRACE Capture ; PID computation based on error ; true for decimal, false for hex
include dcmotor.h17 ; Initialization, Global Defs, ;************************************************************************* ; ; Header file for dcmotor.asm: ; Revised: 8/5/92 ;************************************************************************* ; ; hardware constants ; ; 005C 003D 0900 #define _SET_BAUD_RATE(bps) ((10*MASTER_CLOCK/(64*bps))+5)/10 - 1 CLKOUT set MASTER_CLOCK >> 2 ; Clock Out = CLKIN/4
DS00532B-page 20
4-204
DDRB_INIT set 0xF3 DDRD_INIT set 0x00 ; ; ; max and min pwm values ; PWMINL set 0x40 PWMINH set 0x01 ; 0x0000 + 0x0140 (min 10 bit PWMAXL set 0x80 PWMAXH set 0xFE ; 0xFFC0 - 0x0140 ( max 10 bit ; ; ;************************************************************************* ; global variables ; CBLOCK 0x18 DPX,DPX1,DPX2,DPX3 ; arithmetic accumula AARG,AARG1,BARG,BARG1 ; multiply arguments ENDC CBLOCK 0x18 TMP,TMP1,TMP2,TMP3 MOVTMP,MOVTMP1,MOVTMP2,MOVTMP3
4
3
0018 0004 001C 0004 ENDC CBLOCK 0020 0023 0026 0026 0028 002A 002C 002C 002D 002F 0031 0031 0034 0034 0037 0039 003D 0040 0040 0043 0046 0049 004C 004C 004E 0051 0051 0053 0055 0058 005B 0003 0003 0000 0002 0002 0002 0000 0001 0002 0002 0000 0003 0000 0003 0002 0004 0003 0000 0003 0003 0003 0003 0000 0002 0003 0000 0002 0002 0003 0003 0000
0x20 VL,VL1,VL2 AL,AL1,AL2 KP,KP1 KV,KV1 KI,KI1 IM FV,FV1 FA,FA1 VALBUF,VALBUF1,VALBUF2 DVALBUF,DVALBUF1,DVALBUF2 ISRBSR,ISRWREG CMDCHAR,CMDTEMP,CMDPTRH,CMDPTRL PARTEMP,PARLEN,PARPTR CPOSITION,CPOSITION1,CPOSITION2 CVELOCITY,CVELOCITY1,CVELOCITY2 CMPOSITION,CMPOSITION1,CMPOSITION2 CMVELOCITY,CMVELOCITY1,CMVELOCITY2 STRVALH,STRVALL HEXVAL,HEXTMP,HEXSTAT OPOSITION,OPOSITION1 OPOSITION2,OPOSITION3 POSITION,POSITION1,POSITION2 VELOCITY,VELOCITY1,VELOCITY2
; velocity limit ; acceleration limit ; proportional gain ; velocity gain ; integral gain ; integrator mode ; velocity feedforward ; acceleration ; iovalue buffer ; ; ; ; ; ; ; ; iovalue buffer isr save storage command interface parameter variables shutter shutter shutter shutter commanded commanded measured measured
DS00532B-page 21
4-205
; 0x00 for positive, ; ; ; ; ; time to maximum time for half the total move time next move modetype move modetype
; measured position ; measured velocity ; position error ; velocity error ; multiply sign ; Y(k) before pwm ; saturated error at ; pwm input ; pwm input limits ; ; ; ; ; ; ; servoflag = 0 => no mode external status move status register move flag saturation flag integrator
; decimal io variables ; ; ; ; commanded commanded commanded commanded accelera velocity = position velocity
; running up counter ; running down counter ; move discretization ; phase 2 flat itera ; position at last ; # of bit shifts from
if _PICMASTER_DEBUG ;************************************************************************** ; For PICMASTER Debug/servo tuning Purposes Only CAPFLAG CAPCOUNT,CAPCOUNT1 CAPTMP,CAPTMP1 ; trace capture flag ; PICMASTER trace ; trace capture
;**************************************************************************
DS00532B-page 22
4-206
4
3
;*************************************************************************
DS00532B-page 23
4-207
TIMING (cycles): 4 A,B MOVFP MOVFP MOVFP MOVFP A+B0,AARG+B0 A+B1,AARG+B1 B+B0,BARG+B0 B+B1,BARG+B1 ; ; ; ; load load load load lo hi lo hi byte byte byte byte of of of of A A B B to to to to AARG AARG BARG BARG
LOADAB MACRO
ENDM ;************************************************************************** ;************************************************************************** ; ascii constants ; CR set 0x0D CAN set 0x18 BS set 0x08 SP set 0x20 LF set 0x0A MN set - ; ;********************************************************* ; cmds constants and macros ; ; CHARREADY set 0x01 ; ; NUMPAR set 0x08 ; ; Response characters ; CMD_OK set ! CMD_BAD set ? ; ; Exit values ; ; HEX_SP set 0x00 HEX_MN set 0x01 HEX_CR set 0x02 HEX_CAN set 0x03 ; DEC_SP set 0x00 DEC_MN set 0x01 DEC_CR set 0x02 DEC_CAN set 0x03 ; ; ; Command characters ; DO_NULL set CR DO_MOVE set M ; M DO_MODE set O ; O DO_SETPARAMETER set S ; S DO_READPARAMETER set R ; R DO_SHUTTER set C ; C DO_READCOMPOSITION set P ; P DO_READCOMVELOCITY set V ; V
0001
0008
0021 003F
DS00532B-page 24
4-208
;************************************************************************* ; NAME: CMD_DEF ; ; DESCRIPTION: Creates all the definitions for a command table data struc; ture. The first word is at the command character used, and ; the second word is a pointer to the function that handles ; this command function. ; ; ENTRY CONDITIONS: Must be contiguous with the other entries for the ; function to work. ; ; ARGUMENTS: FUNC command execution function ; ROOT NAME ROOT ; CMD_DEF MACRO FUNC,ROOT DATA DATA ENDM 0002 CMD_ENTRY_LENGTH set 2 ROOT FUNC
4
3
;************************************************************************* ;************************************************************************* ; NAME: CMD_START ; ; DESCRIPTION: Labels the start of the command table. ; CMD_START MACRO LABEL LABEL ENDM ;
;************************************************************************* ;************************************************************************* ; NAME: CMD_END ; ; DESCRIPTION: Marks the end of the command table with an entry of 0x00 ; CMD_END MACRO ; DATA ENDM 0x00 ;
;*************************************************************************
; ; ;************************************************************************** ; PID Constantnts ; define PIV parameters, computation based on errors only. Does not involve
DS00532B-page 25
4-209
0004
equ
;*************************************************************************
0000 C021
0020 C07D
; interrupt
;************************************************************************* ; NAME: Startup ; ; DESCRIPTION: This routine is called on the hardware reset or when the ; program wishes to restore initial conditions. Initiali; zation of run-time constants takes place here. ; ; RETURNS: restart to safe and initial state ; ; STACK UTILIZATION: none ; TIMING (in cycles): X Startup 0021 8406 bsf _glintd AUTONO ; no auto 0022 0023 0024 0025 8404 8504 8604 8704 BSF BSF BSF BSF _fs0 _fs1 _fs2 _fs3 ; disable all
0026 B018 0027 4A01 memloop 0028 2900 0029 1F01 002A C028 002B 15C2
movlw movpf
0x18 wreg,fsr0
; clear all
DS00532B-page 26
4-210
; set duty
; bank2 initialization
003C B800 003D B080 003E 650A 003F B0F8 0040 0110
; bank0 initialization
4
3
; sets RTC for external input ; RA2 connected to BREAK Input of LMD18200 ; On Reset, thus pulled high breaking the motor
0041 B090 0042 730A 0043 B020 0044 750A 0045 B019 0046 770A endif 0047 B0F3 0048 710A 0049 B801
if (_SERVO_PID == TRUE) MOVK16 _KP,KP 004A 004B 004C 004D B008 0126 B007 0127 MOVLW MOVWF MOVLW MOVWF (1800) & 0xff KP+B0 ((1800) >> 8) KP+B1
MOVK16 004E 004F 0050 0051 B034 012A B000 012B MOVLW MOVWF MOVLW MOVWF
_KI,KI
MOVK16
_KV,KV
DS00532B-page 27
4-211
endif MOVK16 0056 0057 0058 0059 B000 0123 B020 0124 MOVLW MOVWF MOVLW MOVWF _ACCL_LIMIT,AL
MOVK16 005A 005B 005C 005D B000 0120 B032 0121 MOVLW MOVWF MOVLW MOVWF
_VEL_LIMIT,VL
005E B004 005F 01B9 0060 5289 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C B080 4A8E B0FE 4A8F B040 4A8C B001 4A8D 2916 2907 8517 8307
movlw movwf movpf movlw movpf movlw movpf movlw movpf movlw movpf clrf clrf bsf bsf bcf movlb zeroctrs
_SHIFTNUM SHIFTNUM pw1dch,YPWM+B1 PWMAXL ; initialize pwm limits wreg,YPWMAX+B0 PWMAXH wreg,YPWMAX+B1 PWMINL wreg,YPWMIN+B0 PWMINH wreg,YPWMIN+B1 pir intsta _tm2ie _peie _glintd bank2 ; clear flags, set indiviual interrupts
; enable interrupts
006F 290B 0070 290C 0071 2912 0072 2913 0073 B0FF 0074 170A 0075 C074 0076 0077 0078 0079 007A 007B 6A0B 080C 0812 0813 330A C06F
clrf clrf clrf clrf movlw decfsz goto movfp iorwf iorwf iorwf tstfsz goto goto
rtccl rtcch tmr3l tmr3h 0xFF wreg delay rtccl,wreg rtcch,W tmr3l,W tmr3h,W wreg zeroctrs PollingLoop
; clear up counter
delay
007C C124
;************************************************************************
DS00532B-page 28
4-212
InterruptPoll
movlb call
bank1 doMPosMVel ; calculate measured position and ; velocity ; evaluate external status ; ; ; ; if MOVFLAG=0 and MOVSTAT,bit7=1 then do premove. This is only executed once at the beginning of each move
0087 E111 0088 0089 008A 008B 008C 2293 B501 0494 9F0A E23D
call rlncf andlw subwf btfsc call btfsc call call tstfsz call if
doExtstat MOVSTAT,W 0x01 MOVFLAG,W wreg,MSB doPreMove MOVSTAT,bit6 doMove doError SERVOFLAG doServo
4
3
008D 9E93 008E E30F 008F E09E 0090 3390 0091 E4AC
; is motion continuing? ; if so, do move ; calculate position and velocity ; error ; test servoflag, if 0 then no servo ; do servo
0092 33BB 0093 E79A endif 0094 B801 0095 2916 0096 0097 0098 0099 009A 009B 009C A4C5 A6C6 6DC3 6EC4 6F37 64C7 6A38
movlb clrf tlwt tlwt movfp movfp movfp movfp movfp retfie
bank1 pir 0,TblLatLo 1,TblLatHi tblptrlTemp,tblptrl tblptrhTemp,tblptrh ISRBSR,bsr alustaTemp,alusta ISRWREG,wreg ; clear all interrupt request flags
; restored table latch ; restored table pointers ; restore BSR,wreg,alusta & Table
009D 0005
;************************************************************************* ;************************************************************************* ; NAME: doError ; ; DESCRIPTION: Calculates the position and velocity error. ; doError MOV24 POSITION,POSERROR ; calculate position error
DS00532B-page 29
4-213
SUB24 00A4 00A5 00A6 00A7 00A8 00A9 6A72 0579 6A73 037A 6A74 037B MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB
MPOSITION,POSERROR MPOSITION+B0,wreg POSERROR+B0 MPOSITION+B1,wreg POSERROR+B1 MPOSITION+B2,wreg POSERROR+B2 ; ; ; ; ; ; get sub get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of of MPOSITION into of POSERROR, MPOSITION into POSERROR, save MPOSITION into POSERROR, save
00AA 9F7B 00AB C0B7 ppos 00AC 00AD 00AE 00AF 00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB 00BC 00BD 00BE 00BF 00C0 6A7A B580 097B 290A 327B C0C1 297B B07F 4A7A 2B79 C0C1 pneg 6A7A B37F 0B7B 2B0A 307B C0C1 2B7B 297A 877A 2979 psatok
btfsc goto movfp andlw iorwf clrf cpfsgt goto clrf movlw movpf setf goto movfp iorlw andwf setf cpfslt goto setf clrf bsf clrf
POSERROR+B2,MSB pneg POSERROR+B1,wreg 0x80 POSERROR+B2 wreg POSERROR+B2 psatok POSERROR+B2 0x7F wreg,POSERROR+B1 POSERROR psatok POSERROR+B1,wreg 0x7F POSERROR+B2 wreg POSERROR+B2 psatok POSERROR+B2 POSERROR+B1 POSERROR+B1,MSB POSERROR
MOV24 00C1 00C2 00C3 00C4 00C5 00C6 6A58 4A7C 6A59 4A7D 6A5A 4A7E MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF
; calculate velocity error ; ; ; ; ; ; get byte of VELOCITY into w move to VELERROR(B0) get byte of VELOCITY into w move to VELERROR(B1) get byte of VELOCITY into w move to VELERROR(B2)
SUB24 00C7 00C8 00C9 00CA 00CB 00CC 6A75 057C 6A76 037D 6A77 037E MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB
MVELOCITY,VELERROR MVELOCITY+B0,wreg VELERROR+B0 MVELOCITY+B1,wreg VELERROR+B1 MVELOCITY+B2,wreg VELERROR+B2 ; ; ; ; ; ; get sub get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of of MVELOCITY into w of VELERROR, save MVELOCITY into w VELERROR, save in MVELOCITY into w VELERROR, save in
btfsc goto
VELERROR+B2,MSB vneg
DS00532B-page 30
4-214
4
3
;************************************************************************* ; NAME: doMPosMVel ; ; DESCRIPTION: Calculates current position from UpCount and DownCount ; doMPosMVel ; Do UpCounter first MOVFP16 UPCOUNT,TMP+B0 00E5 78AC 00E6 79AD MOVFP MOVFP UPCOUNT+B0,TMP+B0+B0 UPCOUNT+B1,TMP+B0+B1 ; save old upcount ; move UPCOUNT(B0) to TMP+B0(B0) ; move UPCOUNT(B1) to TMP+B0(B1)
readUp 00E7 00E8 00E9 00EA 00EB 4C0A 4BAC 310C C0E7 4AAD movpf movpf cpfseq goto movpf clrf MOV16 00ED 00EE 00EF 00F0 6AAC 0176 6AAD 0177 MOVFP MOVWF MOVFP MOVWF rtcch,wreg rtccl,UPCOUNT+B0 rtcch readUp wreg,UPCOUNT+B1 MVELOCITY+B0 UPCOUNT,MVELOCITY+B1 UPCOUNT+B0,wreg MVELOCITY+B1+B0 UPCOUNT+B1,wreg MVELOCITY+B1+B1
; Skip next if HI hasnt changed ; HI changed, re-read LO ; OK to store HI now ; clear bits below binary point ; compute upcount increment ; ; ; ; get byte of UPCOUNT into w move to MVELOCITY+B1(B0) get byte of UPCOUNT into w move to MVELOCITY+B1(B1)
00EC 2975
SUB16 00F1 00F2 00F3 00F4 6A18 0576 6A19 0377 MOVFP SUBWF MOVFP SUBWFB
TMP+B0,MVELOCITY+B1 TMP+B0+B0,wreg MVELOCITY+B1+B0 TMP+B0+B1,wreg MVELOCITY+B1+B1 ; ; ; ; get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of of TMP+B0 into of TMP+B0 into w MVELOCITY+B1,
DS00532B-page 31
4-215
readDown 00F7 00F8 00F9 00FA 00FB 00FC B802 530A 52AE 3113 C0F7 4AAF movlb movpf movpf cpfseq goto movpf MOVFP16 00FD 7AAE 00FE 7BAF MOVFP MOVFP bank2 ; timers in Bank 2 tmr3h,wreg tmr3l,DOWNCOUNT+B0 tmr3h ; Skip next if HI hasnt changed readDown ; HI changed, re-read LO wreg,DOWNCOUNT+B1 ; OK to store HI now DOWNCOUNT+B0,TMP+B2 DOWNCOUNT+B0+B0,TMP+B2+B0 DOWNCOUNT+B0+B1,TMP+B2+B1 ; compute downcount increment ; move DOWNCOUNT+B0(B0) to ; move DOWNCOUNT+B0(B1) to
SUB16 00FF 0100 0101 0102 6A18 051A 6A19 031B MOVFP SUBWF MOVFP SUBWFB
TMP+B0,TMP+B2 TMP+B0+B0,wreg TMP+B2+B0 TMP+B0+B1,wreg TMP+B2+B1 ; ; ; ; get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of of TMP+B0 into of TMP+B2, save TMP+B0 into w TMP+B2, save in
SUB16 0103 0104 0105 0106 6A1A 0576 6A1B 0377 MOVFP SUBWF MOVFP SUBWFB
; compute new measured velocity ; ; ; ; get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of of TMP+B2 into of TMP+B2 into w MVELOCITY+B1,
ADD24 010A 010B 010C 010D 010E 010F 6A76 0F72 6A77 1173 6A78 1174 MOVFP ADDWF MOVFP ADDWFC MOVFP ADDWFC
; compute new measured position ; ; ; ; ; ; get add get add get add lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of of MVELOCITY+B1 of MPOSITION, MVELOCITY+B1 MPOSITION, save MVELOCITY+B1 MPOSITION, save
; delta position = measured 0110 0002 return ;************************************************************************* ; NAME: doExtstat ; ; DESCRIPTION: Get +limit,-limit,GPI from PORTB and set in EXTSTAT ; doExtstat btfss _intir goto otherbits MOV24 MPOSITION,INDEXPOS
DS00532B-page 32
4-216
bcf bsf otherbits movlb movfp rrcf andlw movpf swapf iorwf iorwf return
_intir EXTSTAT,MSB
; set in EXTSTAT
0123 0002
;************************************************************************* ;************************************************************************* ; NAME: PollingLoop ; ; DESCRIPTION: The actual polling loop called after the boards ; initialization ; ; ENTRY CONDITIONS: System globals and hardware initialized and the ; interrupt processes started. ; PollingLoop if _SERIAL_IO call call cpfseq goto call movpf goto else clrwdt goto endif ;************************************************************************* include mult.asm ; Double Precision Multiplication Routine ;************************************************************************* ; Double Precision Multiplication Routine ; ; NAME: Dmult ; ; DESCRIPTION: Mult: AARG (16 bits) * BARG (16 bits) -> DPX (32 bits) ; ; (a) Load the 1st operand in locations AARG+B0 & AARG+B1 (16 bits) ; (b) Load the 2nd operand in locations BARG+B0 & BARG+B1 (16 bits) ; (c) call Dmult ; (d) The 32 bit result is in locations (DPX+B0,DPX+B1,DPX+B2,DPX+B3) ; ; In the signed case, a savings of 9 clks can be realized by choosing PollingLoop ; wait for Interrupt
4
3
DS00532B-page 33
4-217
DS00532B-page 34
4-218
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
4
3
; Double Precision Multiply ( ; ( AARG*BARG -> : 32 bit ; Dmult if 012B 971F 012C C137 SIGNED btfss BARG+B1,MSB goto argsok NEG16 COMF COMF CLRF INCF ADDWFC COMF COMF CLRF INCF ADDWFC endif argsok 0137 291B 0138 291A MULTMAC 0000 0000 variable i i = 0 if SIGNED while i < 15 else while i < 16 endif if i < 8 btfsc BARG+B0,i else btfsc BARG+B1,i-8 endif goto add#v(i) if i < 8 rlcf DPX+B3,W rrcf DPX+B3 clrf clrf DPX+B3 DPX+B2 ; clear initial partial product ; use macro for multiplication AARG+B0+B0 AARG+B0+B1 wreg AARG+B0+B0 AARG+B0+B1 NEG16 BARG+B0+B0 BARG+B0+B1 wreg BARG+B0+B0 BARG+B0+B1 ; test sign of BARG ; if positive, ok ; if negative, then negate
AARG+B0
012D 012E 012F 0130 0131 0132 0133 0134 0135 0136
131C 131D 290A 151C 111D 131E 131F 290A 151E 111F
BARG+B0
DS00532B-page 35
4-219
0139 981E
BARG+B0,i BARG+B1,i-8 add0 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
013A C19C 013B 013C 013D 013E 1A1B 191B 191A 1919
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
BARG+B0,i BARG+B1,i-8 add1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
0140 C1A6 0141 0142 0143 0144 1A1B 191B 191A 1919
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
BARG+B0,i BARG+B1,i-8
DS00532B-page 36
4-220
BARG+B0,i BARG+B1,i-8 add3 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
014C C1BA 014D 014E 014F 0150 1A1B 191B 191A 1919
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
BARG+B0,i BARG+B1,i-8 add4 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
4
3
0152 C1C4 0153 0154 0155 0156 1A1B 191B 191A 1919
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
BARG+B0,i BARG+B1,i-8 add5 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
0158 C1CE 0159 015A 015B 015C 1A1B 191B 191A 1919
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
DS00532B-page 37
4-221
BARG+B0,i BARG+B1,i-8 add7 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
0164 C1E2 0165 0166 0167 0168 1A1B 191B 191A 1919
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
0008
BARG+B0,i BARG+B1,i-8 add8 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
BARG+B0,i BARG+B1,i-8 add9 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
BARG+B0,i
DS00532B-page 38
4-222
BARG+B0,i BARG+B1,i-8 add11 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
4
3
BARG+B0,i BARG+B1,i-8 add12 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
DS00532B-page 39
4-223
BARG+B0,i BARG+B1,i-8 add14 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B3,W DPX+B3 DPX+B2 DPX+B1 DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
DPX+B0
; rotate sign into carry bit ; for i < 8, no meaningful ; are in DPX+B0
i = 1 if SIGNED while i < 15 else while i < 16 endif if i < 8 btfss BARG+B0,i ; test low byte else btfss BARG+B1,i-8 ; test high byte endif goto noadd#v(i) add#v(i) movfp addwf movfp addwfc noadd#v(i) if i < 8 rlcf rrcf rrcf rrcf else rlcf rrcf rrcf rrcf rrcf endif i = i+1 endw if i < 8 btfss AARG+B1,W DPX+B3 DPX+B2 DPX+B1 AARG+B1,W DPX+B3 DPX+B2 DPX+B1 DPX+B0 ; rotate sign into carry bit ; for i < 8, no meaningful bits ; are in DPX+B0 AARG+B0,wreg DPX+B2 ;add lsb AARG+B1,wreg DPX+B3 ;add msb
01A4 911E
BARG+B0,i
DS00532B-page 40
4-224
01A5 C1AA
; test low byte ; test high byte add2 ;add lsb ;add msb
4
3
01B9 C1BE
DS00532B-page 41
4-225
01C3 C1C8
01CD C1D2
endif
0006
01D6 961E
BARG+B0,i BARG+B1,i-8
goto movfp
noadd6 AARG+B0,wreg
DS00532B-page 42
4-226
01E1 C1E6
4
3
0008
DS00532B-page 43
4-227
DS00532B-page 44
4-228
4
3
DS00532B-page 45
4-229
0232 0233 0234 0235 0236 000F 0237 0238 0239 023A 023B
023C 0002
;************************************************************************* ; NAME: doPreMove ; ; DESCRIPTION: doPreMove: CLR16 023D 2996 023E 2997 MOV24 023F 0240 0241 0242 0243 0244 0245 0246 0247 0248 0249 6A5B 4A5F 6A5C 4A60 6A5D 4A61 8F93 8693 8593 6AC2 4A94 INTEGRAL CLRF CLRF INTEGRAL+B0 INTEGRAL+B1 ; move buffer to MOVVAL ; ; ; ; ; ; get byte of NMOVVAL into w move to MOVVAL(B0) get byte of NMOVVAL into w move to MOVVAL(B1) get byte of NMOVVAL into w move to MOVVAL(B2)
NMOVVAL,MOVVAL MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF bcf bsf bsf movfp movpf NMOVVAL+B0,wreg wreg,MOVVAL+B0 NMOVVAL+B1,wreg wreg,MOVVAL+B1 NMOVVAL+B2,wreg wreg,MOVVAL+B2 MOVSTAT,bit7 MOVSTAT,bit6 MOVSTAT,bit5 ONE,wreg wreg,MOVFLAG
; clear buffer flag ; set motion status flag ; set move in progress flag ; initialize MOVEFLAG to 1
; initialize buffers
; get byte of POSITION into w ; move to OPOSITION+B1(B0) ; get byte of POSITION into w
DS00532B-page 46
4-230
MOV32 0251 0252 0253 0254 0255 0256 0257 0258 6A51 4AA4 6A52 4AA5 6A53 4AA6 6A54 4AA7
OPOSITION,MOVPBUF MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF OPOSITION+B0,wreg wreg,MOVPBUF+B0 OPOSITION+B1,wreg wreg,MOVPBUF+B1 OPOSITION+B2,wreg wreg,MOVPBUF+B2 OPOSITION+B3,wreg wreg,MOVPBUF+B3 ; ; ; ; ; ; ; ; get byte of OPOSITION move to MOVPBUF(B0) get byte of OPOSITION move to MOVPBUF(B1) get byte of OPOSITION move to MOVPBUF(B2) get byte of OPOSITION move to MOVPBUF(B3) into w into w into w into w
4
3
0268 3391 0269 C2C5 pmode MOVFP24 026A 785F 026B 7960 026C 7A61
tstfsz goto
MODETYPE vmode
MOVVAL,TMP MOVFP MOVFP MOVFP MOVVAL+B0,TMP+B0 MOVVAL+B1,TMP+B1 MOVVAL+B2,TMP+B2 ; move MOVVAL(B0) to TMP(B0) ; move MOVVAL(B1) to TMP(B1) ; move MOVVAL(B2) to TMP(B2)
btfss goto
TMP+B2,MSB mvpos
DS00532B-page 47
4-231
mvpos 0276 0277 tive 0278 0279 027A 291C 291D 291E 801C 811C SUB24 027B 027C 027D 027E 027F 0280 6A1C 0518 6A1D 0319 6A1E 031A clrf clrf MOVTMP+B0 MOVTMP+B1 ; calculate abs(MOVVAL) - 3 ; do immediate move if nega-
clrf MOVTMP+B2 bsf MOVTMP+B0,bit0 bsf MOVTMP+B0,bit1 MOVTMP,TMP MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB MOVTMP+B0,wreg TMP+B0 MOVTMP+B1,wreg TMP+B1 MOVTMP+B2,wreg TMP+B2 ; ; ; ; ; ; get sub get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of of MOVTMP of TMP, save MOVTMP into TMP, save in MOVTMP into TMP, save in
btfss TMP+B2,MSB goto nonzero setf SERVOFLAG clrf MOVFLAG bcf MOVSTAT,bit5 bcf MOVSTAT,bit6 MOVVAL,POSITION MOVFP ADDWF MOVFP ADDWFC MOVFP ADDWFC MOVVAL+B0,wreg POSITION+B0 MOVVAL+B1,wreg POSITION+B1 MOVVAL+B2,wreg POSITION+B2
; ; ; ; ; ;
lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of
028D 0002
return nonzero CLR32 MOVVBUF CLRF CLRF CLRF CLRF MOVVBUF+B0 MOVVBUF+B1 MOVVBUF+B2 MOVVBUF+B3
0292 6A61 0293 B580 0294 4A69 0295 29A3 MOV24 0296 0297 0298 0299 029A 029B 6A20 4AA0 6A21 4AA1 6A22 4AA2
movfp andlw movpf clrf VL,V MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF
; move sign
; create appropriate velocity ; acceleration limits from ; ; ; ; ; ; get byte of VL into w move to V(B0) get byte of VL into w move to V(B1) get byte of VL into w move to V(B2)
DS00532B-page 48
4-232
029C 299F MOV24 029D 029E 029F 02A0 02A1 02A2 6A23 4A9C 6A24 4A9D 6A25 4A9E
A+B3
; ; ; ; ;
get byte of AL into w move to A(B0) get byte of AL into w move to A(B1) get byte of AL into w ; move to A(B2)
02A3 290A 02A4 3269 02A5 C2B8 NEG32 02A6 02A7 02A8 02A9 02AA 02AB 02AC 02AD 02AE 13A0 13A1 13A2 13A3 290A 15A0 11A1 11A2 11A3
clrf cpfsgt goto V COMF COMF COMF COMF CLRF INCF ADDWFC ADDWFC ADDWFC
4
3
NEG32 02AF 02B0 02B1 02B2 02B3 02B4 02B5 02B6 02B7 139C 139D 139E 139F 290A 159C 119D 119E 119F
A COMF COMF COMF COMF CLRF INCF ADDWFC ADDWFC ADDWFC A+B0 A+B1 A+B2 A+B3 wreg A+B0 A+B1 A+B2 A+B3
minc 02B8 2963 clrf MOV24 MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF HMOVVAL+B0 MOVVAL,HMOVVAL+B1 MOVVAL+B0,wreg wreg,HMOVVAL+B1+B0 MOVVAL+B1,wreg wreg,HMOVVAL+B1+B1 MOVVAL+B2,wreg wreg,HMOVVAL+B1+B2 ; evaluate MOVVAL/2
; ; ; ; ; ;
get byte of MOVVAL into w move to HMOVVAL+B1(B0) get byte of MOVVAL into w move to HMOVVAL+B1(B1) get byte of MOVVAL into w move to HMOVVAL+B1(B2)
RRC32 02BF 02C0 02C1 02C2 02C3 1A66 1966 1965 1964 1963
HMOVVAL RLCF RRCF RRCF RRCF RRCF HMOVVAL+B3,W HMOVVAL+B3 HMOVVAL+B2 HMOVVAL+B1 HMOVVAL+B0
goto
modeready
btfsc goto
MODETYPE,MSB tmode
; is it torque move?
DS00532B-page 49
4-233
; ; ; ; ; ;
get byte of MOVVAL into w move to HMOVVAL(B0) get byte of MOVVAL into w move to HMOVVAL(B1) get byte of MOVVAL into w move to HMOVVAL(B2)
02CE 9F61 02CF 2B66 SUB32 02D0 02D1 02D2 02D3 02D4 02D5 02D6 02D7 02D8 02D9 02DA 6AA8 0563 6AA9 0364 6AAA 0365 6AAB 0366 6A66 B580 4A69
btfsc MOVVAL+B2,MSB setf HMOVVAL+B3 MOVVBUF,HMOVVAL MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB MOVFP SUBWFB movfp andlw movpf clrf VL,V MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF MOVVBUF+B0,wreg HMOVVAL+B0 MOVVBUF+B1,wreg HMOVVAL+B1 MOVVBUF+B2,wreg HMOVVAL+B2 MOVVBUF+B3,wreg HMOVVAL+B3 HMOVVAL+B3,wreg 0x80 wreg,MOVSIGN V+B3 ; ; ; ; ; ; ; ; get sub get sub get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of 4th byte of 4th byte of of MOVVBUF into w of HMOVVAL, save in MOVVBUF into w HMOVVAL, save in MOVVBUF into w HMOVVAL, save in MOVVBUF into w HMOVVAL, save in
02DB 29A3 MOV24 02DC 02DD 02DE 02DF 02E0 02E1 6A20 4AA0 6A21 4AA1 6A22 4AA2
; create appropriate velocity and ; acceleration limits from move sign ; ; ; ; ; ; get byte of VL into w move to V(B0) get byte of VL into w move to V(B1) get byte of VL into w move to V(B2)
02E2 299F MOV24 02E3 02E4 02E5 02E6 02E7 02E8 6A23 4A9C 6A24 4A9D 6A25 4A9E
A+B3
; ; ; ; ; ;
get byte of AL into w move to A(B0) get byte of AL into w move to A(B1) get byte of AL into w move to A(B2)
02E9 290A 02EA 3269 02EB C2FE NEG32 02EC 02ED 02EE 02EF 02F0 02F1 02F2 02F3 02F4 13A0 13A1 13A2 13A3 290A 15A0 11A1 11A2 11A3 V
DS00532B-page 50
4-234
if
_PICMASTER_DEBUG
;**************************************************************** ; For PICMASTER Debug/servo tuning puporses only Purposes Only ; testCapCount movfp CAPCOUNT+B0,wreg iorwf CAPCOUNT+B1,W movpf wreg,CAPFLAG ;************************************************************************* endif return tmode MOV16 ; torque/voltage mode ; set new commanded value ; ; ; ; get byte of MOVVAL+B1 into w move to YPWM(B0) get byte of MOVVAL+B1 into w move to YPWM(B1)
4
3
0305 0002
clrf SERVOFLAG call doTorque clrf MOVFLAG bcf MOVSTAT,bit5 _PICMASTER_DEBUG goto testCapCount return
endif ;************************************************************************** ;************************************************************************* ; NAME: doMove ; ; DESCRIPTION: In position mode, trapezoidal moves are performed. Phase1 ; and phase2 respectively, are the periods for the first and ; second halves of the move. The move time is defined as zero ; at the beginning of the move,T2 is the time at half the move, T1 is the time when c ; begins,(the region of constant velocity reduces to a point ; in the case where maximum speed is not realized, and the ; trapezoidal move degenerates into a trianglular move, ; together with T1=T2), and TAU is the total time of the move. ; The accelerations are +-AL or 0. ; ; ; triangle speed trapezoidal speed ; ; ________________ ; / \
DS00532B-page 51
4-235
Let x denote the undershoot and y the overshoot commanded at adjacent sample times as half the move is crossed. In the case of a triangular move, the discretization error is given by error = min (2x,2y) For a trapezoidal move, the discretization error is error = min (2x,y-x) <= .5*(maximum commanded speed) This discretization error is resolved in the final sample time of the move by executing a step to the final position at zero speed. The method employed here the best possible performance with regard to discretization error without dynamically modifying velocity and acceleration limits.
call doPosVel tstfsz MODETYPE goto vmove pmove movfp ONE,wreg cpfseq MOVFLAG goto phase2
; test if in phase1
DS00532B-page 52
4-236
; get lowest byte of HMOVVAL into w ; add lowest byte of MOVDEL, save in ; get 2nd byte of HMOVVAL into w ; add 2nd byte of MOVDEL, save in ; get 3rd byte of HMOVVAL into w ; add 3rd byte of MOVDEL, save in ; get 4th byte of HMOVVAL into w ; add 4th byte of MOVDEL, save in ; ; ; ; ; ; ; ; get sub get sub get sub get sub lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of 4th byte of 4th byte of of MOVPBUF into of MOVDEL, save MOVPBUF into w MOVDEL, save in MOVPBUF into w MOVDEL, save in MOVPBUF into w MOVDEL, save in
4
3
033F 97B3 0340 C3A5 0341 6A6A 0342 086B 0343 330A
; reached, ; has been set in speedup 0344 C378 0345 0346 0347 0348 0349 034A 034B 034C 034D 034E 034F 0350 0351 0352 0353 0354 0355 0356 0357 0358 0359 139C 139D 139E 139F 290A 159C 119D 119E 119F 6AB0 0F1C 6AB1 111D 6AB2 111E 6AB3 111F 971F C36E 2B6C 2B6D goto NEG32 COMF COMF COMF COMF CLRF INCF ADDWFC ADDWFC ADDWFC ADD32 MOVFP ADDWF MOVFP ADDWFC MOVFP ADDWFC MOVFP ADDWFC btfss goto setf setf NEG32 t2net1 A A+B0 A+B1 A+B2 A+B3 wreg A+B0 A+B1 A+B2 A+B3 MOVDEL,MOVTMP MOVDEL+B0,wreg MOVTMP+B0 MOVDEL+B1,wreg MOVTMP+B1 MOVDEL+B2,wreg MOVTMP+B2 MOVDEL+B3,wreg MOVTMP+B3 MOVTMP+B3,MSB triok T2+B0 T2+B1 A ; negate A for speeddown
; ; ; ; ; ; ; ; ; ; ; ;
test x-y < 0 get lowest byte of MOVDEL into add lowest byte of MOVTMP, save get 2nd byte of MOVDEL into w add 2nd byte of MOVTMP, save in get 3rd byte of MOVDEL into w add 3rd byte of MOVTMP, save in get 4th byte of MOVDEL into w add 4th byte of MOVTMP, save in if new discretization error larger, backup to define T2, otherwise ok set T2=-1 for backup
; negate A to undo
DS00532B-page 53
4-237
035A 035B 035C 035D 035E 035F 0360 0361 0362 0363 0364 0365 0366 0367 0368 0369 036A 036B 036C 036D
139C 139D 139E 139F 290A 159C 119D 119E 119F E48A 139C 139D 139E 139F 290A 159C 119D 119E 119F E468
036E 036F 0370 0371 0372 0373 0374 0375 0376 0377
6A67 0F6C 6A68 116D 6A6C 016A 6A6D 016B 1594 C3CE t2net1
COMF COMF COMF COMF CLRF INCF ADDWFC ADDWFC ADDWFC call NEG32 COMF COMF COMF COMF CLRF INCF ADDWFC ADDWFC ADDWFC call triok ADD16 MOVFP ADDWF MOVFP ADDWFC MOV16 MOVFP MOVWF MOVFP MOVWF incf goto setf setf ADD16 MOVFP ADDWF MOVFP ADDWFC MOVFP32 MOVFP MOVFP MOVFP MOVFP RLC32 BCF RLCF RLCF RLCF RLCF ADD32 MOVFP ADDWF MOVFP ADDWFC MOVFP ADDWFC MOVFP ADDWFC ADD32 MOVFP ADDWF MOVFP ADDWFC
A+B0 A+B1 A+B2 A+B3 wreg A+B0 A+B1 A+B2 A+B3 undoPosVel A A+B0 A+B1 A+B2 A+B3 wreg A+B0 A+B1 A+B2 A+B3 doPosVel MOVTIME,T2 MOVTIME+B0,wreg T2+B0 MOVTIME+B1,wreg T2+B1 T2,T1 T2+B0,wreg T1+B0 T2+B1,wreg T1+B1 MOVFLAG mvok T2+B0 T2+B1 MOVTIME,T2 MOVTIME+B0,wreg T2+B0 MOVTIME+B1,wreg T2+B1 MOVTMP,TMP MOVTMP+B0,TMP+B0 MOVTMP+B1,TMP+B1 MOVTMP+B2,TMP+B2 MOVTMP+B3,TMP+B3 MOVTMP _carry MOVTMP+B0 MOVTMP+B1 MOVTMP+B2 MOVTMP+B3 TMP,MOVTMP TMP+B0,wreg MOVTMP+B0 TMP+B1,wreg MOVTMP+B1 TMP+B2,wreg MOVTMP+B2 TMP+B3,wreg MOVTMP+B3 MOVDEL,MOVTMP MOVDEL+B0,wreg MOVTMP+B0 MOVDEL+B1,wreg MOVTMP+B1
; and reevaluate iterative equations ; add time to T2 lowest byte of MOVTIME into w lowest byte of T2, save in 2nd byte of MOVTIME into w 2nd byte of T2, save in T2(B1) w w for move
; ; ; ; ; ; ; ; ; ;
get byte of T2 into move to T1(B0) get byte of T2 into move to T1(B1) increment move flag execute last phase1
0378 2B6C 0379 2B6D 037A 037B 037C 037D 037E 037F 0380 0381 0382 0383 0384 0385 0386 0387 0388 0389 038A 038B 038C 038D 038E 038F 0390 0391 0392 6A67 0F6C 6A68 116D 781C 791D 7A1E 7B1F 8804 1B1C 1B1D 1B1E 1B1F 6A18 0F1C 6A19 111D 6A1A 111E 6A1B 111F 6AB0 0F1C 6AB1 111D
; set T2=-1 for backup ; ; ; ; ; ; ; ; ; ; add time to T2 get lowest byte of MOVTIME add lowest byte of T2, save get 2nd byte of MOVTIME into add 2nd byte of T2, save in T2(B1) test if 3x-y < 0 move MOVTMP(B0) to TMP(B0) move MOVTMP(B1) to TMP(B1) move MOVTMP(B2) to TMP(B2) move MOVTMP(B3) to TMP(B3)
; ; ; ; ; ; ; ; ; ; ; ;
get add get add get add get add get add get add
lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of 4th byte of 4th byte of lowest byte lowest byte 2nd byte of 2nd byte of
of TMP into of MOVTMP, TMP into w MOVTMP, save TMP into w MOVTMP, save TMP into w MOVTMP, save of MOVDEL of MOVTMP, MOVDEL into MOVTMP, save
DS00532B-page 54
4-238
get lowest byte of T1 into w sub lowest byte of PH2FLAT, get 2nd byte of T1 into w sub 2nd byte of PH2FLAT, increment move flag for execute last phase1 move test move move move move get sub get sub get sub get sub if maximum velocity V(B0) to MOVTMP(B0) V(B1) to MOVTMP(B1) V(B2) to MOVTMP(B2) V(B3) to MOVTMP(B3) lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of 4th byte of 4th byte of of MOVVBUF of MOVTMP, MOVVBUF into MOVTMP, save MOVVBUF into MOVTMP, save MOVVBUF into MOVTMP, save in
03A5 03A6 03A7 03A8 03A9 03AA 03AB 03AC 03AD 03AE 03AF 03B0 03B1 03B2 03B3 03B4 03B5 03B6 03B7 03B8 03B9 03BA 03BB
7CA0 7DA1 7EA2 7FA3 6AA8 051C 6AA9 031D 6AAA 031E 6AAB 031F 9769 C3BC 131C 131D 131E 131F 290A 151C 111D 111E 111F
4
3
DS00532B-page 55
4-239
03DB 03DC 03DD 03DE 03DF 03E0 03E1 03E2 03E3 03E4 03E5 03E6 03E7 03E8 03E9 03EA 03EB 03EC 03ED 03EE 03EF 03F0 03F1 03F2 03F3 03F4 03F5 03F6 03F7 03F8 03F9 03FA 03FB 03FC 03FD 03FE
6AB4 08B5 330A C3FF 6AA8 08A9 08AA 08AB 330A C41C 2994 8E93 8D93 299C 299D 299E 299F 6A67 016E 6A68 016F 6A51 4AA4 6A52 4AA5 6A53 4AA6 6A54 4AA7 6A5F 0FA5 6A60 11A6 6A61 11A7 C41C
PH2FLAT PH2FLAT+B0,wreg PH2FLAT+B1,W wreg flat MOVVBUF MOVVBUF+B0,wreg MOVVBUF+B1,W MOVVBUF+B2,W MOVVBUF+B3,W wreg mready MOVFLAG MOVSTAT,bit6 MOVSTAT,bit5 A A+B0 A+B1 A+B2 A+B3 MOVTIME,TAU MOVTIME+B0,wreg TAU+B0 MOVTIME+B1,wreg TAU+B1 OPOSITION,MOVPBUF OPOSITION+B0,wreg wreg,MOVPBUF+B0 OPOSITION+B1,wreg wreg,MOVPBUF+B1 OPOSITION+B2,wreg wreg,MOVPBUF+B2 OPOSITION+B3,wreg wreg,MOVPBUF+B3 MOVVAL,MOVPBUF+B1 MOVVAL+B0,wreg MOVPBUF+B1+B0 MOVVAL+B1,wreg MOVPBUF+B1+B1 MOVVAL+B2,wreg MOVPBUF+B1+B2 mready
; is velocity zero?
; ; ; ; ;
if not, execute move if so, clear MOVFLAG clear motion status flag clear move in progress flag set zero velocity and acceleration,
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
get byte of MOVTIME into w move to TAU(B0) get byte of MOVTIME into w move to TAU(B1) execute last move to P(0)+MOVVAL get byte of OPOSITION into w move to MOVPBUF(B0) get byte of OPOSITION into w move to MOVPBUF(B1) get byte of OPOSITION into w move to MOVPBUF(B2) get byte of OPOSITION into w move to MOVPBUF(B3) get add get add get add lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of of MOVVAL into w of MOVPBUF+B1, save MOVVAL into w MOVPBUF+B1, save in MOVVAL into w MOVPBUF+B1, save in
; decrement by one use DEC16 ; get lowest byte of MOVTMP into w ; add lowest byte of PH2FLAT, save in
DS00532B-page 56
4-240
; begin speed down section ; ; ; ; ; ; get byte of AL into w move to A(B0) get byte of AL into w move to A(B1) get byte of AL into w move to A(B2)
4
3
lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of 4th byte of 4th byte of
DS00532B-page 57
4-241
044E 2994 044F 8D93 0450 0451 0452 0453 0454 0455 0456 0457 0458 0459 045A 6A67 016E 6A68 016F 6A5F 0860 0861 0862 330A C45B 8E93
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
move unless the final velocity get byte of MOVVAL into w move to MOVVBUF(B0) get byte of MOVVAL into w move to MOVVBUF(B1) get byte of MOVVAL into w move to MOVVBUF(B2) get byte of MOVVAL into w move to MOVVBUF(B3) is zero. clear MOVFLAG clear move in progress flag get byte of MOVTIME into w move to TAU(B0) get byte of MOVTIME into w move to TAU(B1)
DS00532B-page 58
4-242
of MOVVBUF into w of MOVPBUF, save in MOVVBUF into w MOVPBUF, save in MOVVBUF into w MOVPBUF, save in MOVVBUF into w MOVPBUF, save in
4
3
; ; ; ; ; ; ; ; ; ; ; ; ;
; V(k)=V(k-1)+A lowest byte of A into w lowest byte of MOVVBUF, save in 2nd byte of A into w 2nd byte of MOVVBUF, save in 3rd byte of A into w 3rd byte of MOVVBUF, save in 4th byte of A into w 4th byte of MOVVBUF, save in
compute A/2 move A(B0) to move A(B1) to move A(B2) to move A(B3) to
; ; ; ; ; ; ; ;
; P(k)=P(k-1)+V(k-1)+A/2, lowest byte of MOVTMP into w lowest byte of MOVPBUF, save in 2nd byte of MOVTMP into w 2nd byte of MOVPBUF, save in 3rd byte of MOVTMP into w 3rd byte of MOVPBUF, save in 4th byte of MOVTMP into w 4th byte of MOVPBUF, save in )
0489 0002
DS00532B-page 59
4-243
;******************************************************************* ;***************************************************************** ; NAME: undoPosVel ; ; DESCRIPTION: Backward iteration of the equations for trapezoidal ; generation ; ; V(k-1)=V(k)-A, P(k-1)=P(k)-V(k-1)-A/2, ; ; where abs(A)={AL,0} depending on the region of the ; being executed. This routine is used to reverse a ; to be made beyond a decision point. ; undoPosVel SUB32 MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB MOVFP SUBWFB SUB32 MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB MOVFP SUBWFB MOVFP32 MOVFP MOVFP MOVFP MOVFP RRC32 RLCF RRCF RRCF RRCF RRCF SUB32 MOVFP SUBWF MOVFP SUBWFB MOVFP SUBWFB MOVFP SUBWFB return A,MOVVBUF A+B0,wreg MOVVBUF+B0 A+B1,wreg MOVVBUF+B1 A+B2,wreg MOVVBUF+B2 A+B3,wreg MOVVBUF+B3 ; ; ; ; ; ; ; ; ; V(k-1)=V(k)-A get lowest byte sub lowest byte get 2nd byte of sub 2nd byte of get 3rd byte of sub 3rd byte of get 4th byte of sub 4th byte of P(k)-V(k-1) get lowest byte sub lowest byte get 2nd byte of sub 2nd byte of get 3rd byte of sub 3rd byte of get 4th byte of sub 4th byte of compute A/2 move A(B0) to move A(B1) to move A(B2) to move A(B3) to
of A into w of MOVVBUF, save in A into w MOVVBUF, save in A into w MOVVBUF, save in A into w MOVVBUF, save in
MOVVBUF,MOVPBUF ; MOVVBUF+B0,wreg ; MOVPBUF+B0 ; MOVVBUF+B1,wreg ; MOVPBUF+B1 ; MOVVBUF+B2,wreg ; MOVPBUF+B2 ; MOVVBUF+B3,wreg ; MOVPBUF+B3 ; A,MOVTMP A+B0,MOVTMP+B0 A+B1,MOVTMP+B1 A+B2,MOVTMP+B2 A+B3,MOVTMP+B3 MOVTMP MOVTMP+B3,W MOVTMP+B3 MOVTMP+B2 MOVTMP+B1 MOVTMP+B0 MOVTMP,MOVPBUF MOVTMP+B0,wreg MOVPBUF+B0 MOVTMP+B1,wreg MOVPBUF+B1 MOVTMP+B2,wreg MOVPBUF+B2 MOVTMP+B3,wreg MOVPBUF+B3 ; ; ; ; ;
of MOVVBUF into w of MOVPBUF, save in MOVVBUF into w MOVPBUF, save in MOVVBUF into w MOVPBUF, save in MOVVBUF into w MOVPBUF, save in
; ; ; ; ; ; ; ; ;
P(k-1)=P(k)-V(k-1)-A/2, get lowest byte of MOVTMP into w sub lowest byte of MOVPBUF, save in get 2nd byte of MOVTMP into w sub 2nd byte of MOVPBUF, save in get 3rd byte of MOVTMP into w sub 3rd byte of MOVPBUF, save in get 4th byte of MOVTMP into w sub 4th byte of MOVPBUF, save in
04AB 0002
DS00532B-page 60
4-244
;******************************************************************* ; NAME: doServo ; ; DESCRIPTION: Performs the servo loop calculations. ; doServo: MOV16 MOVFP MOVWF MOVFP MOVWF LOADAB MOVFP MOVFP MOVFP MOVFP call MOVPF32 MOVPF MOVPF MOVPF MOVPF clrf cpfsgt call LOADAB MOVFP MOVFP MOVFP MOVFP call ADD32 MOVFP ADDWF MOVFP ADDWFC MOVFP ADDWFC MOVFP ADDWFC POSERROR,U0 POSERROR+B0,wreg U0+B0 POSERROR+B1,wreg U0+B1 U0,KP U0+B0,AARG+B0 U0+B1,AARG+B1 KP+B0,BARG+B0 KP+B1,BARG+B1 Dmult DPX,Y DPX+B0,Y+B0 DPX+B1,Y+B1 DPX+B2,Y+B2 DPX+B3,Y+B3 wreg SATFLAG doIntegral INTEGRAL,KI INTEGRAL+B0,AARG+B0 INTEGRAL+B1,AARG+B1 KI+B0,BARG+B0 KI+B1,BARG+B1 Dmult DPX,Y DPX+B0,wreg Y+B0 DPX+B1,wreg Y+B1 DPX+B2,wreg Y+B2 DPX+B3,wreg Y+B3 ; save new position error in ; get byte of POSERROR into w ;move to U0(B0) ; get byte of POSERROR into w ; move to U0(B1) ; ; ; ; ; ; ; ; ; ; ; ; compute load lo load hi load lo load hi KP*U0 byte of byte of byte of byte of
4
3
04B0 04B1 04B2 04B3 04B4 04B5 04B6 04B7 04B8 04B9 04BA 04BB
7C84 7D85 7E26 7F27 E12B 5880 5981 5A82 5B83 290A 3295 E552
U0 U0 KP KP
to to to to
Y=KP*U0 move DPX(B0) to Y(B0) move DPX(B1) to Y(B1) move DPX(B2) to Y(B2) move DPX(B3) to Y(B3) if previous output saturated, do not accumulate integrator
; ; ; ; ;
KI*INTEGRAL byte of INTEGRAL to AARG byte of INTEGRAL to AARG byte of KI to BARG byte of KI to BARG
; ; ; ; ; ; ; ; ;
Y=KP*U0+KI*INTEGRAL get lowest byte of DPX into w add lowest byte of Y, save in Y(B0) get 2nd byte of DPX into w add 2nd byte of Y, save in Y(B1) get 3rd byte of DPX into w add 3rd byte of Y, save in Y(B2) get 4th byte of DPX into w add 4th byte of Y, save in Y(B3)
MOVFP16 U0,AARG MOVFP U0+B0,AARG+B0 MOVFP U0+B1,AARG+B1 SUB16 MOVFP SUBWF MOVFP SUBWFB U1,AARG U1+B0,wreg AARG+B0 U1+B1,wreg AARG+B1
; ; ; ;
DS00532B-page 61
4-245
; if not, zero 6 bits ; if so, set Y=0x007FFFFF ; clear for debug purposes
DS00532B-page 62
4-246
4
3
; ; ; ; ; ; get lowest byte of TMP into w add lowest byte of YPWM, save in YPWM(B0) get 2nd byte of TMP into w add 2nd byte of YPWM, save in YPWM(B1) correct by 1 LSB add one to bit5 of pw1dcL
; ; ; ;
of TMP into w of YPWM, save in YPWM(B0) TMP into w YPWM, save in YPWM(B1)
DS00532B-page 63
4-247
return ;************************************************************** ;*************************************************************** ; NAME: doIntegral ; ; DESCRIPTION: Evaluates the integral for the servo calculations. ; doIntegral ADD16 U0,INTEGRAL U0+B0,wreg INTEGRAL+B0 U0+B1,wreg INTEGRAL+B1 ; do integral ; ; ; ; get add get add lowest byte lowest byte 2nd byte of 2nd byte of of U0 into w of INTEGRAL, save in U0 into w INTEGRAL, save in
0556 0002
;**************************************************************** endif if _SERIAL_IO include serial.asm ; Serial I/O Routines ;****************************************************************** ; ; Serial I/O & Utility Functions ; ;****************************************************************
;****************************************************************** ; NAME: IdleFunction ; DESCRIPTION: ; ; IdleFunction 0557 0004 0558 0002 CLRWDT return ;**************************************************************** ;**************************************************************** ; NAME: DoCommand This routine will perform work while doing waits in serial I/O functions.
DS00532B-page 64
4-248
055D AB3A
4
3
;************************************************************************** ;*************************************************************************** ; NAME: do_null ; ; DESCRIPTION: The do nothing command used to determine if the chip is ; working. Initiated by a carriage return. do_null 0570 B021 0571 C56A movlw goto CMD_OK cmdFinish
;************************************************************************** ;************************************************************************** ; NAME: do_move ; DESCRIPTION: ; ; ; ; ; ; ; ; Commands the axis to move to a new position or velocity. Position data is relative, and in encoder counts. Velocity data is absolute, and in encoder counts/sample time multiplied by 256. All moves are performed by the controller such that velocity and acceleration limits set into parameter memory will not be violated. All move commands are kept in a one deep FIFO buffer. The command in the buffer is executed as soon as the currently executed command is complete.
DS00532B-page 65
4-249
DECIO GetDecVal
;************************************************************************** ;************************************************************************** ; NAME: do_mode ; ; DESCRIPTION: An argument of P will cause all subsequent move commands ; to be incremental position moves. A V argument will cause ; all subsequent moves to be absolute velocity moves. ; ; ARGUMENTS: O [P,V] ; do_mode 0580 0581 0582 0583 0584 0585 0586 0587 0588 0589 058A 058B 058C 058D 058E 058F 0590 0591 0592 0593 E557 E681 31C2 C580 E676 4A4D 2991 testP B050 314D C58B C598 testV B056 314D C590 1591 C598 testT B054 314D C596 2B91 movlw cpfseq goto setf T STRVALL modeerror MODETYPE ; TORQUE Moves for type T movlw cpfseq goto incf goto V STRVALL testT MODETYPE modeok ; velocity moves for type V movlw cpfseq goto goto P STRVALL testV modeok ; position moves for type P call call cpfseq goto call movpf clrf IdleFunction GetChk ONE do_mode GetChar wreg,STRVALL MODETYPE ; get single character loop
DS00532B-page 66
4-250
; mode error
;*************************************************************************** ;*************************************************************************** ; NAME: do_setparameter ; ; DESCRIPTION: Sets controller parameters to the value given. ; ; Parameter # Range ; ; VL=velocity limit 0 [0,7FFFFF] ; AL=acceleration limit 1 [0,7FFFFF] ; ; KP=proportional gain 2 [8000,7FFF] ; KP=velocity gain 3 [8000,7FFF] ; KP=integral gain 4 [8000,7FFF] ; ; IM=integrator mode 5 [0,3] ; ; FV=velocity FF 6 [8000,7FFF] : Not Imple ; FA=acceleration FF 7 [8000,7FFF] : Not Imple ; ; ; ARGUMENTS: S [0,FF] [800000,7FFFFF] ; do_setparameter 059C E669 059D B008 059E 3031 059F C5C1 05A0 05A1 05A2 05A3 B07C 4A0D B007 4A0E call movlw cpfslt goto movlw movpf movlw movpf tablrd setNextPar 05A5 A23D 05A6 A93E 05A7 A93F 05A8 B008 05A9 303D 05AA C5C1 05AB 6A3D 05AC 3131 05AD C5A5 05AE 6A3F 05AF 690A tlrd tablrd tablrd movlw cpfslt goto movfp cpfseq goto movfp movfp 1,PARTEMP 0,1,PARLEN 0,1,PARPTR NUMPAR PARTEMP Serror PARTEMP,wreg VALBUF+B0 setNextPar PARPTR,wreg wreg,fsr1 ; pointer to parameter in fsr1 ; read entry from table GetPar NUMPAR VALBUF+B0 Serror (PAR_TABLE & 0xff) wreg,tblptrl page PAR_TABLE wreg,tblptrh 1,1,PARTEMP ; get parameter number ; check if in range [0,NUMPAR]
4
3
05A4 AB3D
DS00532B-page 67
4-251
movlw goto
CMD_BAD cmdFinish
;************************************************************************** ;************************************************************************** ; NAME: do_readparameter ; ; DESCRIPTION: Returns the present value of a parameter. ; ; ARGUMENTS: R [0,FF] ; ; RETURNS: The present value of the requested parameter is returned. do_readparameter 05C3 E669 05C4 B008 05C5 3031 05C6 C5EB 05C7 05C8 05C9 05CA B07C 4A0D B007 4A0E call movlw cpfslt goto movlw movpf movlw movpf tablrd readNextPar 05CC A23D tlrd 1,PARTEMP ; read entry from table GetPar NUMPAR VALBUF+B0 Rerror (PAR_TABLE & 0xff) wreg,tblptrl page PAR_TABLE wreg,tblptrh 1,1,PARTEMP ; get parameter number ; check if in range [0,NUMPAR]
05CB AB3D
DS00532B-page 68
4-252
movlw VALBUF movfp wreg,fsr0 AUTOINC BSF BCF BSF BCF CLR24 _fs0 _fs1 _fs2 _fs3 VALBUF VALBUF+B0 VALBUF+B1 VALBUF+B2
4
3
; no autoincrement BSF BSF BSF BSF if _fs0 _fs1 _fs2 _fs3 DECIO PutDecVal ; send parameter value
05E8 E728
PutVal
movlw goto
CMD_OK cmdFinish
movlw goto
CMD_BAD cmdFinish
;*************************************************************************** ;************************************************************************** ; NAME: do_shutter ; ; DESCRIPTION: Returns the time (in sample time counts [0,FFFF]) since the ; start of the present move and captures the commanded and ; measured values of position and velocity at the time of the ; command.
DS00532B-page 69
4-253
MOV24 05F3 05F4 05F5 05F6 05F7 05F8 6A58 4A43 6A59 4A44 6A5A 4A45 MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF
; capture commanded velocity ; ; ; ; ; ; get byte of VELOCITY into w move to CVELOCITY(B0) get byte of VELOCITY into w move to CVELOCITY(B1) get byte of VELOCITY into w move to CVELOCITY(B2)
MOV24 05F9 05FA 05FB 05FC 05FD 05FE 6A72 4A46 6A73 4A47 6A74 4A48 MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF
; capture measured position ; ; ; ; ; ; get byte of MPOSITION into w move to CMPOSITION(B0) get byte of MPOSITION into w move to CMPOSITION(B1) get byte of MPOSITION into w move to CMPOSITION(B2)
MOV24 05FF 0600 0601 0602 0603 0604 6A75 4A49 6A76 4A4A 6A77 4A4B MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF clrf MOV16 MOVFP MOVWF MOVFP MOVWF if 060A E728 call else call endif 060B B021 060C C56A movlw goto
MVELOCITY,CMVELOCITY MVELOCITY+B0,wreg wreg,CMVELOCITY+B0 MVELOCITY+B1,wreg wreg,CMVELOCITY+B1 MVELOCITY+B2,wreg wreg,CMVELOCITY+B2 VALBUF+B2 MOVTIME,VALBUF MOVTIME+B0,wreg VALBUF+B0 MOVTIME+B1,wreg VALBUF+B1 DECIO PutDecVal
; capture measured velocity ; ; ; ; ; ; get byte of MVELOCITY into w move to CMVELOCITY(B0) get byte of MVELOCITY into w move to CMVELOCITY(B1) get byte of MVELOCITY into w move to CMVELOCITY(B2)
0605 2933
; capture move time, move to VALBUF ; ; ; ; get byte of MOVTIME into w move to VALBUF(B0) get byte of MOVTIME into w move to VALBUF(B1)
PutVal
CMD_OK cmdFinish
DS00532B-page 70
4-254
4
3
;*************************************************************************** ;*************************************************************************** ; NAME: do_readcomvelocity ; ; DESCRIPTION: Returns the commanded velocity multiplied by 256 which was ; captured during the last shutter command. ; ; ARGUMENTS: V ; ; RETURNS: The last captured commanded velocity times 256 is returned. ; [800000,7FFFFF] ; do_readcomvelocity MOV24 0616 0617 0618 0619 061A 061B 6A43 4A31 6A44 4A32 6A45 4A33 MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF if 061C E728 call else call PutVal CVELOCITY,VALBUF CVELOCITY+B0,wreg wreg,VALBUF+B0 CVELOCITY+B1,wreg wreg,VALBUF+B1 CVELOCITY+B2,wreg wreg,VALBUF+B2 DECIO PutDecVal ; move commanded velocity to VALBUF ; ; ; ; ; ; get byte of CVELOCITY into w move to VALBUF(B0) get byte of CVELOCITY into w move to VALBUF(B1) get byte of CVELOCITY into w move to VALBUF(B2)
DS00532B-page 71
4-255
;************************************************************************** ;************************************************************************** ; NAME: do_readactposition ; ; DESCRIPTION: Returns the measured position count which was captured ; during the last shutter command. ; ; ARGUMENTS: p ; ; RETURNS: The last captured measured position count is returned. ; [800000,7FFFFF] ; do_readactposition MOV24 061F 0620 0621 0622 0623 0624 6A46 4A31 6A47 4A32 6A48 4A33 CMPOSITION,VALBUF MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF if 0625 E728 call else call endif 0626 B021 0627 C56A movlw goto CMD_OK cmdFinish PutVal CMPOSITION+B0,wreg wreg,VALBUF+B0 CMPOSITION+B1,wreg wreg,VALBUF+B1 CMPOSITION+B2,wreg wreg,VALBUF+B2 DECIO PutDecVal ; move measured position to ; ; ; ; ; ; get byte of CMPOSITION into w move to VALBUF(B0) get byte of CMPOSITION into w move to VALBUF(B1) get byte of CMPOSITION into w move to VALBUF(B2)
;************************************************************************** ;************************************************************************** ; NAME: do_readactvelocity ; ; DESCRIPTION: Returns the measured velocity multiplied by 256 which was ; captured during the last shutter command. ; ; ARGUMENTS: v ; ; RETURNS: The last captured measured velocity times 256 is returned. ; [800000,7FFFFF] ; do_readactvelocity MOV24 0628 0629 062A 062B 062C 062D 6A49 4A31 6A4A 4A32 6A4B 4A33 MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF CMVELOCITY,VALBUF CMVELOCITY+B0,wreg wreg,VALBUF+B0 CMVELOCITY+B1,wreg wreg,VALBUF+B1 CMVELOCITY+B2,wreg wreg,VALBUF+B2 ; move measured velocity to ; ; ; ; ; ; get byte of CMVELOCITY into w move to VALBUF(B0) get byte of CMVELOCITY into w move to VALBUF(B1) get byte of CMVELOCITY into w move to VALBUF(B2)
DS00532B-page 72
4-256
;*************************************************************************** ;*************************************************************************** ; NAME: do_externalstatus ; ; DESCRIPTION: Returns a two digit hex number which defines the state of ; the bits in the external status register. Issuing this ; command will clear all the bits in the external status ; register unless the event which set the bit is still true. ; ; ; ARGUMENTS: X ; ; RETURNS: The external status register is returned. ; do_externalstatus 0631 0632 0633 0634 0635 8406 6A92 2992 8C06 E688 bsf movfp clrf bcf call movlw goto _glintd EXTSTAT,wreg EXTSTAT _glintd PutHex CMD_OK cmdFinish
4
3
;*************************************************************************** ;*************************************************************************** ; NAME: do_movestatus ; ; DESCRIPTION: Returns a two digit hex number which defines the state of ; the bits in the move status register. Issuing this command ; will clear all the bits in the move status register unless ; the event which set the bit is still true. ; ; ARGUMENTS: Y ; ; RETURNS: The move status register is returned. ; do_movestatus 0638 6A93 0639 E688 063A B021 063B C56A movfp call movlw goto MOVSTAT,wreg PutHex CMD_OK cmdFinish
DS00532B-page 73
4-257
;*************************************************************************** ;*************************************************************************** ; NAME: do_setposition ; ; DESCRIPTION: Sets the measured and commanded position to the value given. ; This command should not be sent unless the move FIFO buffer ; ; ARGUMENTS: H [800000,7FFFFF] ; do_setposition if 0645 E6CC call else call endif MOV24 0646 0647 0648 0649 064A 064B 6A31 4A55 6A32 4A56 6A33 4A57 MOVFP MOVPF MOVFP MOVPF MOVFP MOVPF VALBUF,POSITION VALBUF+B0,wreg wreg,POSITION+B0 VALBUF+B1,wreg wreg,POSITION+B1 VALBUF+B2,wreg wreg,POSITION+B2 ; ; ; ; ; ; get byte of VALBUF into w move to POSITION(B0) get byte of VALBUF into w move to POSITION(B1) get byte of VALBUF into w move to POSITION(B2) GetVal DECIO GetDecVal
DS00532B-page 74
4-258
;*************************************************************************** ;*************************************************************************** ; NAME: do_reset ; ; DESCRIPTION: Performs a software reset. ; ; ARGUMENTS: Z ; do_reset 0658 B021 0659 E679 065A C021 movlw call goto CMD_OK PutChar Startup
4
3
;*************************************************************************** ; NAME: do_stop ; ; DESCRIPTION: Stops servo by clearing SERVOFLAG. ; do_stop 065B 2990 065C B021 065D C56A clrf movlw goto SERVOFLAG CMD_OK cmdFinish
;*************************************************************************** ;*************************************************************************** ; NAME: do_capture ; do_capture if 065E E6CC endif if ((_PICMASTER_DEBUG == 1) && (DECIO == 0)) call endif if _PICMASTER_DEBUG == 1 GetVal ((_PICMASTER_DEBUG == 1) && (DECIO == 1)) call GetDecVal
DS00532B-page 75
4-259
0671 E6B2 0672 6A31 0673 0E4E 0674 4A31 0675 0002
DS00532B-page 76
4-260
4
3
;*************************************************************************** ;*************************************************************************** ; NAME: PutDec ; ; DESCRIPTION: Converts a hex value [0,F] in wreg to its ASCII equivalent. ; The upper nibble of wreg is assumed to be zero. ; ; ENTRY CONDITIONS: wreg = value to be converted and sent in ASCII decimal ; if PutDec 0685 B130 0686 E679 0687 0002 addlw call return endif ;*************************************************************************** ;*************************************************************************** ; NAME: PutHex ; ; DESCRIPTION: Convert the wreg value to ASCII hexadecimal. The output ; format is two digits with the A-F parts in upper case and ; leading zeros. The result is sent out the serial port with ; PutChar. ; ; ENTRY CONDITIONS: wreg = value to be converted and sent in ASCII hex ; PutHex 0x30 PutChar ; convert to ASCII DECIO
DS00532B-page 77
4-261
06A5 A24C 06A6 A94D 06A7 06A8 06A9 06AA 6A4C 31C1 C6AB 0002
;************************************************************************** ;***************************************************************************
DS00532B-page 78
4-262
4
3
;***************************************************************************
;*************************************************************************** ; NAME: getval ; ; DESCRIPTION: Get a value [800000,7FFFFF] from the serial port and place ; it in VALBUF. ; if DECIO else GetVal CLR24 getnext call movlw cpfseq goto return shift swapf movfp VALBUF+B2 VALBUF+B2,wreg GetHex 0x01 HEXSTAT shift VALBUF
DS00532B-page 79
4-263
06D4 E708 06D5 06D6 06D7 06D8 B002 3199 C6D9 C6FD
DS00532B-page 80
4-264
4
3
lowest byte lowest byte 2nd byte of 2nd byte of 3rd byte of 3rd byte of
of DVALBUF into of VALBUF, save DVALBUF into w VALBUF, save in DVALBUF into w VALBUF, save in
w in VALBUF(B1) VALBUF(B2)
06FC C6D4
0707 0002
DS00532B-page 81
4-265
IdleFunction GetChk ONE getdecnxt GetChar wreg,DECVAL PutChar CR DECVAL,W ZERO gtdCR MN DECVAL,W ZERO gtdMN SP DECVAL,W ZERO gtdSP
070C E676 070D 4A98 070E E679 070F 0710 0711 0712 0713 0714 0715 0716 0717 0718 0719 071A B00D 0498 30C1 C71F B02D 0498 30C1 C722 B020 0498 30C1 C725
;*************************************************************************** ; NAME: PutVal ; ; DESCRIPTION: Sends the value in VALBUF [800000,7FFFFF] out the serial ; if else PutVal DECIO
DS00532B-page 82
4-266
4
3
0731 B02D 0732 E679 0733 C736 pdpos 0734 B020 0735 E679 pddigits 0736 0737 0738 0739 B08D 4A0D B007 4A0E
movlw movpf movlw movpf tablrd readNextDec tlrd tablrd tablrd setf cpfseq goto goto getdigit incf setf inc incf SUB24 MOVFP SUBWF
073A A934
073B A034 073C AB35 073D A936 073E 073F 0740 0741 2B0A 3134 C742 C756
0,DVALBUF+B0 1,1,DVALBUF+B1 0,1,DVALBUF+B2 wreg DVALBUF+B0 getdigit unitsposition DVALBUF+B0 DECVAL DECVAL DVALBUF,VALBUF DVALBUF+B0,wreg VALBUF+B0
; restore to power of 10 ; set DECVAL to -1 ; increment DECVAL ; check if in range ; get lowest byte of DVALBUF into w ; sub lowest byte of VALBUF, save in
DS00532B-page 83
4-267
endif ;***************************************************************************
;*************************************************************************** ; ; ; TABLES:
CMD_START CMD_TABLE CMD_TABLE CMD_DEF do_null,DO_NULL 0759 000D 075A 0570 DATA DATA DO_NULL do_null
CMD_DEF do_move,DO_MOVE 075B 004D 075C 0572 DATA DATA DO_MOVE do_move
CMD_DEF do_mode,DO_MODE 075D 004F 075E 0580 DATA DATA DO_MODE do_mode
CMD_DEF do_setparameter,DO_SETPARAMETER 075F 0053 0760 059C DATA DATA DO_SETPARAMETER do_setparameter
CMD_DEF do_readparameter,DO_READPARAMETER 0761 0052 0762 05C3 DATA DATA DO_READPARAMETER do_readparameter
DS00532B-page 84
4-268
CMD_DEF do_readcomposition,DO_READCOMPOSITION 0765 0050 0766 060D DATA DATA DO_READCOMPOSITION do_readcomposition
CMD_DEF do_readcomvelocity,DO_READCOMVELOCITY 0767 0056 0768 0616 DATA DATA DO_READCOMVELOCITY do_readcomvelocity
CMD_DEF do_readactposition,DO_READACTPOSITION 0769 0070 076A 061F DATA DATA DO_READACTPOSITION do_readactposition
CMD_DEF do_readactvelocity,DO_READACTVELOCITY 076B 0076 076C 0628 DATA DATA DO_READACTVELOCITY do_readactvelocity
4
3
CMD_DEF do_externalstatus,DO_EXTERNALSTATUS 076D 0058 076E 0631 DATA DATA DO_EXTERNALSTATUS do_externalstatus
CMD_DEF do_movestatus,DO_MOVESTATUS 076F 0059 0770 0638 DATA DATA DO_MOVESTATUS do_movestatus
CMD_DEF do_readindposition,DO_READINDPOSITION 0771 0049 0772 063C DATA DATA DO_READINDPOSITION do_readindposition
CMD_DEF do_setposition,DO_SETPOSITION 0773 0048 0774 0645 DATA DATA DO_SETPOSITION do_setposition
CMD_DEF do_reset,DO_RESET 0775 005A 0776 0658 DATA DATA DO_RESET do_reset
CMD_DEF do_stop,DO_STOP 0777 0073 0778 065B if DATA DATA DO_STOP do_stop
DS00532B-page 85
4-269
PAR_TABLE
DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DECIO DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA
if 078D 078E 078F 0790 0791 0792 0793 0794 0795 0796 0797 0798 0799 423F 000F 869F 0001 270F 0000 03E7 0000 0063 0000 0009 0000 FFFF DEC_TABLE
0x423F 0x000F 0x869F 0x0001 0x270F 0x0000 0x03E7 0x0000 0x0063 0x0000 0x0009 0x0000 0xFFFF
endif
endif if _PICMASTER_DEBUG include picmastr.asm ; PIC-MASTER Debug (data capture) File 0x8000 ; addr for dummy Table Writes (to TRACE
0060
#define CaptureAddr
;*************************************************************************** ; NAME: doCaptureRegs ; ; DESCRIPTION: Captures Desired Register Values To PIC-MASTER Trace Buffer ; Intended for PICMASTER Demo/debug/servo tuning Purposes Only ; Capture The following registers to Trace Buffer by putting ; A Trace point on a TABLW instruction. Trace only 2nd Cycle ; ; (a) POSERROR (position error : 16 bits) ; (b) VELERROR (velocity error : 16 bits) ; (c) MPOSITION (measured position value : 24 bits) ; (d) MVELOCITY (measured velocity value : 24 bits) ; (e) POSITION (commanded position : 24 bits) ; (f) VELOCITY (commanded velocity : 24 bits) ; (g) Y (output of servo loop : 32 bits) ; (h) YPWM (output value written to PWM : 10 bits) ; ; ; doCaptureRegs ; !end! hdr !skip start! movlw (CaptureAddr & 0xff) movwf tblptrl movlw CaptureAddr/256
DS00532B-page 86
4-270
tablwt tlwt
0,0,VELERROR+B0 1,VELERROR+B1
4
; capture measured velocity
07BB 29BB
CAPFLAG CAPCOUNT,CAPTMP
MOVFP CAPCOUNT+B0,wreg ; get byte of CAPCOUNT into w MOVWF CAPTMP+B0 ; move to CAPTMP(B0) MOVFP CAPCOUNT+B1,wreg ; get byte of CAPCOUNT into w MOVWF CAPTMP+B1 ; move to CAPTMP(B1) return ;************************************************************************* end END
Errors : Warnings :
0 0
DS00532B-page 87
4-271
DS00532B-page 88
4-272
AMERICAS (continued)
San Jose Microchip Technology Inc. 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408 436-7950 Fax: 408 436-7955
EUROPE
United Kingdom Arizona Microchip Technology Ltd. Unit 6, The Courtyard Meadow Bank, Furlong Road Bourne End, Buckinghamshire SL8 5AJ Tel: 44 0 1628 851077 Fax: 44 0 1628 850259 France Arizona Microchip Technology SARL 2 Rue du Buisson aux Fraises 91300 Massy - France Tel: 33 1 69 53 63 20 Fax: 33 1 69 30 90 79 Germany Arizona Microchip Technology GmbH Gustav-Heinemann-Ring 125 D-81739 Muenchen, Germany Tel: 49 89 627 144 0 Fax: 49 89 627 144 44 Italy Arizona Microchip Technology SRL Centro Direzionale Colleoni Palazzo Pegaso Ingresso No. 2 Via Paracelso 23, 20041 Agrate Brianza (MI) Italy Tel: 39 039 689 9939 Fax: 39 039 689 9883
ASIA/PACIFIC
Hong Kong Microchip Technology Unit No. 3002-3004, Tower 1 Metroplaza 223 Hing Fong Road Kwai Fong, N.T. Hong Kong Tel: 852 2 401 1200 Fax: 852 2 401 3431 Korea Microchip Technology 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku, Seoul, Korea Tel: 82 2 554 7200 Fax: 82 2 558 5934 Singapore Microchip Technology 200 Middle Road #10-03 Prime Centre Singapore 188980 Tel: 65 334 8870 Fax: 65 334 8850 Taiwan Microchip Technology 10F-1C 207 Tung Hua North Road Taipei, Taiwan, ROC Tel: 886 2 717 7175 Fax: 886 2 545 0139
JAPAN
Microchip Technology Intl. Inc. Benex S-1 6F 3-18-20, Shin Yokohama Kohoku-Ku, Yokohama Kanagawa 222 Japan Tel: 81 45 471 6166 Fax: 81 45 471 6122 9/22/95