This is only a preview of the September 2020 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Using Cheap Asian Electronic Modules Part 24: by Jim Rowe
Three Stepper
Motor Drivers
Want to build your own 3D printer or CNC
machine? You’ll need multiple stepper motors
to control it, and a way to drive them. Or
maybe you have some stepper motors from old
printers or disc drives and want to reuse them.
Here are three of the most common stepper
motor driver modules and how to use them.
T
his article assumes you
understand the basics of how
stepper motors work. If you
want an introduction to this type of
motor then read Paul Cooper’s excellent Using Stepper Motors series in the
October 2019 to February 2020 issues.
Our first driver module is also the
largest, at 60 × 55 × 28mm, including
the finned heatsink for the driver IC.
It’s based on the ST Microelectronics L298N dual H-bridge driver chip
and is currently available on eBay
for around £3 to £4.50 (at the time of
writing see item 182636983939). If
you don’t mind waiting up to a month
for delivery, then AliExpress sell this
item for nearly half the eBay price.
The ‘N’ on the end of the chip version signifies that it’s in a 15-pin Multiwatt Power package, intended to be
mounted vertically on a heatsink. ST
Micro also make a similar version
(L298HN) intended to be mounted
horizontally, and a version in a Power-SO20 SMD package (L298P).
Fig.1 shows a simplified block diagram of what’s inside the L298. It has
two full H-bridge drivers (using bipolar power transistors) and so can drive
both stator windings of a standard twophase bipolar hybrid stepper motor.
Each bridge has an enable input
and two logic control inputs, and both
bridges have their negative supply
32
connections brought out separately, to
allow for an external current-sensing
resistor (RSA and RSB, shown in red).
The L298 can operate from supply
voltages from 6-46V and can handle up
to 2A per bridge. The inputs are TTL
compatible. This makes it the most
rugged of the driver ICs we’re looking
at here, especially when it’s fitted to
that 23 × 25 × 15mm finned heatsink.
Fig.2 shows the full circuit of the
L298N-based driver module. In addition to the L298N chip itself (IC1),
there’s regulator REG1, which provides a 5V supply for the logic circuitry from the stator supply voltage
VMS, if no separate 5V supply is available. REG1 is enabled simply by leaving the jumper shunt in place on the
‘5V_EN’ header.
There are also eight MDDM7 fastswitching silicon diodes to ensure
that all four outputs of IC1 are protected from damage due to back-EMF
spikes from the motor stator windings, at the end of each current pulse.
The upper diodes prevent the outputs from swinging more positive
than one diode forward-voltage drop
above the supply voltage (VMS), while
the lower diodes prevent them from
swinging below ground by more than
one diode forward drop.
Note that there are no current-sensing resistors fitted between the SenseA
(pin 1) and SenseB (pin 15) pins of IC1
and ground. Instead, these pins are
brought out to the two pairs of header
pins (CSA and CSB) at the right-hand
end of the 6x2 pin DIL header, just below IC1 in Fig.2.
This allows you to connect in current-sensing resistors if you wish,
or just short both pins to ground (by
leaving the jumper shunts in place) if
you do not need current monitoring.
The other four pairs of header pins
(U1-U4) allow you to disconnect
the four 10kΩ pull-up resistors between the control inputs of IC1 and
+5V. Four of the five indicator LEDs
(LEDs1-4) show when each of the four
logic inputs is high, while the fifth
(LED5) is a 5V power-on indicator.
This module is quite flexible but it
does have one significant shortcoming: it is purely a dual H-bridge stepper driver, lacking any built-in indexing controller.
ST Micro make a matching controller chip for use with the L298, called
the L297. This can control the L298
for full- or half-stepping, wave microstepping and clockwise or anticlockwise rotation. It can also sense
the voltages across the current sensing resistors CSA and CSB, and use
PWM to control and regulate the stator winding currents. However, the
L297 chip costs around £10 – two to
Practical Electronics | September | 2020
Fig.1 (right): block diagram of the L298N IC, which is shown as
part of the module above, attached to the heatsink.
three times the price of the L298 module itself. Instead of using an L297
controller chip, you can use software
running in your Arduino, Micromite
or some other micro. Developing this
can be a bit of a challenge but it is by
no means impossible.
By the way, the L298N module isn’t
restricted to driving a stepper motor.
It can also be used to drive a pair of
conventional brushed DC motors –
one from each of the two H-bridges.
All you need to do is feed one input
of each bridge with a PWM (pulsewidth modulated) pulse stream. You
could drive one input for clockwise
rotation and the other for anticlockwise rotation.
DRV8825-based module
The next module is much smaller and
combines a stepper motor controller
and driver, both within the Texas Instruments DRV8825 chip. The mod-
ule measures just 20 × 15 × 16mm, including the stick-on heatsink; and is
currently available from eBay suppliers for around £1.25 each (at the time
of writing, see item 392867154045).
The DRV8825 chip packs a lot into
a 28-pin SSOP (SMD) package, as you
can see from the internal block diagram in Fig.3.
There are two full H-bridge drivers,
labelled MOTOR DRIVER A and MOTOR DRIVER B. These use N-channel
Fig.2: complete circuit diagram of the L298N-based stepper driver module. CSA and CSB can be fitted with two currentsensing resistors if needed, otherwise they can just be shorted to ground.
Practical Electronics | September | 2020
33
power MOSFETs and can operate
with a supply of 8.2-45V, with
a drive capability of up to 2.5A
(for each channel) at a supply
voltage of 24V.
Each driver has provision for
connection of current-sensing resistors at the bottom of each bridge
(ISENA and ISENB).
The block above the motor drivers is a charge pump used to develop the gate drive supply for the
upper MOSFETs in each bridge.
Then at upper left, there’s a
3.3V regulator, which can provide the current reference voltages for the two bridges (AVREF
and BVREF).
The DRV8825 also includes its
own stepper control logic/indexer block, shown at lower left. This
has STEP and DIR logic inputs for
basic motor control, plus three
MODE control inputs (MODE0,
MODE1, MODE2) which determine the stepping mode.
A total of six different stepping
modes are available: Full-stepping,
half-stepping, quarter-stepping and
three different microstepping resolutions (8/16/32 microsteps per full
step). The microstepping is performed
using PWM current control, together with synthesised sine and cosine
waveforms.
Internal feedback from the ISENA
and ISENB pins allows the PWM circuitry to regulate the motor winding
currents at the same time. The chip
supports fast, slow or mixed current
decay modes.
Fig.3: block diagram of the DRV8825 IC.
The SLEEP input allows the internal circuitry to be shut down for very
low current drain between active motor drive periods. There are also ENBL
and RESET inputs, both of which have
internal pulldowns. And there’s a
FAULT output, which goes low if the
device detects an over-temperature or
over-current condition.
Fig.4 shows the full circuit of the
DRV8825-based stepper driver module, and there’s little in it apart from
the DRV8825 chip (IC1).
The 10nF capacitor between pins
CP1 (1) and CP2 (2), and the 100nF
capacitor connected between the
VCP pin (3) and the motor voltage
line VMA are needed so that the internal charge pump can develop
the high-side gate drive voltage for
the two internal H-bridge drivers.
The chip’s ISENA and ISENB output
current-sensing pins are connected to ground via 0.1Ω resistors, to
allow the regulation circuitry to
operate. Trimpot VR1, shown at
upper left, allows the maximum
current level in each motor winding to be set to any desired level,
by setting the voltage at the AVREF
and BVREF pins.
The DRV8825 data sheet advises
that there is an op amp with a gain
of five in the feedback circuit from
the ISENA and ISENB pins, so the relationship between the maximum
motor winding current, the sensing
resistor values and the VREF voltage (set by VR1) is straightforward:
IMAX = VREF ÷ (5 × RSENSE)
So with the 0.1Ω sensing resistors
used in this module, the maximum
winding current (IMAX) will be equal
to VREF × 2. As a result, VR1 can easily set the maximum current level up
to 2.5A. For example, setting VR1 so
that VREF = 1.0V will give a maximum
winding current of 2A.
As you can see, despite its tiny size,
the DRV8825 has a surprising range
of capabilities, including a very flexible built-in indexing controller to
Fig.4: complete circuit diagram of the DRV8825-based stepper driver/controller module. While this circuit is less complex
than the L298N-based module shown in Fig.2, it doubles as a controller and driver instead of only being a driver.
34
Practical Electronics | September | 2020
The DRV8825 (left) and TB6612FNG-based module (right) shown slightly enlarged. Note the stick-on heatsink for the
DRV8825, which would likely be required when driving large stepper motors with windings that pull 1A or more.
simplify controlling a stepper motor
from a micro.
TB6612FNG driver module
The third stepper motor driver module
is based on the Toshiba TB6612FNG
chip. It’s slightly larger than the
DRV8825-based module, measuring
only 20.5 × 20.5 × 11mm, including
headers. It’s available from suppliers
on eBay for around £2.40 each – at the
time of writing see item 254645741337.
Fig.5 shows a simplified block
diagram of what’s inside the TB6612FNG, which comes in a 24-pin
SSOP SMD package. It’s basically a
pair of H-bridge drivers, each driven
from a control logic block. So in many
ways, it’s rather like the L298N, except that the H-bridges use LDMOS
power transistors rather than bipolar
power transistors.
The TB6612FNG is rated to operate at a maximum motor supply volt-
age (VM) of 15V, and to deliver output currents of up to 1.2A average or
3.2A peak, for each channel. But it
also needs a logic circuit supply voltage (VCC) of between 2.7V and 5.5V,
and there is no on-chip regulator to
derive this from the motor supply.
So this must be supplied externally.
Note that although the ground connection of each H-bridge is brought
out to a pair of device pins (3 and 4,
9 and 10), these pins are all linked
together inside the device.
You therefore can’t individually
monitor or control bridge currents.
You’d have to use a single resistor,
and it would develop a voltage corresponding to a vector sum of the two
bridge currents.
By the way, like the L298N, the
TB6612FNG does not include any
indexing/control circuitry ahead of
the control logic. So it too needs external indexing hardware or software
to drive a stepper motor.
On the other hand, it’s suitable for
driving a pair of brush-type DC motors, using PWM input signals to control motor speed and the AIN1/AIN2
and BIN1/BIN2 signals to determine
rotation.
Fig.6 shows the actual circuit of
the TB6612FNG based driver module,
and clearly, there is very little in it
apart from the main chip itself (IC1).
There are just three bypass capacitors on the supply lines and two 8-pin
SIL headers (CON1 and CON2) to
make the input and output connections. It couldn’t be much simpler.
Trying them out
Since the driving schemes of the
L298N and TB6612FNG are quite similar, we’ve decided to concentrate on
demonstrating how to use the L298N
and DRV8825-based modules. And
we’re going to demonstrate driving
Fig.5 (left): block diagram of the TB6612FNG driver IC.
Fig.6 (above): complete circuit diagram of the TB6612FNG-based module
which is only a driver module and does not have any control circuitry.
Practical Electronics | September | 2020
35
Low-cost stepper
motors currently
available
Currently, there are quite a few new stepper motors available via eBay and other
online sources.
Here’s a sample of those we found in
the standard NEMA sizes, together with
their price range:
NEMA 11 from around £9-£30 each depending on specification
NEMA 17 £7.50 each or five for £26
NEMA 23 around £25 each
There were also many small non-NEMA
steppers available at much lower prices.
For example, a 28BYJ-48 5V unipolar
stepper motor bundled with a ULN2003
driver module was around £3 each or £12
for a pack of five.
one from an Arduino and one from
a Micromite.
You should not have difficulty
adapting our examples to different
combinations of the modules and controllers if it turns out that you’d prefer
to use some other pairing.
First, let’s start by driving the
L298N-based module from an Arduino. While this module lacks its own
indexing controller, the Arduino IDE
comes with a library called ‘Stepper’
which has functions to perform indexing. That makes hooking up controller chips like the L298N (or the
TB6612FNG) quite easy.
Fig.7 shows how we connected the
L298N module to an Arduino Uno and
a typical bipolar stepper motor. The
connections between the Uno and the
module inputs are the defaults for the
Stepper library, so it’s important to
follow these carefully.
The stepper motor windings are
each connected to either the MOTOR
A or MOTOR B output terminals,
while the VMS and GND terminals are
connected to the motor power supply.
All the jumper shunts are left in
place on the module.
Also, note that the module’s centre GND pin needs to be connected to
one of the GND pins of the Arduino.
That’s because there is no other connection between the two GNDs, and
the control signals would otherwise
not work correctly.
The Arduino IDE Stepper library
comes with some example sketches
written by Tom Igoe. We adapted one of
these to make it easier for our readers.
It’s called SCstepper_oneRevolution.
ino and you can download it from the
September 2020 page of the PE website. It directs the stepper motor to rotate in one direction by a full revolution, then reverse and rotate back by a
full revolution.
The number of steps required for a
full revolution needs to be added to
the sketch before you run it. The correct figure for many motors is 200, so
that is the default.
If you find this sketch interesting,
you’ll find another three sketches in
the ‘Examples’ folder of the Stepper
library folder on your PC (if you have
installed the Arduino IDE). These
will all work with the setup shown in
Fig.7, performing different functions.
Microstepping with the Micromite
We decided to drive the DRV8825-based
module with a Micromite because its
inbuilt indexer made it a little easier
to program ‘from scratch’.
Fig.8 shows how we connected the
module between the Micromite and
a bipolar stepper. The main STP and
DIR inputs of the module are driven
from pins 10 and 9 of the Micromite,
with the SLP and RST inputs both
driven from pin 16.
Similarly, the ENBL input is driven
from pin 22, while the M0, M1 and
M2 mode control inputs are driven
from pins 21, 18 and 17 respectively.
On the output side, the motor windings are connected to the A1, A2, B1
and B2 pins, while the motor supply
is connected to the VMA (+12V) and
GND pins. The two GND pins are also
connected together, and on to a GND
pin on the Micromite. This is done to
ensure that both the module and the
Micromite have a common ground.
An electrolytic capacitor of at least
100µF must be connected between the
VMA and GND pins of the module, as
shown in Fig.8.
This is to provide a low impedance
reservoir from which the module’s
H-bridges can draw current pulses –
without any impedance from inductance in the power leads.
The USB-UART bridge module at
top centre in Fig.8 is to program the
Micromite from your PC, as well as
to provide the Micromite with 5V DC.
Note that while the DRV8825 module
comes with a tiny (9 × 9 × 5mm) finned
heatsink which can be attached to the
top of the DRV8825 chip using an adhesive patch, it is unnecessary when
driving a small stepper motor from a
12V supply. Presumably, it would be required if the module is driving a reasonably large stepper motor with windings
drawing over 1A from a 24V supply.
Fig.7: wiring diagram to connect the L298N-based driver module driving a
4-wire bipolar stepper motor with an Arduino or compatible board. Note that
the module’s ground connection needs to be wired to the Arduino’s ground
connection otherwise the control signals will not work properly. The program is
available from the PE website.
36
Practical Electronics | September | 2020
The three screengrabs of the example microstepping program for the DRV8825 running on a Micromite. From left to right
there is the main menu at power-up, the SET FUNCT sub menu (which determine how the drive pulses should be sent)
and then the SET MODE sub menu (which is used to select the stepping mode).
In our test, the winding current was
only about 330mA and even without
the extra heatsink, the DRV8825 became only barely warm. The module
PCB provides copper patches on both
sides under the chip, linked by an array of vias. So it already has a useful
amount of heatsinking.
After studying TI’s datasheet and
application notes, I was able to write
a Micromite program to control a stepper via the DRV8825 module.
This program is named DRV8825
stepper driving program.bas and you
can download it from the September
2020 page of the PE website.
When loaded onto a Micromite with
LCD BackPack, at power-up it will present you with the main screen with
six touch buttons, shown in Screen 1.
The buttons are labelled SET FUNCT,
SET MODE, < DIR, DIR >, START and
STOP. Pressing SET FUNCT loads the
SELECT FUNCTION screen shown in
Screen 2. This lets you choose from
one of five functions:
SINGLE
Send a single step pulse
each time
CONTIN Send a large number of
step pulses)
1/2 REV
Send pulses for a half
revolution of the motor)
FULL REV Send pulses for a full
revolution)
FWD-REV Send pulses for one full
revolution in one direction, followed by pulses
to make the motor return
in the opposite direction
to its original position).
The sixth button on this screen is
labelled RETURN, allowing you to
get back to the main screen without
changing the existing selection.
If you press the SET MODE button
on the main screen, you’ll be presented with the SELECT STEPPING MODE
screen shown in Screen 3. This allows
you to select one of the six stepping
modes provided by the DRV8825:
FULL STEP, HALF STEP, 1/4 STEP,
1/8 STEP, 1/16 STEP or 1/32 STEP.
Touching any one of these buttons
selects the desired mode and switches
you back to the main screen.
The two red buttons on the main
screen are used to select the direction of motor rotation. And touching the START button at lower left
should result in the motor performing
the selected function, using steps of
the mode you’ve selected. The STOP
button allows you to stop the motor
at any time.
This program demonstrates a fair
number of possibilities when it comes
to using the Micromite to control a stepper motor using the DRV8825 module.
Some useful links on each of the
modules are listed below:
www.st.com/en/motor-drivers/l298
www.ti.com/product/DRV8825
siliconchip.com.au/link/aama
Reproduced by arrangement with
SILICON CHIP magazine 2020.
www.siliconchip.com.au
Fig.8: wiring diagram for the DRV8825-based driver module connected to a
4-wire bipolar stepper motor and Micromite. The 100µF electrolytic capacitor is
required to provide a low impedance supply for the module’s two H-bridges.
Practical Electronics | September | 2020
37
|