STM32F0 Bipolar Stepper Motor Driver

So I’ve been looking quite a lot into minimum cost robotics as of late and have been searching for the best drive methods. I’ve been looking for a slow high torque motor and the standard for that generally lies with stepper motors. Having searched around on eBay and Aliexpress for the cheapest stepper motors, I came across these really cool 15mm ones for ridiculously cheap at 99p each on eBay and 79p in packs of 10 on Aliexpress. I’ve used standard unipolar stepper motors previously as these are much easier to drive requiring only pull down transistors, for example the standard ULN2003 transistor array with integrated flyback diodes.

Unfortunately however, bipolar motors require H bridges to drive current both ways in the motor windings to allow for directional control. This can easily be achieved using dedicated chips such as DRV8811. While I could’ve bought this chip or one similar, it was much easier and cheaper for me to wire up some simple H bridges using some discrete MOSFETs that I had to hand (2N7000 N channel and BS250 P channel). I’ve not designed this particularly well as the upper P MOSFETs aren’t properly turned off though they’re turned off enough to not draw significant current.

bsd1Simple dual H bridge schematic with 8 MOSFETs

As the outputs from the STM32F0 are 3.0V logic, PA1, PA3, PA5 and PA7 never reach 5V meaning there will always be atleast 2V Vgs on each P channel MOSFET. Fortunately, looking at the datasheet for this MOSFET shows that with a Vgs of 2V should lead to minimal current flow though this is MOSFET dependent and a better circuit should be developed… Or a dedicated chip used.

 

This code should hopefully work for any bipolar 4 wire stepper motor though the wiring may need to be figured. From the datasheet of this motor, I can see that each step is 18 degrees. In my coding, I set the step and delay for a certain amount of time. The minimum delay is 1ms therefore at this delay, the motor should take 360/18 = 20 milliseconds per rotation giving an RPM of 3000. In 8 step (half step) mode however, the maximum RPM will be 1500.

The differences between 4 step and 8 step drive modes are well explained in this article. I’ve found that 8 step mode has much smoother motion and produces less noise at the expense of lower maximum achievable speed.

While there is much more that can be added to a program of this kind such as acceleration and deceleration routines, this is enough for a test of motors.

The code can be found on my Github.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s