Sir, i am using stepper motor of 2 degree step angle. I m using following c program:
#include<reg51.h> void main() { while(1) { void delay (int); P1=0xCC; delay(1); P1=0x66; delay(1); P1=0x33; delay(1); P1=0x99; delay(1); } } void delay(int a) { unsigned int x,y; for(x=0;x<10;x++) for(y=0;y<a;a++); }
But i want to rotate it to 80 degree only. I want to stop motor at 80 degree. Please give me the c program for this....??
So you want to rotate 80 degrees. And every step is 2 degrees. And you _really_ can't figure out how to stop the rotation after 40 steps???
thank u for your valuable reply..... bt m having problem for increasing the speed of rotation, I am using following code for delay :
void delay(int a) { for(i=0;i<1275;i++) for(j=0;j<a:j++); }
But when i am putting minimum value of a i.e. a=1, then i m getting the speed of 5.5 rpm..... So please tell me how can i increase the speed of rotation more than 20 rpm
Think about it. What happens if you try to step too fast? You think the stepper motor is able to have infinite acceleration?
So if you want a stepper motor to run fast, you have to gradually increase the step frequency.
Same thing when it's time to stop the rotation - you can't just instantly stop generating pulses but have to slow down the frequency until you have reached a speed where the stepper motor is able to finally stop if no more pulses are generated.
The need for acceleration/retardation will obviously depend on used motor, how you drive the current through the windings and what load you have that the motor should drive. So time for you to spend some time experimenting. We can't do it for you.
I agree with Andrew. Delays written in C are not exactly brillant.
If I remember correctly I have read something about timers and interrupts on micro-controllers. This combination is nearly unbeatable by software.
Idea:
* setup timer to start speed * setup counter-variable, how many steps * enable timer irq
on timer irq: * check counter-variable, if not zero do next step an decrement variable * possibly correct timer period to realize acceleration/deceleration
Be aware! Stepper motors are a challange. If you are going to optimize noise, torque, engine efficiency, ramps, detent torque and so on: you will be busy for a while. Not even thought about microstepping, stall detection or sinusoidal phase currents.
on timer irq: * check counter-variable, if not zero you have a malfunctioning chip.
Erik
you msy not have zero in the timer, some timers keep running after triggering the interrupt which happened when the count passed zero.
Note that "counter variable" in the post you commented on was not the counter register for the timer, but a normal variable to keep track of total movement of the stepper motor.
And correct - better timers will support continuous operation while issuing an interrupt. So they do not leak time before the ISR have time to restart the timer again.
I just sketched an idea.
"counter variable" was not meant to be the timer itself rather a counter to count the steps of the motor. The timer should be running independently. Favoured with autoreload if supported.