programming VS-2 servo motor

Thread Starter

jayk

Joined Dec 18, 2011
3
I have done the following program but servo motor is rotating fully. I cant control the angle.

Rich (BB code):
#include<avr/io.h>
#include<compat/deprecated.h>
#include<util/delay.h>

main()
{ 
   sbi(DDRD,5);
   
  while(1)
  { 
     int i;

     for(i=10000; i > 0; i--)
     {
         sbi(PORTD,5);
         _delay_ms(0.6);
         cbi(PORTD,5);
         _delay_ms(19.4);
    }
     
     for(i=10000; i > 0; i--)
     {
         sbi(PORTD,5);
         _delay_ms(1.5);
         cbi(PORTD,5);
         _delay_ms(18.5);
     }

     
     for(i=10000; i > 0; i--)
     {
         sbi(PORTD,5);
         _delay_ms(2.4);
         cbi(PORTD,5);
         _delay_ms(17.6);
     }


   }
}
 
Last edited by a moderator:

thatoneguy

Joined Feb 19, 2009
6,359
You are only setting and clearing port D.5, so it will only go in one direction, if it moves at all.

Need a schematic of how everything is hooked together to really give advice. Usually at least 3 pins are used, one for enable, and one for fwd/reverse or phase if using a stepper.
 
Top