This is only a preview of the February 2019 issue of Silicon Chip. You can view 47 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Versatile Trailing Edge Dimmer with Touch Plate & IR ":
Items relevant to "El Cheapo Modules 22: Stepper Motor Drivers":
Items relevant to "Motion-sensing 12V Power Switch":
Items relevant to "USB Mouse and Keyboard Interface for Micros":
Items relevant to "Build-it-yourself DAB+/FM/AM radio":
Purchase a printed copy of this issue for $10.00. |
Using Cheap Asian Electronic Modules Part 22: by Jim Rowe
Three Stepper
Motor Drivers
Want to build your own 3D printer or
CNC machine? You will 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
our primer in the January 2019 issue
(siliconchip.com.au/Article/11370).
The first driver module we’re looking at is also the largest, at 60 x 55 x
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 less than A$3.80.
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 PowerSO20 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 two-phase bipolar hybrid stepper motor.
Each bridge has an enable input
and two logic control inputs, and both
bridges have their negative supply
connections brought out separately, to
siliconchip.com.au
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 x 25 x 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.
Australia’s electronics magazine
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 10kW 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 has 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 voltFebruary 2019 35
Fig.1 (right): block diagram of the L298N IC, which is shown as
part of the module above, attached to the heatsink.
ages 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 $16 – nearly four 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.
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.
36
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
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 module measures just 20 x 15 x 16mm, including the stick-on heatsink; and is
currently available from eBay
suppliers for around $2 each.
The DRV8825 chip packs a lot
into a 28-pin SSOP (SMD) package, as you can see from the internal block diagram, Fig.3.
There are two full H-bridge
drivers, labelled MOTOR DRIVER
A and MOTOR DRIVER B. These
use N-channel power Mosfets and
can operate with a supply of 8.245V, 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
Fig.3: block diagram of the DRV8825 IC.
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 us-
ing 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.
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.1W resistors, to allow the
regulation circuitry to operate. Trimpot VR1, shown at upper left, allows
the maximum current level in each
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.
siliconchip.com.au
Australia’s electronics magazine
February 2019 37
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.
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 times 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 quite straightforward:
Imax = Vref ÷ (5 × Rsense)
So with the 0.1W 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
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 x 20.5 x 11mm, including
headers. Currently, it’s available from
various suppliers on eBay for around
$1.65 in one-off quantities.
Fig.5 shows a simplified block dia-
gram of what’s inside the TB6612FNG,
which comes in a 24-pin SSOP SMD
package. It’s basically a pair of Hbridge 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 voltage (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.
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.
38
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
Note that although the ground connection of each H-bridge is brought
out to a pair of device pins (3 & 4, 9 &
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
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 Silicon Chip 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 DRV8825based module from a Micromite
because with its inbuilt indexer,
it’s 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.
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 would not work properly. The program
is available from the Silicon Chip website.
siliconchip.com.au
Australia’s electronics magazine
February 2019 39
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).
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 x 9 x 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.
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 step-
per via the DRV8825 module.
This program is named “DRV8825
stepper driving program.bas” and you
can download it from the Silicon Chip
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), and FWD-REV (send
pulses for one full revolution in one
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.
40
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
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
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: around $11 each
NEMA 17: $12-22 each or five
for $38-69
NEMA 23: around $50 each
There were also many small nonNEMA steppers available at much
lower prices.
For example, a 28BYJ-48 5V unipolar stepper motor bundled with a
ULN2003 driver module was around
SC
$3.22 each.
siliconchip.com.au
DID YOU
MSS OUT?
Is there a particular project in S ILICON C HIP
that you wanted to read – but missed that
issue? Or perhaps a feature that
really interests you?
Grab a back issue . . .
while they last!
The SILICON CHIP Online Shop carries back issues for all months
(with some exceptions!) from 1997 to date. Some popular issues
are sold out, and some months are getting quite low.
But if you want a particular issue, you can order it for just
$12.00 INCLUDING P&P* – while stocks last!
The following issues are still available (at time of going to press):
1997 – all except August and September
1998 – all except March
1999 – all except February
2000 – all except April
2001 – all except October & December
2002 – all except June & July
2003 – all still available
2004 – all still available
2005 – all still available
2006 – all except January & October
2007 – all still available
2008 – all still available
2009 – all still available
2010 – all still available
2011 – all still available
2012 – all except December
2013 – all except February
2014 – all except January
2015 – all still available
2016 – all still available
2017 – all still available
2018 – all still available
HOW TO ORDER WITH YOUR CREDIT/DEBIT CARD#:
Don’t forget to let us know which issues you require!
Via email: silchip<at>siliconchip.com.au (24 hours a day)
Via the net: siliconchip.com.au/shop/ (24 hours a day)
By mail:
Silicon Chip, PO Box 139, Collaroy NSW 2097
By phone: (02) 9939 3295; Mon-Fri 9am to 4.30pm
* Australia only. O’seas? email for a quote
# Visa/Mastercard only.
OH NO! THE back issue
YOU WANT IS SOLD OUT!
DON’T PANIC AND STAY CALM! We can still help you! The SILICON CHIP
website (siliconchip.com.au) houses complete issues from mid 1997 on.
You can browse a preview version – and if it’s what you want, you can
purchase a digital edition (complete magazine) .
Full details are given where you browse the issue. And if you’re a current
digital edition subscriber, there are even more attractive rates!
SPEAKING OF SUBSCRIBING . . .
That’s the one way to guarantee you’ll never miss an issue! Not only that, you’ll
$AVE money on the over-the-counter price.
Full details are at siliconchip.com.au/shop/subscriptions
Australia’s electronics magazine
February 2019 41
|