programming VS-2 servo motor

Discussion in 'Embedded Systems and Microcontrollers' started by jayk, Dec 29, 2011.

  1. jayk

    Thread Starter New Member

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

    Code ( (Unknown Language)):
    1.  
    2. #include<avr/io.h>
    3. #include<compat/deprecated.h>
    4. #include<util/delay.h>
    5.  
    6. main()
    7. {
    8.    sbi(DDRD,5);
    9.    
    10.   while(1)
    11.   {
    12.      int i;
    13.  
    14.      for(i=10000; i > 0; i--)
    15.      {
    16.          sbi(PORTD,5);
    17.          _delay_ms(0.6);
    18.          cbi(PORTD,5);
    19.          _delay_ms(19.4);
    20.     }
    21.      
    22.      for(i=10000; i > 0; i--)
    23.      {
    24.          sbi(PORTD,5);
    25.          _delay_ms(1.5);
    26.          cbi(PORTD,5);
    27.          _delay_ms(18.5);
    28.      }
    29.  
    30.      
    31.      for(i=10000; i > 0; i--)
    32.      {
    33.          sbi(PORTD,5);
    34.          _delay_ms(2.4);
    35.          cbi(PORTD,5);
    36.          _delay_ms(17.6);
    37.      }
    38.  
    39.  
    40.    }
    41. }
    42.  
    43.  
     
    Last edited by a moderator: Dec 29, 2011
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Are you waiting long enough for it to move? 10000 X 20ms = 200 seconds
     
  3. jayk

    Thread Starter New Member

    Dec 18, 2011
    3
    0
    then how long should i wait.can you give me suggestion
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    According to the code it should change position every 200 seconds which is 3 minutes and 20 seconds.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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.
     
Loading...