Pages: [1]   Go Down
Author Topic: How to PWM stepper motor?  (Read 587 times)
0 Members and 1 Guest are viewing this topic.
Luton,UK
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Taimur

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 14, 2013, 10:46:33 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Luton,UK
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Taimur

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: