+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 3
    Points: 904, Level: 6

    Join Date
    Dec 2009
    Posts
    4
    Helped
    1 / 1
    Points
    904
    Level
    6

    how to control 2 servo motors by atmega32 simultaneously

    I am driving 2 RC servo motors simultaneously in my robot.I am using atmega32 at 14.7456MHZ frequency. there are no errors when i connect one servo to atmega32, but when two servos connected to MCU, the motors rotate erratic. Can anyone give me suggestion?
    excuse me if there is any error in my post, my language isn't English.

    •   Alt6th May 2012, 19:33

      advertising

        
       

  2. #2
    Full Member level 5
    Points: 3,501, Level: 13
    js's Avatar
    Join Date
    Oct 2005
    Posts
    265
    Helped
    38 / 38
    Points
    3,501
    Level
    13
    Blog Entries
    1

    Re: how to control 2 servo motors by atmega32 simultaneously

    I think problem is in your power supply.... or maybe some induction on your control lines when one of motor is powered!
    Check your power supply first, large enough ELCOs..?!
    ______________________________________________

    Stupid questions are better than stupid mistakes.
    ______________________________________________



  3. #3
    Newbie level 3
    Points: 904, Level: 6

    Join Date
    Dec 2009
    Posts
    4
    Helped
    1 / 1
    Points
    904
    Level
    6

    Re: how to control 2 servo motors by atmega32 simultaneously

    thanks js.
    but what is the ELCOs? also i used a 5volt regulator for my power supply. is there any way to separate the motor power from MCU?



    •   Alt7th May 2012, 14:35

      advertising

        
       

  4. #4
    Full Member level 5
    Points: 3,501, Level: 13
    js's Avatar
    Join Date
    Oct 2005
    Posts
    265
    Helped
    38 / 38
    Points
    3,501
    Level
    13
    Blog Entries
    1

    Re: how to control 2 servo motors by atmega32 simultaneously

    ELCOs are condensators! :)
    http://nl.wikipedia.org/wiki/Elektro...he_condensator
    you must have enough good voltage and maybe RC filter between your MCU and servo power supply...
    ______________________________________________

    Stupid questions are better than stupid mistakes.
    ______________________________________________


    1 members found this post helpful.

    •   Alt7th May 2012, 14:41

      advertising

        
       

  5. #5
    Advanced Member level 5
    Points: 33,525, Level: 44
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    tpetar's Avatar
    Join Date
    Sep 2010
    Location
    Pancevo-Belgrade, Serbia
    Posts
    6,427
    Helped
    1731 / 1731
    Points
    33,525
    Level
    44

    Re: how to control 2 servo motors by atmega32 simultaneously

    Its looks like there is not enough power. But posting of circuit and firmware source will help if some troubleshooting is needed.



  6. #6
    Newbie level 3
    Points: 904, Level: 6

    Join Date
    Dec 2009
    Posts
    4
    Helped
    1 / 1
    Points
    904
    Level
    6

    Re: how to control 2 servo motors by atmega32 simultaneously

    here is the code that i used, written in codevision:
    __________________________________________________ ________________
    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    
    #include <mega32.h>
     
    // Standard Input/Output functions
    #include <stdio.h>
     
    // Declare your global variables here
     
    void main(void)
    {
    // Declare your local variables here
    int c1,c2,c3;
     
    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTA=0x00;
    DDRA=0x00;
     
    // Port B initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTB=0x00;
    DDRB=0x00;
     
    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTC=0x00;
    DDRC=0x00;
     
    // Port D initialization
    // Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In 
    // State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T 
    PORTD=0x00;
    DDRD=0xB0;
     
    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: Timer 0 Stopped
    // Mode: Normal top=FFh
    // OC0 output: Disconnected
    TCCR0=0x00;
    TCNT0=0x00;
    OCR0=0x00;
     
    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: 230.400 kHz
    // Mode: Ph. & fr. cor. PWM top=ICR1
    // OC1A output: Non-Inv.
    // OC1B output: Non-Inv.
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer 1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=0xA0;
    TCCR1B=0x13;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x2D;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;
     
     
    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=0x00;
    MCUCSR=0x00;
     
    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x00;
     
    // USART initialization
    // Communication Parameters: 8 Data, 1 Stop, No Parity
    // USART Receiver: On
    // USART Transmitter: Off
    // USART Mode: Asynchronous
    // USART Baud rate: 115200
    UCSRA=0x00;
    UCSRB=0x10;
    UCSRC=0x86;
    UBRRH=0x00;
    UBRRL=0x07;
     
    // Analog Comparator initialization
    // Analog Comparator: Off
    // Analog Comparator Input Capture by Timer/Counter 1: Off
    ACSR=0x80;
    SFIOR=0x00;
     
     
     
    while (1)
          {
          // Place your code here  
          scanf("%d %d",&c1,&c2); 
          OCR1A=c1;
          OCR1B=c2;      
                   
          };
    }
    __________________________________________________ ________________


    and the circuit is:
    Click image for larger version. 

Name:	Untitled12.png 
Views:	27 
Size:	37.6 KB 
ID:	73817
    Last edited by alexan_e; 7th May 2012 at 19:17. Reason: added SYNTAX tags



  7. #7
    Advanced Member level 5
    Points: 33,525, Level: 44
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    tpetar's Avatar
    Join Date
    Sep 2010
    Location
    Pancevo-Belgrade, Serbia
    Posts
    6,427
    Helped
    1731 / 1731
    Points
    33,525
    Level
    44

    Re: how to control 2 servo motors by atmega32 simultaneously

    My friend you cant drive motors like that, direct from uC pins. Its not healthy for uC. You should use transistors, uln,...


    1 members found this post helpful.

    •   Alt7th May 2012, 19:43

      advertising

        
       

  8. #8
    Newbie level 3
    Points: 904, Level: 6

    Join Date
    Dec 2009
    Posts
    4
    Helped
    1 / 1
    Points
    904
    Level
    6

    Re: how to control 2 servo motors by atmega32 simultaneously

    thanks. by using a more voltage than 5 volts, the problem solved.


    1 members found this post helpful.

  9. #9
    Advanced Member level 5
    Points: 33,525, Level: 44
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    tpetar's Avatar
    Join Date
    Sep 2010
    Location
    Pancevo-Belgrade, Serbia
    Posts
    6,427
    Helped
    1731 / 1731
    Points
    33,525
    Level
    44

    Re: how to control 2 servo motors by atmega32 simultaneously

    There is some fine project example with code:
    http://extremeelectronics.co.in/avr-...crocontroller/


    2 members found this post helpful.

--[[ ]]--