AN857
DS00857A-page 16 2002 Microchip Technology Inc.
The first reading is taken during drive phase 4 when ter-
minal A is actively driven high. This is the applied volt-
age. The next two readings are taken during drive
phase 5 when terminal A is floating. The first reading is
taken when ¼ of the commutation time has elapsed
and the second reading is taken when ¾ of the commu-
tation time has elapsed. We'll call these readings 1 and
2 respectively. The commutation table index is adjusted
according to the following relationship between the
applied voltage reading and readings 1 and 2:
• Index is unchanged if Reading 1 > Applied Volt-
age/2 and Reading 2 < Applied Voltage/2
• Index is increased if Reading 1 < Applied Voltage/
2
• Index is decreased if Reading 1 > Applied Volt-
age/2 and Reading 2 > Applied Voltage/2
The motor rotor and everything it is connected to has a
certain amount of inertia. The inertia delays the motor
response to changes in voltage load and commutation
time. Updates to the commutation time table index are
delayed to compensate for the mechanical delay and
allow the motor to catch up.
Acceleration and Deceleration Delay
The inertia of the motor and what it is driving, tends to
delay motor response to changes in the drive voltage.
We need to compensate for this delay by adding a
matching delay to the control loop. The control loop
delay requires two time constants, a relatively slow one
for acceleration, and a relatively fast one for decelera-
tion.
Consider what happens in the control loop when the
voltage to the motor suddenly rises, or the motor load
is suddenly reduced. The control senses that the motor
rotation is too slow and attempts to adjust by making
the commutation time shorter. Without delay in the con-
trol loop, the next speed measurement will be taken
before the motor has reacted to the adjustment, and
another speed adjustment will be made. Adjustments
continue to be made ahead of the motor response until
eventually, the commutation time is too short for the
applied voltage, and the motor goes out of lock. The
acceleration timer delay prevents this runaway condi-
tion. Since the motor can tolerate commutation times
that are too long, but not commutation times that are
too short, the acceleration time delay can be longer
than required without serious detrimental effect.
Consider what happens in the control loop when the
voltage to the motor suddenly falls, or the motor load is
suddenly increased. If the change is sufficiently large,
commutation time will immediately be running too short
for the motor conditions. The motor cannot tolerate this,
and loss of lock will occur. To prevent loss of lock, the
loop deceleration timer delay must be short enough for
the control loop to track, or precede the changing motor
condition. If the time delay is too short, then the control
loop will continue to lengthen the commutation time
ahead of the motor response resulting in over compen-
sation. The motor will eventually slow to a speed that
will indicate to the BEMF sensor that the speed is too
slow for the applied voltage. At that point, commutation
deceleration will cease, and the commutation change
will adjust in the opposite direction governed by the
acceleration time delay. Over compensation during
deceleration will not result in loss of lock, but will cause
increased levels of torque ripple and motor current until
the ideal commutation time is eventually reached.
Determining The Commutation Time
Table Values
The assembler supplied with MPLAB performs all cal-
culations as 32-bit integers. To avoid the rounding
errors that would be caused by integer math, we will
use a spreadsheet, such as Excel, to compute the table
entries then cut and paste the results to an include file.
The spreadsheet is setup as shown in Table 4.
TABLE 4: COMMUTATION TIME TABLE VALUES
Variable Name Number or Formula Description
Phases 12 Number of commutation phase changes in one
mechanical revolution.
FOSC 20 MHz Microcontroller clock frequency
F
OSC_4 FOSC/4 Microcontroller timers source clock
Prescale 4 Timer 1 prescale
MaxRPM 8000 Maximum expected speed of the motor at full
applied voltage
MinRPM (60*F
OSC_4)/Phases*Prescale*65535)+1 Limitation of 16-bit timer
Offset -345 This is the zero voltage intercept on the RPM axis.
A property normalized to the 8-bit A to D converter.
Slope (MaxRPM-Offset)/255 Slope of the RPM to voltage input response curve
normalized to the 8-bit A to D converter.