How to PWM stepper motor?

Hi,
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.

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.

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.