Code for mini bipolar steppers?

JayAuckland

New Member
I'm helping friends create some small animated figures and have sourced some very small, very cheap bipolar stepper motors (see 24107
pic) which will be ideal to create movement of arms, etc. However I am having difficulties successfully driving them.
I'm trialing them using an existing combination of 14M2, code and an L293D H-bridge. While this combination works fine with a slightly larger bipolar stepper, enabling controlled movement clockwise and anticlockwise, when I replace that stepper with this new miniature one it is a little erratic and will move in one direction (CW as viewed from the shaft) only, regardless of the 'direction' of the pulses. Even when I parallel up this mini stepper with the slightly larger one the larger one still works fine while the mini one only moves clockwise. ie when pulsed to move clockwise they both move clockwise. When pulled to move anticlockwise the larger one moves anticlockwise but the small one moves clockwise. Hmmm. I've tried this with three of the mini steppers and they all exhibit the problem so am assuming it's not a dud motor. And the problem is evident at fast and slow rotation speeds.

This is the clunky but easy to fiddle around with bit of test code I've been running for these trials:
Code:
setfreq m8

b0 = 30                'rotation min ttl pause @ m8 = 7
b1 = 0                  'loop counter

Running:
for b1 = 0 to 50
gosub CW
next b1
for b1 = 0 to 50
gosub ACW
next b1
goto Running

CW:
gosub Step1
pause b0
gosub Step2
pause b0
gosub Step3
pause b0
gosub Step4
pause b0
return

ACW:
gosub Step4
pause b0
gosub Step3
pause b0
gosub Step2
pause b0
gosub Step1
pause b0
return


Step1:
high B.1: low B.2: high B.3: low B.4        'rotate cw one step (1)
return

Step2:
high B.1: low B.2: low B.3: high B.4        'rotate cw one step (2)
return

Step3:
low B.1: high B.2: low B.3: high B.4        'rotate cw one step (3)
return

Step4:
low B.1: high B.2: high B.3: low B.4        'rotate cw one step (4)
return

end
While looking for ideas or even a solution I found this YouTube clip LINK of much the same mini stepper being run directly (seemingly without an h-bridge!) from an Arduino and doing exactly what I wish to achieve. So I know it should be possible, but having limited Picaxe knowledge and not a shred of Arduino knowledge or experience I am hoping someone can shine some light on my problem(s).
Such as:
How come the mini stepper won't play nice like the slightly larger one does?
How should I adapt my code if necessary?
Or what would be a Picaxe code approach to emulate what the YouTube guy is so successfully doing with Arduino?
With or with an h-bridge?

Hoping someone has got their head around this better than I can!

Jay
 

AllyCat

Senior Member
Hi,

IIRC the coil resistance is about 20 ohms and intended to run from 3.7 volts (with very low Rdson FETs) so you may need about 200 mA. There's no load on the motor in that YouTube demo, so the current might be much less (but more than a PICaxe could manage). I think they're 20 pulses/rev and you may need to optimise the pulse widths (to around 5ms); I didn't see any sign of that demo running at different speeds. It's also rather easy to damage the coil connections.

Take a look at my thread from a few years ago. I certainly managed to get the little motors rotating without much difficulty (as in that demo), but producing any real motive power, was much more difficult. I do have plans for a "2 cubic inch (30cc) line follower" project using those steppers, but I'm afraid it's on the "back burner" at the moment. The PAM8403 worked fine (above about 3 volts), I just shorted their input coupling capacitors and (over-)drove the input through about 33k from the PICaxe pins; only 2 pins needed (1 per coil) for HIGH / LOW / TRISTATE (input) for each stepper. For larger (non-stepper) motors, I did find it necessary to add inductors in series with the outputs.

Cheers, Alan.

PS: Check the (specified) voltage drops across the (bipolar darlington) output transistors in the L293D !
 

AllyCat

Senior Member
Hi,

I've taken another look at the YouTube video and have a few more observations. Firstly, in the text he does say that the coils are directly driven by the ATTiny, but I see that the Atmel chip has a significantly higher current rating (at least twice) that of the PIC(axe). Also, to drive each coil you need one output active high and another low, but the PIC(axe) has a rather weak pullup current, perhaps only 1/3 of the Atmel. But even the Atmel won't drive the motor very hard, when I drove both coils of those steppers continuously from a genuine 3 volts, they got too hot to touch within a minute. That's not surprising since with two 20 ohm coils the power is about 2 x 3v x 150 mA = almost 1 watt. As I said before, it's quite easy to make the motors rotate (although he did say that his became unreliable on the 4 volt battery), the problem is extracting sufficient useful power.

Secondly, remember that PICaxe Basic is inherently slow, but your code has a number of "unnecessary" commands and/or with an undefined sequence (since you have not identified which outputs go to the two coils). Because those steppers have so little inertia, the sequence in which the coils are activated might be significant. It is possible to update all the pin levels with a single OUTPINS (possibly from a LOOKUP command), but I adopted a more direct approach:

My test code was more complex, with a controllable "8-phase" clocking scheme, to give more control over the input power. For lowest consumption it pulsed each coil individually (with a programmable dead space in between,) so each coil acts against the permanent magnetism within the motor. For higher current (and hopefully power), one coil is switched on before switching the other off (so then the coils act against each other). But it is only for the maximum current (which I'm not sure is optimum) that one coil is reversed whilst the other remains active (i.e. a 4-phase mode). So here are some typical drive sequences, no subroutines (because they also waste time) but a more complex system (e.g. driving two steppers at different speeds) might be interrupt-driven:
Code:
; Single-pulse mode  - Assume all outputs start LOW
do
  pause gapwid  :  High A1    ; Enable coil A
  pause pulswid  :  High A2    ; Disable coil A 
  pause gapwid  :  High B1    ; Enable  coil B
  pause pulswid  :  High B2   ; Disable coil B
  pause gapwid  :  Low A1    ; Enable coil A (reversed)
  pause pulswid  :  Low A2    ; Disable coil A
  pause gapwid  :  Low B1     ; Enable coil B (reversed)
  pause pulswid  :  Low B2    ; Disable coil B
loop

; Overlapping-pulse mode  - Assume all outputs start LOW except A1 HIGH
do
  pause gapwid  :  High B1    ; Enable coil B (A enabled)
  pause overlap  :  High A2    ; Disable coil A
  pause gapwid  :  Low A1     ; Enable coil A  (reversed)
  pause overlap  :  High B2    ; Disable coil B
  pause gapwid  :  Low B1     ; Enable coil B   (reversed)
  pause overlap  :  Low A2     ; Disable coil A
  pause gapwid  :  High A1    ; Enable coil A
  pause overlap  :  Low B2     ; Disable coil B
loop

; Full Overlap pulse mode  - Assume A1, B1 start LOW, A2 and B2 start HIGH
do
  pause gapwid  :  High A1 : Low A2     ; Enable coil A
  pause gapwid  :  High B1 : Low B2     ; Enable coil B
  pause gapwid  :  Low A1 : High A2     ; Reverse coil A
  pause gapwid  :  Low B1 : High B2     ; Reverse coil B
loop
Cheers, Alan.
 
Last edited:

JayAuckland

New Member
Hi Alan, that looks very interesting, thanks for taking the time to make your observations and suggestions!!! I think I understand what each of your suggestions is based on/doing and will sit down tonight NZ time and have a go with them! Watch this space!
Jay
 

JayAuckland

New Member
Thanks too AllyCat. I'm not sure what load the motor will be driving yet, but had anticipated making it as little as possible by using the screw shaft to create a linear movement or having the item being moved fairly well balanced and needing only to be nudged in either direction by the motor reeling in a thread or something similar. Your more technical comments will require some study on my part but it's always a learning exercise doing this stuff! Thanks heaps and I'll report back when I have progress!

Jay
 

Hemi345

Senior Member
The PAM8403 worked fine (above about 3 volts), I just shorted their input coupling capacitors and (over-)drove the input through about 33k from the PICaxe pins; only 2 pins needed (1 per coil) for HIGH / LOW / TRISTATE (input) for each stepper.
You are using an audio amplifier IC to drive the little stepper motor? Sorry to derail the thread... I just built a IoT clock/radio with one of those ICs so I was curious how you were using it to drive a stepper.
 

AllyCat

Senior Member
Hi,

Most is explained in my linked post which is worth reading through because there is good input from Pongo. Basically, the PAM8403 is a "Class D" (Switched Mode, PWM) Amplifier so it has outputs which switch quickly (~150 kHz) and "hard" between the Supply and Earth Rails. Also, to drive 3 watts into a 4 ohm loudspeaker it drives both ends to give a 10 volts peak-peak signal from a 5 volt rail. Thus it has two full-H-bridge output stages (for Stereo), with excellent fast and low resistance FETs, ideal for also driving a Stepper Motor. Basically, you just overdrive the amplifier so that it switches hard between the supply or ground, exactly like (but probably better) than a normal H-bridge.

Most Arduino Library functions appear to (and the OPs code here) just switches the current in the coils from Forward to Reverse, but (IMHO) that's a very inefficient way to drive a stepper for some uses. I've shown in the code above how the coils can be switched off by taking both ends to either supply or earth, but that can't be done with the PAM8403, because it has only one input pin to drive each H-bridge. But we can turn the outputs "OFF" (actually switching between VDD and VSS rapidly to give an average "half-supply" output at both ends of the coil) by setting the PICaxe output pin(s) to tri-state ("Input" or "Reverse").

It seems that most YouTube stepper demos are just interested in showing that "it goes around and around". For that, my PICaxe 08M2 + PAM8403 implementation (which I'll post later) runs on 3 volts and 10 mA to give 1 rev/second (the quiescent current of the PAM is about 5 mA). That uses a "pulse" time of about 3 ms and a gap time of 47 ms (to give 20 pps at the 100+ mA expected for 20 ohm coils). The average current rose to about 50 mA for 10 revs/second (200 pps), or the 1 rev/second would actually run off 2 x AA NiMH cells (2.5 volts). :)

I'll post some more details and code later, but I want to actually measure the Torque of those steppers, not just watch them go around and around. ;)

BTW on one occasion, my test Stepper was rotating happily with one coll open-circuit - that might be the OP's issue.

Cheers, Alan.
 

JayAuckland

New Member
oops...just noticed that Alan IS AlleyCat! Duh. Have had an incredibly busy few days/nights but will start to pick my way through your suggestions asap.
J.
 

AllyCat

Senior Member
Hi,

No worry, normally I would have edited my immediately preceding post, but thought that adding so much more detail might lead to confusion. At the moment I've temporarily taken my original project off the back-burner and soon hope to update my PAM8403 thread linked above. However, I have now measured the torque of a similar motor, which might be relevant to this thread. The stepper I'm using is a little larger (6mm diameter), with a very similar electrical specification to my previous ones, but looks to be a better "quality". It's commonly described as a "micro stepper with copper gear" on ebay, available in several formats, including some with a wiring loom attached.

To measure the torque, I constructed a "winch" to lift a small weight (a coin) against gravity. The drum is attached directly onto the stepper shaft and the "rope/cable" is a plastic tape (actually leader tape for 1/4 inch magnetic audio tape). As the tape is reeled in, the diameter of the spool increases, thus increasing the load (torque) on the shaft until the motor stalls (or more stutters in the case of a stepper). For this test, at every instant, one of the coils (at least) must be energised, or gravity pulls the weight down again. Thus there is a minimum current consumption regardless of the speed, which at 3.2 volts was about 125 mA. Driving the coils consecutively, lifted around 7 grams on a reel diameter up to 8 mm, giving a maximum torque of 2.8 gm.cms. That load required a minimum pulse width of 8 ms, thus a maximum speed around 6 revs/sec. Introducing a drive-current overlap of around 8 ms increased the potential load to about 10 grams (4 gm.cms), at which point I encountered some issues with the attachment of the spool onto the tiny driveshaft so had to suspend the test.

Just a few hints on (my experience with) coupling the motor shaft to a "load": The connection needs some "resilience", to decouple any inertia of the load because the rotor must be able to move to its next "step" position, in the short pulse time (which may be only a few ms). A "belt drive" (elastic band) is a possibility, but I'm also concerned about the side thrust (and end float) on the rotor shaft, so my preference is for a pinion gear train. But a "lead screw" is an interesting alternative, if the shafts can be accurately aligned. It has an "advantage" that as its mechanical efficiency is (nearly always) below 50%, then the load (e.g. gravity) is unable to drive the motor "backwards", so it is not necessary to apply a holding or braking current to any of the motor coils.

Cheers, Alan.
 

Wrigley

Active member
Hi Jay
Mike here from England, good afternoon. I just noticed your thread regarding mini steppers. I bought a plastic 1:32 model of a crane
see photo.
My full circuit looks at the pulses from a 2.4GHz R.C. receiver and makes the crane (via L293D drivers with 7 volts on pin 8) rotate, extend etc using the joysticks.
It took me a while to figure out the stepper pulses. I also noticed that some of coil wires were opposite to most others which meant the motor would just back and forth.
You may notice that the L293D's draw about 70mA or so without motors rotating. Steppers may draw up to 270mA.
I've attached my circuit, photo and snippets of the stepper drive program.
Hope some of this info may be useful.
Mike
 

Attachments

Top