This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

c program for rotating stepper motor to particular angle in 8051 microcontroller

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

Parents
  • 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.

Reply
  • 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.

Children