MOTOROLA
10
AN1215/D
S-record formatted object code can be loaded and run on the EVS using appropriate serial communications
software. The default EVS Baud rate is 19200 Baud.
A simple RC circuit is used to provide the feedback necessary for the software PID loop to operate. The
connections to the EVS are shown in
Figure 4
. PH0 is the processor PWM output and PE0 is the channel
1 A/D input. Note that the A/D reference inputs must be connected to appropriate supplies and the
SUP6(F(,IRQ)) line must also be tied high. A two-channel oscilloscope can be used to observe PWM output
and controlled voltage. Both versions of the code write $FF to PORTA just before performing PID loop cal-
culations and then write $00 to the port just after calculations are complete, allowing execution times to be
observed with a scope.
Figure 4 Evaluation System Schematic
PERFORMANCE
Since two very different approaches were taken to implement the PID loop algorithm, it is not surprising that
the performance and code sizes of the two routines differ significantly. The C language version contains
over 1500 bytes, much of which consists of floating point runtime support. Because it carries full floating-
point precision and does not use math support hardware, the C version takes approximately 6 milliseconds
to complete the loop. The assembly version contains approximately 1000 bytes, and could be reduced to
about 800 bytes if features added for clarity and experimentation were removed. Because it uses a tailored
arithmetic format and gets a hardware assist from the math coprocessor, the assembly version completes
the loop in approximately 700 microseconds. In both cases, performance could be improved by precomput-
ing all the results with constant factors.
EXPERIMENTS AND EXTENSIONS
To develop a more intuitive understanding of PID loop function, try varying the term constants in the object
code and observing the effect on controller performance. For the C version, it is best to change the values
in the C source and recompile. For the assembly version, it is easy to recalculate and change denominators
of the constants: only decimal-to-hex conversion is required. The PERDT constant must be changed when
the RTI interrupt rate is changed, or the time base of the algorithm will be destroyed. Try adjusting the pro-
portional and derivative constants to give good observable control and then start substituting smaller value
resistors for R1. Eventually, the substitution will cause an unstable underdamped system.
K4 EVS TEST AN1215
VRH
1 M
3.8 M
0.1
μ
F
P4
VRL
PE0
PH0
VSS
IRQ
P5
VDD
7
14
16
18
23
4.7 k
VDD
3.8 M
VSS
VSS
VDD