Go Down

Topic: How to PWM stepper motor? (Read 806 times) previous topic - next topic

taimur21

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

PaulS

Quote
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.

HazardsMind

#2
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.
1000
0100
0010
0001

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:
https://github.com/AndrewMascolo?tab=repositories

taimur21

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

PaulS

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.

macavity

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