Robin2:

This is worrying. Stepper motors don’t use PWM.

Have a look at the links below.

i mean the signal i give to easydriver, i don’t really know its principle clearly,

but i think it is similar to the paragraph “Arduino Pulse Width Modulation (PWM)” in your article.

i only need to give the step and direction signal.

this code is copied from the link in my article.

i am using the modified version of this.

```
////////////////////////////////////////////////////////
// Stepper Motor skecth for use with the EasyDriver 3.1
////////////////////////////////////////////////////////
// Dan Thompson 2008
//
// Inpired by the code and chat on this thread.
// http://forum.sparkfun.com/viewtopic.php?t=10378&highlight=easydriver
//
// Use this code at your own risk.
// For all the product details visit http://greta.dhs.org/EasyDriver/
// For the full tutorial visit http://danthompsonsblog.blogspot.com/
//
int dirpin = 3;
int steppin = 12;
void setup() {
Serial.begin(9600);
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop()
{
int i;
digitalWrite(dirpin, LOW); // Set the direction.
delay(100);
Serial.println(">>");
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps.
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
digitalWrite(dirpin, HIGH); // Change direction.
delay(100);
Serial.println("<<");
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}
```

Robin2:

Post your code

And please use the code button </>

```
so your code looks like this
```

and is easy to copy to a text editor

Do you want the motor to move with a **speed** that is proportionate to the sine of the angle, or do you want it to move to a **position** that is proportionate to the sine of the angle ?

i think this is same, because if the function of angle varying with time is sine,

the function of angle speed varying with time is cosine.

Robin2:

When you say you want to “force a torsion” I wonder if a DC motor might be more suitable?

in fact, first i have the opinion same as you, but it’s the ask of my teacher.

and TAs told me that the DC motor is not easy to control its position.

Robin2:

Please describe the project you are trying to implement.

…R

Stepper Motor Basics

Simple Stepper Code

my project is to detect some factor such as damping coefficient in the motion of torsion

when you rotate the torsion a particular angle, obviously you will feel a restoring torque

and the torque is proportional to the angle in a suitable range.

so we can write down as I(theta)’’+k(theta)=0

theta = the angle of the torsion comparing with the balance position.

this is similar to S.H.M, so the torsion will rotate with clockwise direction, counterclockwise direction,…

and in reality, there is a damping torque which is proportional to angle speed in low speed.

the equation become as I(theta)’’+c(theta)+k(theta)=0

so the amplitude will decreasing in exponent way.

we have done the above, then we can fitting the point to find what we want to know.

you can see that in here

then, we want to observe the motion if we give a torque to the torsion periodical.

and we know any periodical function can be decompose as many sine function.

so we just focus on the torque varying with sine to time.

I(theta)’’+c(theta)+k(theta)=A*sin(wt)

and we know if the angle varying with time is sine,

then angle speed, angle acceleration and torque should be sine or cosine.

in fact, if i use the code above, i can observe that the amplitude will increase, decrease periodically.

it seem be a wave pack which superpose by many sine,

so i think it should can work, if i can make the angle varying with time is sine.