PWM Control (For Stepper)

I need to run a stepper at variable rpm. I have a stepper driver. I was previously using a digital output but the frequency does not go fast enough.

I would like to use a pwm output but I am having trouble to find out how to do this. I seem to always see duty cycle, but not control the frequency. I have an arduino uno, and was going to get a arduino tiny to take a potentiometer input, and change the pulse frequency of a fast pwm output.

I am sure there is some pic timing chip that would do what i am talking about, but it just seems like it should be so easy with an arduino.

It is not that hard:

playground.arduino.cc/Main/TimerPWMCheatsheet
http://
and I think here too

The Arduino does not control a stepper with PWM. That is used to control the speed of DC motors. Stepper motors are controlled by "step" pulses.

What stepper motor driver board are you using?

Post your stepper code that is not fast enough.

...R

I need to run a stepper at variable rpm.

Can you elaborate ? It's kind of hard to write a program for changing the rpm without knowing the criteria and specs for the rpm change. Is it random or do you have criteria for how and when (or why ) it changes and by how much ? Do you think you could share that with us so we know where to start ?

I presume you're using a PWM output as the step-input to an offboard stepper controller? In that case, you can use tone() instead of analogWrite(), because it will set the frequency instead of the duty cycle. It's only good for one stepper though because you can't produce different tones on different outputs with the arduino base library, and it's difficult/impossible to keep track of the exact number of steps produced using this means.

If you want careful control of step speed, you probably want to use Timer1 and its attachInterrupt()/setPeriod() functions, and do your stepping events in the interrupt handler. That will give you microsecond-accurate arbitrary stepping. If it doesn't support calls to setPeriod inside the interrupt, you will need to write your own timer1 handling code but that's not particularly difficult if you read the mega328 datasheet.

thewormz:
I need to run a stepper at variable rpm. I have a stepper driver. I was previously using a digital output but the frequency does not go fast enough.

What frequency do you need?