AN696
DS00696A-page 10 Preliminary 2000 Microchip Technology Inc.
Stand-alone Operation
The provided application firmware allows the servo-
motor to perform a few basic motions without a PC con-
nected. Specifically, data for three different motion
profiles are stored in the MCU program memory and
are loaded into data memory at start-up. Each profile is
selected by turning on DIP switch #2, #3, or #4, con-
nected to PORTB and pressing the MCLR
button.
The software polls the DIP switches once, at start-up,
to see if a profile should be executed. The selected pro-
file will begin to execute immediately. If DIP switch #1
is turned on in combination with one of the other
switches, the selected profile will execute repeatedly.
PICmicro MCU RESOURCES
There is a broad range of PICmicro devices that can be
used to implement the servomotor application, depend-
ing on the level of performance that you need. To begin
with, let’s consider the processing time needed by the
servo calculations.
A large amount of time is spent in the servo calcula-
tions executing the compensator, which requires one or
more multiplications depending on the type of algorithm
used. Three 16 x 16 signed multiplications are required
by the PID compensator algorithm used here. Since the
servo update calculations must be performed fre-
quently, a hardware multiplier can provide a significant
reduction in the MCU bandwidth. With a 8 x 8 hardware
multiplier, each 16 x 16 multiplication can be performed
in approximately 32 instruction cycles. Without the
hardware multiplier, each multiplication can take 500
instruction cycles or more, depending on the algorithm
that is used.
The servo calculation times were compared for the
PIC16CXXX and PIC18CXXX architectures, using the
same source code. Table 2 shows the performance
results. You can easily see the increase in available
bandwidth gained by the hardware multiplier. For a
given servo update period, the hardware multiplier in
the PIC18CXXX architecture frees a large amount of
MCU bandwidth for performing other tasks. In addition,
extra MCU bandwidth may be obtained from the
PIC18CXXX architecture, since the devices may be
operated up to 40 MHz.
Table 3 and Table 4 show a comparison of memory
usage by the servomotor application, for both the
16F877 and the 18C452. Depending on the memory
requirements for motion profile segment data and other
application functions, the design may be adapted for
other MCUs. As an example of a minimal implementa-
tion, this application could be modified to operate on a
PIC16C73B. The PIC16C73B has 22 I/O pins, 4K x 14
words of program memory, and 192 bytes of data
memory.
The resolution of the available timer resources must be
considered when using the position sensing method
described here. The maximum RPM of the servomotor
is a function of the timer resolution, servo update fre-
quency, and the resolution of the incremental encoder.
Because two’s complement arithmetic is used to find
the motor position, the timers used to accumulate the
encoder pulses should not increment more than 2
N-1
counts during each servo update interval, or position
information will be lost.
When a PIC16CXXX device is used for the servomotor
application, Timer0 and Timer1 are the only timers with
an external clock input and Timer0 has only 8 bits of
resolution. For some cases, this may limit the maxi-
mum motor RPM. A formula that can be used to calcu-
late the maximum RPM is given in Equation 1 below:
EQUATION 1: MAXIMUM RPM
In this equation, N represents the resolution of the timer
in bits, f
S
, is the servo update frequency, and CPR is
the resolution of the encoder. The incremental encoder
used in this application provides 500 CPR. For the
moment, let’s assume that our servo update frequency
is 1000 Hz. Using 1x decoding, the maximum RPM that
we can permit without a timer overflow, is over 15,000
RPM. This maximum limit is of no concern for us, since
the motor we are using provides a no-load speed of
6000 RPM. Now, let’s assume that a 4x decoding
method was used, so that our encoder now provides
2000 CPR. Now, the maximum motor speed is 3840
RPM, which is definitely a problem! In this case, the
servo update frequency would have to be increased, if
possible, or the encoder resolution decreased.
RPM
MAX
=
2
N-1
f
s
60
CPR