Small stepper DIY driver with Flicker interface

On this page I am describing a small, 1.5 ampere stepper motor driver equipped with the experimental Flicker interface. The intention is to build a simple microcontroller DIY board that can be used to experiment with various stepper motor driving techniques. In addition, this is the opportunity for me to test the Flicker-parameterization-interface in practice.

The Flicker interface is a simple low-resource, unidirectional communication protocol used to wirelessly send parameters from your mobile phone to a limited-resource 8-bit microcontroller. For example we can define stepper driver parameters like, current, V-F curve, speed limit… on your fancy smartphone GUI and then simply transfer these down into the microcontroller (more...).

For some reason, stepper motors are regarded as half-toys. However it is not at all easy to make a stepper motor runs smoothly and into high. For me, the first time I tried to drive a stepper motor using my own driver design was a great failure.

The board described here uses L298. The L298 is, I would say, a bit touchy – the microcontroller should always keep an eye on the current. If it ever detects an overcurrent situation it should immediately shut-down L298 H-bridges. If you build the board for experimentation, make sure you put the L298 into a socket because you might need to replace them often… If you want a more robust and more powerful driver you might take a look at the similar driver that uses discrete mosfets.

The microcontroller used is the ATmega8.

List of resources

You can download the zip file (70kB) that contains:

  • DipTrace driver schematics
  • DipTrace PCB design (<300 pads)
  • Simple demo application source code (for AVR studio)

You can download the Flicker application for android smartphones.

You can download two Flicker interfaces, to be used with the demo application (here and here).

The power supply

The board needs external DC power supply 24…35V (2A). On the board, internally, two additional levels are generated: 5VDC (to run the microcontroller) and 12VDC.

Note that the 12VDC level generation is in a way too naive and thus not very stable. You might decide to use 12VDC integrated circuit regulator instead (especially if you are not able to find 5.6V and 7.5V zener diodes to generate about 13.1V. Note that diodes should be low-power, maybe 200mW. If you find 100mW even better – you can then remove R1_B resistor). My original intention was to use input voltages from 15 to 42 volts, but I quickly learned that due to the naive 12VDC generation I must limit the input voltage into the 24V to 35V range.

The large 2A diode D1 is only used to protect the circuit from reverse power connection and you may omit it. I actually divided the capacitor C2 into three capacitors of 470uF, 50V. The BD139 transistor must be mounted on a heatsink. The 7805 might also be in a need of a small heatsink. Resistors R22 and R23 are used to provide input voltage measurement to the microcontroller analog input pin.

The L298 and surrounding electronics

Some simple logic circuitry made from diodes resistors and two transistors is used to prepare signals needed to drive the L298 dual H-bridge integrated circuit. Normally, one H-bridge inside the L298 chip is governed using following three signals:

  • IN1 - High/low selection signal for the left half of the H-bridge
  • IN2 - High/low selection signal for the right half of the H-bridge
  • EN - Enable/disable the whole H bridge (when disabled, all transistors are closed)

However, I wanted to use a modified set of signals to govern one H-bridge because I wanted to be able to use microcontroller PWM generator easily. Following signals are provided by the microcontroller:

  • PWM – provides 15.6kHz PWM switching signal
  • DIR – direction (polarity) of the generated PWM voltage (left-to-right or vice versa)
  • ENA – enable the whole H bridge

The ENA signal is, of course, directly connected to the L298 EN signal. The DIR signal determines whether the PWM signal will be supplied to IN1 or to IN2 input of the L298.

At the output of the L298 I used some special circuitry to measure currents through the motor (the motor is connected at the J2 connector). Instead of placing measurement resistors R2 and R3 into the ISEN pins of the L298, I placed them directly in series to the motor windings. This way I am able to measure currents all the time and also keep track on the current direction. Basically at the output of the 741 op-amp I have the voltage level proportional to the motor current plus some voltage offset. The voltage offset is 12V, and I need to reduce it to about 3V (that is, to somewhere between 2.7 and 3.3V). This reduction is done using the 9.1V zener diode.

Unfortunately, the presented method to reduce the voltage offset is not perfect. First, your 9.1V diode must be low-power (100mW ideally) because the 741 can only provide 20mA. The 470ohm resistors R12 and R13 are used to ensure high-enough current level through the zener diodes, but when the 741 outputs low voltage, the current through diodes might not be enough to ensure 9.1 voltage drop. Therefore you might experience some current measurement distortion while measuring large negative currents.

The R4/R6 resistance ratio must be equal to the R5/R7 resistance ratio (also R8/R10=R9/R11). Measurement resistors R2 and R3 (0.47 ohm, both) must have at least 1W.

Eight BYV27 or similar fast diodes must be used – do not try to run the motor without them. I actually used BYV26 due to lower price and had no problems (but BYV26 might be somewhat too small).

The microcontroler and control circuits

I am using ATmega8 microcontroller. It is delivered in DIP28 package and can be easily soldered manually onto your home-made PCB. If the microcontroller is any more powerful, I would consider it a waste for such an application (of course, you might have your own opinions and reasons).

I placed the J3 connector as the SPI interface for in-circuit microcontroller programming. You should redesign this interface according to your needs. The R26 resistor has a bit too high resistance value (100k) and it would be safer if you use like 47k instead (I must use 100k because my home-made programmer is otherwise unable to reset the microcontroller).

As you noticed, the power supply for the AVcc is not filtered. You might want to improve on this if you have concerns about measurement noise.

Two LED diodes, D20 and D21, are here and you can program them as you like. The external connector J4 receives control signals from the outside world. There are following signal lines on the J4 connectors:

  • Digital input 1 (you can use it as ‘step impulse FW’ input)
  • Digital input 2 (you can use it as ‘step impulse RW’ input)
  • Digital input 3 (you can use it as ‘driver enable’ input)
  • Analog input (you can use it for speed reference)
  • 5VDC (small current only)
  • GND

The Flicker interface

The flicker interface consists of one phototransistor (PH1=BPW40), one resistor (R42) and one jumper (J5). It is connected to the pin C5 on the microcontroller. As said, the flicker interface enables parameterization of the stepper driver using your smartphone GUI.

When the jumper J5 is inserted, the flicker interface is disabled (the signal at the C5 pin will always be low as if the phototransistor always detects light). But if the jumper is removed and if the phototransistor is covered (with your smartphone, perhaps) to receive no light, the C5 pin will go high – this can be detected in the microcontroller and the procedure for data receiving can be called. (I suppose that it would be better if instead of the jumper J5, you use a small button connected to another free pin on the microcontroller – when user presses the button, the data receiving procedure is activated. However, this requires two microcontroller pins while I was only willing to sacrifice one.)

You might need to play a little with R42 resistor value. If your smartphone has a very dim screen, you might need to increase R42 to 100k so that the BPW40 phototransistor can produce large-enough signal. Worse thing is if your smartphone screen is slow and its pixels cannot turn on/off quickly – this would limit your data transfer speed. In any case I hope you have an oscilloscope to check what is happening.

The PCB

I decided to make a single-layer board coarse enough to be home made. The board has dimensions 4.75” x 3.85” (about 12x10cm). This is a somewhat large board for a small stepper motor driver but as it is intended for experimentation, its size should not bother much.

After almost all elements soldered the board looks like on the picture below. Note that a reasonable heatsink should be mounted on L298 and BD139. Also note that the picture shows a bit earlier board variant and that this particular PCB was not home made but was made by professional workshop (elements soldered at home, manually).

Microcontroller programming

As the board was made for experimentation, it is up to you to develop your own algorithms. I am providing only some demo software and some basic information… Here is the list of microcontroller pins, as I used them:
   D0 - not used
   D1 - LED1
   D2 - INPUT1 (external pulse input forward)
   D3 - INPUT2 (external pulse input reverse)
   D4 - LED2
   D5 - DIR_A
   D6 - DIR_B
   D7 - INPUT_ENA (external enable input)
   B0 – not used
   B1 - PWM_B
   B2 - PWM_A
   B3 - not used (MOSI SPI)
   B4 - not used (MISO SPI)
   B5 - not used (SCK SPI)
   B6 - ENA_A
   B7 - ENA_B
   C0 - external analog input
   C1 - CURRENT_B (current measurement B)
   C2 - CURRENT_A (current measurement A)
   C3 - input voltage measurement
   C4 - not used
   C5 - Flicker input
   C6 – RESET

In the demo software, the motor is voltage fed. That is, the V-F curve is defined for a motor (in this simple example the V-F curve is only a constant-slope line with some offset) and this curve defines what voltage will be fed to the motor depending on the motor speed. Because the current is regulated only indirectly, the software should have some way to handle overcurrent conditions in order to protect both, the driver circuitry and the motor.

There are many limitations of the demo software. For example, there is no recovery from overcurrent condition – when the overcurrent is detected, the L298 will be disabled and will only be re-enabled again after the microcontroller is reset.

The Flicker interface code

I prepared two interfaces that can be used with the demo software. One interface, when downloaded into the microcontroller, will enable the speed mode, while the other one will enable the position mode. (In the speed mode you use digital inputs to speed-up or speed-down the motor. In the position mode you use digital inputs to step-forward or step-reverse the motor.)

    

The above pictures show these two interfaces in the Flicker application (for android phones). You can download them by typing http://gorupec.awardspace.com/FSpeed.txt or http://gorupec.awardspace.com/FPosition.txt URLs into the Flicker application interface-code definition field.

You can e-mail me if you have any question, suggestion or request... And when you work on your projects you can use the Math-o-mir, math notepad software.


Danijel Gorupec, 2014
danijel.gorupec(at)gmail.com

Home