Sunday, 11 September 2011

Choosing the stepper motor resistors

Using a combination of L293D stepper controller ICs and IRF640 mosfets, we've now got a way of controlling both unipolar and bipolar stepper motors - so no matter where you salvage your motors from, we should have a way of offering a way of controlling them.

Now we have to get a bit nerdy and re-visit old school topics.
Back in the dark ages, those of us of a certain age will remember electronics, or even physics, lessons where we learned Ohm's Law.

Ohm's Law helps us to work out current and power requirements for controlling our stepper motors. We already know - from bitter experience - that if you ignore you basic power requirements, you'll quickly get through quite a few components, as you let the magic smoke out after just a few seconds of driving the motors!

We need to look at the things we can't change, and introduce elements to control those that we can.
For example, we're using the L293D stepper controller. It has a maximum current rating of 600mA (0.6A) per channel. That means, if we push more than 0.6A through the chip, it'll get hot, start to smell, and eventually burst into flames with a pop and a rush of smoke. Understandably, we don't want this to happen, so we need to introduce some resistors to limit the current.

This is where Ohm's Law comes in. Simply put:
V = IR where V=voltage, I=current, R=resistance
P = IV where P=power, I=current, V=voltage

Using these two equations, we can work out what type of resistors we need to use to limit current through the motor coils, to keep everything within safe limits.

As our stepper controller chip L293D has a current rating of 0.6A, ideally we want to drive the motors at not more than about half this (so that if the motor "spikes" or draws more current, to suddenly change direction, for example, we're still within safe limits).

We're going to use a 12V supply for driving the motors (because at a lower voltage, and lower current, the motor loses torque and can slip when driving a load). Now we just need to fill in the missing value:

V = IR; 12 = 0.3 * R; R = 12/0.3 = 40

So we know we want to use a resistor of roughly 40 ohms.
Common resistor values are 22R, 33R, 47R. If we increase the resistance too much, the motor will stall, so let's see what happens if we choose the 33R resistor:

V = IR; 12 = I*33; I = 12/33 = 0.36A
This equation has used only the resistance of the resistor. But we're putting the resistor in series with the motor coil - so we need to factor in the resistance across the coil(s) in the stepper motor.
The motor we're using has a coil resistance of 5 ohms (measure the resistance across your steppers with a simple multimeter - they're all different) so our total resistance is actually 38R.

So to find the current consumption, if we use a 33R resistor in series with the stepper motor coil(s):

V = IR; 12 = I*38; I = 12/38 = 0.32A

It seems that a 33ohm resistor in series with one side of each of the stepper coils results in the motor drawing just over 0.3A per phase. This is half of the current rating of the L293D driver chip, and seems like an ideal value.


Just shoving a regular 33R resistor in-line isn't going to do much good.
We know - from experience - that using puny little resistors with stepper motors means bad smells and lots of smoke! Why? Well, a typical resistor (the type you normally use with breadboard/prototyping boards) can have a resistance of between a few ohms, up to a few million ohms, but typically only handle about 0.25W

Watts are the units of power that the resistor can handle.
Watts are a product of voltage and current.
Ohm's Law tells us that P = IV (power = current * voltage).

So in our example here, we've a 12V supply and a 0.32A current draw.
The total power requirement is 12*0.32 = 3.84W
So we need a resistor with a power rating of at least 4W - ideally more.
It's no wonder that when we pushed current through our 0.25W resistor to drive the motors, they got hot and started to smoke very, very quickly! We're going to need to get hold of some power resistors and maybe a couple of heatsinks, to help keep them from getting too hot while in use.