servo motor controlling with atmega16

Discussion in 'Embedded Systems and Microcontrollers' started by stylediva, Jan 31, 2012.

  1. stylediva

    Thread Starter Member

    Dec 6, 2011
    72
    0
    i have written code for my servo motor which is HITECH HS-442..using atmega16..but with this code it is taking only 12 positions..i need to control the angles..what shud i do with this code??.

    Code ( (Unknown Language)):
    1.  
    2. #include<avr/io.h>
    3. #include<util/delay.h>
    4. float num1=0.1;
    5. int main()
    6. {
    7. DDRB=0xFF;
    8. PORTB=0x00;
    9. int i;
    10.  
    11. while(1)
    12. {
    13. for(i=1;i<=10;i++)
    14. {
    15. PORTB=(1<<0);
    16. _delay_ms(num1);
    17. PORTB=0x00;
    18. _delay_ms(20);
    19. num1=num1+.5;
    20. _delay_ms(1000);
    21. }
    22. }
    23. }
    24.  
     
    Last edited by a moderator: Jan 31, 2012
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Rewrite it to use timer/pwm. This is a simple example of the timing of servos, but if you want your micro to do anything else than simply output one signal, you need the timing to be independent of the main while loop. This way if you calculated anything else before finishing the loop, you would upset the timing.
     
Loading...