Unipolar Stepper Motor Driver
Unipolar Stepper Motor Driver
AN012805-0708
ing two phases), while the rotor poles are perma- Stepper motors feature stator windings that are
nent magnets comprised of soft alloy steel. wound in unipolar or bipolar fashion on any num-
ber of poles; the mechanical step size usually
ranges from 0.9° to 18°. In the unipolar mode of
operation, the current flow in the windings always
remains in the same direction to achieve rotor
movement. A bipolar mode, on the other hand,
involves an alternate reversal of the current flow in
N
the windings to achieve rotation.
AN012805-0708 Page 2 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
required. The reversal of direction in both cases is methods (as per Table 2) for a four-phase motor,
achieved by reversing the sequence only. and S4–S3–S2–S1 for the counterclockwise rota-
tion. The excitation scheme for the 2-ph On
The excitation method of the unipolar drive can be method requires 2 windings to be energized at the
a single-phase On (1-ph On) or a two-phase On (2- same time in an 8-sequence pattern.
ph On) operation. Table 3 shows the 1-ph On
method and Table 4 shows the 2-ph On method for The advantages of the 2-ph On method over the 1-
a four-phase wound motor. ph On method are higher torque and stable, smooth
rotations, due to the fact that two windings are
The excitation scheme is S1–S2–S3–S4 for the energized at a time. The half-step mode effectively
clockwise rotation in the 1-ph On and 2-ph On combines the 1-ph On and 2-ph On methods.
Anti-clockwise
Seq 1 1 0 1 0 Seq 1 1 0 1 0
Seq 2 1 0 0 1 Seq 2 1 0 0 0
Seq 3 0 1 0 1 Seq 3 1 0 0 1
Seq 4 0 1 1 0 Seq 4 0 0 0 1
Seq 5 0 1 0 1
Seq 6 0 1 0 0
Seq 7 0 1 1 0
Seq 8 0 0 1 0
1 2 3 4 5 6 7 8 Pulses 1 2 3 4 5 6 7 8
Wdg 1 1 0 0 0 1 0 0 0 Wdg 1 1 1 0 0 1 1 0 0
Wdg 2 0 1 0 0 0 1 0 0 Wdg 2 0 1 1 0 0 1 1 0
Wdg 3 0 0 1 0 0 0 1 0 Wdg 3 0 0 1 1 0 0 1 1
Wdg 4 0 0 0 1 0 0 0 1 Wdg 4 1 0 0 1 1 0 0 1
A better way to achieve higher resolution is by microstepping method is mainly used in applica-
using the microstepping method, in which a tions that require a greater degree of control for
mechanical step is subdivided into many steps. By precise movement, such as in X-Y table applica-
energizing the windings in various combinations, a tions.
required angular rotation can be executed. The
AN012805-0708 Page 3 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
However, the hardware in this Application Note is istics (in Figure 5) show the ability of the motor to
limited to the construction of a unipolar drive, and sustain rotation at a particular torque without los-
the software uses the 2-ph On method in both full- ing step synchronism.
step and half-step modes.
Torque
Pull-out torque
Pull-in torque
be applied on the shaft of an energized but stopped
motor without causing rotor slippage. The holding
torque and winding current relation is nearly linear, P2 P3
as shown in Figure 4, and the minimum amount of 0
Step Frequency (Hz)
torque on the Y-axis, appearing at zero current, is No start range
the detent torque.
No rotate range
Holding Torque
AN012805-0708 Page 4 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Step Rate (pps) The circuit consists of buffer transistors Q1, Q2,
Q3, and Q4 driving the power MOSFETs T1, T2,
T3, and T4, respectively. There are four buffer-
driver power MOSFET units on four GPIO pins
Figure 6. Typical Regions of Resonance that individually energize each of the four wind-
ings of the stepper motor.
These resonance frequencies must be avoided
when a drive is tuned for a particular motor. A Figure 8 presents a schematic diagram of a single
mechanical damper, illustrated in Figure 7, is cou- stage of the power driver.
pled to the motor shaft, and can be used to damp
the resonance points.
AN012805-0708 Page 5 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
VDD D5
1N4001
R17
1k,0.5W
T1 VDD
Q1 IRFZ44N
BC547 R5 ZD1
3k3 5V1
D1 LED1 R13
1N4148 1E,5W
R9
4k7
6
5
3
2
1
MG1
6-lead Stepper Motor
In Figure 8, note the following: • Resistor R17 limits the gate current.
• Diode D5 removes any surges in the winding
• Diode D1 protects the I/O pin from surges origi- above a voltage level of VDD.
nating on the power circuit side.
• Resistor R9 pulls the Q1 base Low by default
• Resistor R5 drives the LED1 when the winding and prevents it from conducting at spurious sig-
is energized. nals.
• Transistor Q1 acts as a buffer driver for MOS- • Power resistor R13 is used to balance the L/r
FET T1 by switching off when the I/O pin is ratio of the windings and to limit the current
Low and vice-versa, allowing the MOSFET to depending on the resistance of the windings. An
conduct current and energize winding W1. The additional potential divider across this resistor
choice of N-channel MOSFETs depends on the can be used to sense the winding current by uti-
voltage and current rating of the motor. In our lizing other ADC inputs of the Z8 Encore!®
example, IRFZ44N is chosen based on the motor microcontroller, as illustrated in Figure 9.
specifications of 12V and 1.25Amps per wind-
ing. Because the MOSFET carries a high current,
consider using a proper heat sink with a heat sink
compound.
• Zener diode ZD1 ensures that the firing voltage
on the gate of the MOSFET does not exceed 5V.
AN012805-0708 Page 6 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
PD3
Vcc
PA2
U1
PA3
X1
Z8F
X2
PA4
R22
3V3 3k9
PB0/ALG0 PB1/ALG1 PA5
PB2/ALG2
PB3/ALG3
PB4/ALG4
Gnd
R23
10k
From R16
From R15
From R14
From R13
• Switch SW1 (see Figure 14 on page 4), when Unipolar Drive Software Description
connected to pin PD3, acts as the directional con-
trol input. Pressing SW1 reverses the direction of The source code of unipolar drive is written in
rotation, while speed remains unchanged. ANSI compatible C and compiled with ZDS II,
Zilog’s Integrated Development Environment
• The half-step mode (selected at compile time) (IDE) for Z8 Encore!® series. The compilation
rotates the motor at exactly half the RPM of full- options are provided in the source code (AN0128-
step mode at the same step frequency. SC02) available from www.zilog.com.
• The step frequency, and consequently the speed
of the stepper motor, can be varied by using The main routine consists of three functions to ini-
potentiometer R23. The voltage at the wiper pin tialize the peripherals:
of the potentiometer is fed to ADC input channel
0. The reference voltage is generated internally • init_timer0() initializes Timer0
in the microcontroller and is used to compare the
• init_adc() initializes the on-chip ADC
voltage on the ADC input.
• init_p3ad() sets up the GPIO pin 3 of
This circuit is designed such that any type of uni-
port D as an external triggered interrupt
polar wound motor, 8- or 6-lead, can be driven by
it. The only component change that may be These peripherals are interrupt-driven and their
required is a MOSFET with appropriate voltage individual Interrupt Service Routines, are:
and current ratings.
• isr_timer0()
• isr_adc()
AN012805-0708 Page 7 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
The Off period of the pulses is dependent on the A Low on the GPIO pin PA2/PA3/PA4/PA5 ener-
current fall time in a motor winding, and essen- gizes the particular winding, such that the data bit
tially constant; the On period varies according to is inverted before it is sent to the port pin.
the desired speed of the motor. If a higher speed is
required, the On time is reduced to produce nar-
Timer0 is initialized by configuring T0CTL reg-
rower pulses, and vice-versa for lower speeds.
ister with the appropriate Hexadecimal word.
Such variation in speed is achieved by mapping the
position of the potentiometer (voltage available at
wiper pin) with the exact time values to be placed The switch SW1 that is connected to pin PD3 (Pin3
into the T0CPH and T0CPL registers. of PortD), acts to reverse the directionof the motor.
To set PD3 as a source of external interrupts, set
the register PDDD to use pin PD3 as the output
The table.h file in the source code (AN0128-
pin, select the highest priority (same priority as
SC02) available from www.zilog.com contains the
ADC) using IRQ1E0, IRQ1E1, and select the fall-
2-dimensional look-up table, in the format:
ing edge with IRQES. In addition, enable port D
array[10][2], consisting of ten pairs of poten-
for interrupts by setting the PS register appropri-
tiometers:exact time values. Depending on the
ately. To reverse the motor direction, reverse the
ADC calculation (position of the speed potentiom-
sequence as per Table 1 or Table 2 on page 3, in the
eter) an appropriate value is chosen from the table
’switch:case’ statement of the isr_timer0()
and loaded into the timer registers. Varying the
routine.
potentiometer from minimum to maximum posi-
tion results in ten different motor speeds.
To select full or half step mode at compile time,
assign the value of variable step as 0x01 or 0x00,
The look-up table can be expanded to include more
in the main() routine.
number of pairs corresponding to different motor
speeds mapped to potentiometer positions. These
pairs can then be loaded into Timer0, as illus-
trated in the main routine.
AN012805-0708 Page 8 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
VCC
AN012805-0708 Page 9 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
AN012805-0708 Page 10 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Figure 12 is a screen shot of the waveforms in full- inverse of Figure 11 (although not on same time
step mode, available at the gate pins of MOSFETs scale).
T1,T2, T3, and T4. Note that the logic is the
Figure 13 is a screen shot showing the typical volt- mode, available at the Gate and Source of MOS-
age (top) and current waveform (below) in full-step FET T1.
AN012805-0708 Page 11 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Summary
This Application Note successfully demonstrates
the operations of a unipolar stepper motor drive
based on the Z8 Encore!® series of Flash micro-
controllers. Only one 16-bit timer, one 10-bit ADC
channel, and an external interrupt I/O pin are used,
leaving other resources free for the designer. The
ANSI-C code, including an array table, occupies a
mere 1689 bytes, with a RAM requirement of only
38 bytes.
AN012805-0708 Page 12 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Appendix A— Reference
Further details about stepper motors, the Z8 Encore!® MCU and the ZDSII–IDE can be found in the refer-
ences listed in Table 5.
Topic Document
Stepper motors Stepping motors and their Microprocessor Controls – Takashi
Kenjo; Oxford Press, 1984.
Zilog Developer Studio (ZDSII–IDE) Zilog Developer Studio II—Z8 Encore!® User Manual (UM0131).
v4.1.0
Z8 Encore!® product specifications Z8 Encore!® Microcontrollers with Flash Memory and 10-Bit A/D
Converter Product Specification (PS0176).
AN012805-0708 Page 13 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Appendix B—Glossary
Definitions for terms and abbreviations used in this Application Note are listed in Table 6. .
Table 6. Abbreviations/Acronyms
Term/Abbreviation Definition
MOSFET Metal-Oxide Semiconductor Field Effect Transistor,
N-channel or P-channel.
BJT Bipolar Junction Transistor, npn or pnp.
ADC Analog-to-Digital Converter.
Flash Read-Only Memory for Code and Constant Data
Storage.
Emulator Equipment used to mimic the functioning of a
microprocessor.
PPS Pulse Per Second, a measure of frequency.
AN012805-0708 Page 14 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
HV_IN D5
1N4001
R17
1k,0.5W
3V3 T1
Q1 IRFZ44N HV_IN
R1 BC547 R5 ZD1
3k3 5V1
C1 R2 4k7
10uF / 10V D1 LED1 R13
4k7 1N4148 1E,5W
R3 R9
4k7
D6
4k7 HV_IN 1N4001
R4
R18
R21 4k7 1k,0.5W
SW1 100k T2
Q2 IRFZ44N
BC547 R6 ZD2
Vcc
6
0.01uF D2 LED2
1N4148 D7
R10 1N4001 3
4k7 2
C4 1
27 pF U1 HV_IN
PA3
X1 Z8F R19 MG1
X1 1k,0.5W 6-lead Stepper Motor
18.432 MHz T3
Q3 IRFZ44N
X2 BC547 R7 ZD3
C3 PA4 3k3 5V1 R15
27 pF 1E,5W
R22 D3 LED3
3V3 3k9 1N4148
R11
PB0/ALG0 PA5 4k7 D8
1N4001
Gnd
R23 HV_IN
10k
R20
1k,0.5W
T4
Q4 IRFZ44N
BC547 R8 ZD4
3k3 5V1 R16
1E,5W
D4 LED4
1N4148
R12
4k7
Title
Unipolar Stepper Motor Drive with Z8 Encore!
Figure 14. Schematic for A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
AN012805-0708 Page 15 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Appendix D—Flowcharts
This appendix illustrates flowcharts of the various routines developed for a unipolar stepper motor applica-
tion using the Z8 Encore!® MCU.
Reset
¥ Initialize timer0
¥ Set vector isr_timer0
¥ Initialize external interrupt pin Y
Load 9th Is set speed
¥ Set vector for external interrupt pin value of On
¥ Initialize ADC value = speed9?
time from table
¥ Set vector for ADC
¥ Enable interrupts
N
Load highest
¥ Enable ADC conversion value of On
¥ Delay until conversion complete time from table
AN012805-0708 Page 16 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
N
Is SW1 = 1? Set SW1 = 1
Set SW1 = 0
Return
Return
AN012805-0708 Page 17 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
Y Y
End Interrupt
AN012805-0708 Page 18 of 19
A Unipolar Stepper Motor Drive Using the Z8 Encore!® MCU
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perform when properly used in accordance with instructions for
use provided in the labeling can be reasonably expected to result in a significant injury to the user. A
critical component is any comp onent in a life suppor t device or system whose failure to perform can be
reasonably expected to cause the failure of the life support device or system or to affect its safety or
effectiveness.
Document Disclaimer
©2008 by Zilog, Inc. All rights reserved. Information in this publication concerning the devices,
applications, or technology described is intended to suggest possible uses and may be superseded. ZILOG,
INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY
OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT.
Z I L O G A L S O D O E S N O T A S S U M E L I A B I L I T Y F O R I N T E L L E C T U A L P R O P E RT Y
INFRINGEMENT RELATED IN ANY MANNER T O USE OF INFO RMATION, DEVICES, OR
TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. The information contained within this
document has been verified according to the general principles of electrical and mechanical engineering.
Z8, Z8 Encore!, Z8 Encore! XP, Z8 Encore! MC, Crimzon, eZ80, and ZNEO are trademarks or registered
trademarks of Zilog, Inc. All other product or service names are the property of their respective owners.
AN012805-0708 Page 19 of 19
of 19