Use PWM with the Stepper Library

My stepper is getting too hot, so I want to try to limit the current by using PWM. Is this possible using the stepper library? Is it possible to use a transistor in between the power supply and the ULN2003 (second on the page: http://arduino.cc/en/Reference/StepperUnipolarCircuit), or would that mess up the stepping?

My stepper is getting too hot, so I want to try to limit the current by using PWM.

How are you powering it? How are you controlling it? PWM does not limit current.

Is this possible using the stepper library?

No.

Get a proper stepper motor driver, such as Big Easy Driver - ROB-12859 - SparkFun Electronics

Reduce the power supply voltage.

I should probably clarify what I meant before. I am using a ULN2803 to control the stepper.

Reduce the power supply voltage.

I was going to use a transistor with PWM to essentially lower the voltage of the circuit. Unless I got ohms law wrong, lowering the voltage should lower the current, right? I would then use a capacitor to try to help smooth out the square wave into something a little more linear (I know it won't be perfect, but would it work?). I would use a voltage regulator, but I will only use that if I have to. This is because the project I am working on, preferably, would be as compact as possible. Therefore, having a heat sinced regulator would add a lot of bulk. It is powered by a universal laptop charger... I am using the lowest voltage of 12V on it (it goes from 12V-24V).

If you don't need your stepper to "hold" - e.g., it is connected to a worm and gear - then consider turning it off altogether when it's not stepping.

A specialized stepper driver such as the Pololu A4988 uses PWM (or something like it) to limit the current. However it cannot be used with the sort of 5-wire steppers that are contolled with a ULN2003.

The important point about this process is that you need something to detect the current and only cut down the power when the limit is reached. This is usually done with a low-ohms current sense resistor. I'm sure it would be possible to put current sense resistors on the outputs to your motors but reading the extremely low voltages that they produce and acting on those voltages during the short time that a pulse is HIGH would be very tricky - to say the least.

I can't see any value in feeding a PWM signal into your ULN2003 - but I guess it is worth trying. If it were my project I would just use a lower-voltage power supply.

...R

If you don't need your stepper to "hold" - e.g., it is connected to a worm and gear - then consider turning it off altogether when it's not stepping.

That's a good idea. I am probably going to see if can afford to do that. I am actually going to have the stepper sitting flat, so it may work out that I don't need it to hold.

I can't see any value in feeding a PWM signal into your ULN2003 - but I guess it is worth trying. If it were my project I would just use a lower-voltage power supply.

Unfortunately, I won't be able to lower the power supply voltage. I am using this same power supply to run around 4 motors. The other 4 motors are actually rated for 24V, but 12V is fine with them. I am not sure how they would react to an even lower voltage. I would use a desktop PSU (computer), but it is going to be an outdoor project (I know laptop chargers aren't meant for outdoor use, but I will only be using it when it is sunny out).

I will try my method and Paul's method and see what result I get.

By the way, I also have a larger stepper which I don't mind using, but it heats up the IC like crazy, even when using the transistors in parallel, leading me to believe it draws over 1A (I can't afford for one motor to draw that much current from my PSU).

PaulS:
PWM does not limit current.

I've never understood why people say this. Surely by definition, an Amp is 1 Coulomb per second so a PWM duty cycle of (say) 50% must result in half the current of PWM at (say) 100% or am I missing something?

I can understand why it's sometimes not an appropriate method of current limiting (an LED?) but in a motor which by nature will have a significant inductance component it must be an effective way of limiting current otherwise chopper drives wouldn't be much use.

Happy to be corrected if someone can explain where I'm wrong.

I've never understood why people say this.

Because PWM affects voltage. A pin, which can supply current, is on or off a varying amount of time. The PWM function controls the amount of time that the pin is on or off. The amount of current that flows when the pin is on is NOT affected by how long the pin is on. Therefore PWM does NOT limit current.

Couldnt I just use a capacitor to smooth out the square wave a little? Sort of like a swtich mode PSU. I know there is no regulator to help make it fully smooth, but will it still work? I am still new in electronics.

A large capacitor would certainly help.

But I can't see why you cannot insert some sort of voltage regulator (eg LM317) between the 12v (or 24v) power supply and the ULN2003. It may even have the advantage of allowing you to run the other motors at their correct voltage.

...R

Most voltage regulators do not have a high current max. Also, i would need to use a large heatsinc, and this project is supposed to be as compact as possible

PaulS:
Because PWM affects voltage. A pin, which can supply current, is on or off a varying amount of time. The PWM function controls the amount of time that the pin is on or off. The amount of current that flows when the pin is on is NOT affected by how long the pin is on. Therefore PWM does NOT limit current.

As I understand it, that would only be true in an ideal circuit with zero inductance. In a motor where the inductance is significant, the amount of current sourced by the driving circuitry controlled by the pin IS indeed affected by how long the pin is on because of the LR time constant. By utilizing PWM with a frequency high enough that it "switches" within this time constant you end up with a current waveform akin to a shark fin shape (exponential rise/fall). The higher the frequency the less the ripple of course. The RMS value of this "shark fin" current is below that of the steady state current of a constant DC voltage. This is pretty much how chopper drives work - at least this is how I understand it.

electricviolin:
Most voltage regulators do not have a high current max.

A problem for every solution :slight_smile:
Reminds me of the song "There's a hole in the bucket"

How much current can you pass through a ULN2003 ?

...R

How much current can you pass through a ULN2003 ?

Hmm... that's a good point. Here is a strange thought... could I use the dropout voltage of the regulator as a 'feature' of it? I mean I would use a 12V regulator (LM7812) and it would lower it below 12V. I doubt this will be enough though (in terms of lowering the voltage), right? Alternatively, I could use a 5V regulator, but I am worried that I will have to heatsinc it, and that the motor may not run. I will do testing for all of these solutions and find what it best. So far I have these:

1.) Use PWM and a capacitor
2.) Use a voltage regulator (along with PWM and cap for power saving) - both 5v and 12v

electricviolin:
Hmm... that's a good point.

So why not answer the question ?

...R

Yup it can take 1A. Will it need a heat sinc though? I am not sure how to figure that out from the datasheet.

The reason I asked is because an LM317 should be well able to deal with 1 amp.

...R

Do you know what the heat sinc situation is on it? I would have to purchase one if I am going to need it.

Sorry. I don't know. I have one that is 35mm x 30mm - came from Maplin I think.

If you are using an aluminium housing maybe you could use that as the heat sink?

...R