Go Down

Topic: How to PWM stepper motor? (Read 1 time) previous topic - next topic


I am looking for any code examples about PWM control the stepper motor using arduino.


I am looking for any code examples about PWM control the stepper motor using arduino.

Steppers step. You can't use PWM to take 2/3 of a step.

Explain why you think you need to, or why you think you want to, misuse PWM to "control" a stepper motor.


Feb 14, 2013, 04:42 pm Last Edit: Feb 14, 2013, 04:46 pm by HazardsMind Reason: 1
Steppers move with a sequence of bits.

Depending on the rate at which you switch between the sequences, will control how fast the stepper rotates.

So what you could try is set up an array of bits (that would be considered a nibble above) and switch between them with a counter and a delay.
The smaller the delay is between the sequences, the faster it will switch the array and rotate.

You can do it with case statements too.
My GitHub:


I am actually using a position encoder(Potentiometer) for stepper motor and I want PWM to maintain the speed of stepper motor.


How are you making the stepper step? Are you using a motor shield of some sort?

Changing the speed of a stepper means changing when the stepper steps. PWM doesn't enter into it.


taimur21, are attempting to use pwm to do microstepping directly on an arduino?  if so, your going to need the duty cycle of the motor and figure out what position ( think degrees ) the motor is at and where it is going to.  Then it is a matter of trig to figure out how long to pulse the pin for each of the  leads to the motor.  I'm working on this myself at the moment.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131