AN155
8 Rev. 1.1
In contrast the linear-acceleration profile is much more
complex. A single fixed table cannot be used. The initial
conditions of each acceleration phase depend on the
length of all prior phases.
The recommended solution is to always start out using
a properly implemented linear-velocity profiler. This will
be the best solution for most applications. Verify that the
velocity is actually linear and evaluate the dynamic
response of the system. If the dynamic response of the
system does not meet the requirements, consider using
a linear-acceleration profile.
3.8. Interrupt Based Algorithm
When developing an algorithm to control a stepper
motor using a small microcontroller, it is important to
consider the manner in which the code will be executed.
A simple sequential algorithm could accomplish the
task. The sequential algorithm might calculate the
current step time and figure out what to do next
depending on the acceleration phase. However, such
an algorithm would end up writing to the timer and then
waiting until the timer times out. It would spend most of
the time just waiting on the timer.
Fortunately most MCU timers are capable of generating
interrupts. Thus, we can set up the timer to generate an
interrupt after one step period. When the interrupt
occurs, the MCU should commutate the motor and
update the timer with the next step period.
Now considering that we want to make the stepper
motor control interrupt based, we must use a different
paradigm. The timer interrupt service routine should be
small, fast, robust, and only do what must be done on
each commutation period. Anything that can be
calculated once beforehand will be done outside the
interrupt service routine. Values may be stored in global
variables to be accessed by the interrupt service
routine.
Using this scheme there are two basic pieces of code.
The first is the profiler or the move() function. The
second is the timer interrupt service routine. The profiler
is called from the main loop and is executed in the
foreground. The profiler calculates the global variables
based on the target location and the current position of
the motor. The function is named move() so that the
user code makes sense in plain English.
This reference design uses a simple divide-by-four
profiler. This means that the total number of steps is
divided by four. The motor will accelerate and
decelerate for one forth of the total number of steps.
The remainder of the steps will be at a constant velocity.
Some actual profiles are shown in Figure 5. Note that
the total time accelerating for short profiles is much
more that one-forth the total time. This is due to the
effect of the variable step period.
The constant-acceleration and deceleration phases are
accomplished by incrementing and decrementing an
index for the stepper motor table. Incrementing the table
index by one each step will accelerate the motor.
Decrementing the index each step will decelerate the
motor. The maximum index and the corresponding
minimum period determine the top speed of the motor
for a particular profile.
4. Hardware Design
The Stepper motor reference design hardware consists
of four sections: the C8051F300 microcontroller, the
power electronics, the voltage regulator, and the serial
interface. The full schematic is included in Appendix A.
The Bill of Materials is in Appendix B and the printed
circuit board artwork is in Appendix C.
4.1. Microcontroller
The reference design features the C8051F300
microcontroller. This microcontroller is housed in a tiny
3 mm by 3 mm 11-lead micro lead package (MLP). This
package is small enough to be integrated into the
smallest motor. The C8051F30x family includes five
devices with various options. The ‘F300 and ‘F301
include a calibrated internal oscillator. The internal
oscillator is calibrated to within
±2% at test. This is
close enough to use the internal oscillator for the UART
with baud rates up to 115.2 kbps. The reference design
does not utilize 8-bit 500 ksps ADC in the ‘F300. Thus,
the design could use either the ‘F300 or the ‘F301 which
does not include the ADC. The ADC on the F300 might
prove useful in some designs for monitoring the dc
motor voltage, stepper motor current, or the stepper
motor temperature.
The unipolar stepper motor drive requires four outputs
to drive the transistors. P0.0 through pin P0.3 are used
to drive the power MOSFETs. The pins have been
ω
τ
ω
time
Figure 5. Different Profiles