Using pwm instead of high/low in Stepper library.

The x and Y motors I'm using to run my CNC are chopper motors, I believe. They came out of a set up where they were each driven by an stk675-050, and possibly driven with 24v. There isn't a voltage marking, only a 0.8, and a 1.8deg. The rest are numbers that I haven't quite found the answer for. The 0.8 is the impedance, which I have verified, and the 1.8deg is the degree per step. The "TYPE" is "23KM-K224-P2", the "No" is "T 202-01", and the "DWG NO" is "AXC501S7C", all by Minebea Co., LTD, and made in Thailand. All three of the motors very slightly from one another, but eh impedance and step are the same.

Since their impedance is only 0.8 ohms, which at 5 volts is 6.25 amps. So when the motor is just sitting in one place long enough, two coils are going to dissipate a constant 31.25 watts. This is apparently enough to get them pretty hot after just running through the first example that loads in LinuxCNC.

So the main question is, will the pwm from the arduino be a good frequency that won't bother operation at say 50%-75% pulse width? Instead of running on pins 2, 3, 4, 5, use pwm pins 5, 6, 9, and 10, and set the library to analogWrite instead of digitalWrite. Or should I look into a lower supply voltage for these motors?

You can use PWM to make a stepper go faster or run cooler at a higher voltage,
but it is not as simple as a chopper drive chip.

sbright33: You can use PWM to make a stepper go faster or run cooler at a higher voltage, but it is not as simple as a chopper drive chip.

Heheh, well the STK675-050 ~ $20/pc, where the Atmega8 is ~ $1/pc. I don't know of any other chopper chips besides the STK, but I had tried the Stepgenie ~ $12/pc, which are not choppers either, and those ran hot too. Why is a chopper driver simpler? Just because you don't have to program it? Thanks!

Your prices seem about right. It's simpler because there is no trial and error or experimenting involved. It just works. There is feedback to the chip which allows you to limit the current. The code I wrote for PWM took hours of testing to reach the maximum speed or run cooler and still have reasonable torque. In theory the results should be similar. But when you change the motor or supply you have to start over again adjusting the parameters in the code, since there is no feedback loop. If the load on the motor varies, and you can detect it, you can change the current thru the windings with either method. It is possible to detect when the motor stalls or skips steps, then you can adjust the PWM duty cycle or speed until it runs as you want.

That makes sense. Basically I'd have to tune it if I went with PWM. I'm thinking of using both now. The stepper library has a delay based off the setSpeed variable. I'm thinking if I can get a hold of it I can let it step with a digitalWrite, then after the delay, switch to an analogWrite just for holding. This way it can make a solid rotation, but pulse when it needs to sit still. I'm just wondering what kind of noise I'd get from it pulsing like that.

That is a great idea! Smart minds think alike. There is no noise that I can notice.

Turns out it was a little better than just a good idea (Thanks by the way :D), it works great! It wasn’t very hard either, I added a condition for when there is no step to basically step in place, but in the process check the delay and switch over to pwm if time has gone over.

The delay to switch over to pwm is twice the delay to wait for the next step which is determined by setSpeed. It seems to work better this way, rather than waiting only as long as the original step delay. Since setSpeed determines the delay, the higher the rpm results in less of a delay. My initial experiments show that 60rpm works fine, and that 50%(127) modulation is pretty cool, while 25%(63) still operates but may stall at times.

I do get a hum from the motor, but it stayed nice and cool 8)

I attached what I’ve done in a rar file if any one may be so curious. Just drop it in your libraries folder and load the example.

Thanks again!

StepperPWM.rar (5.81 KB)