go_away

Author Topic: DC Motor Control Program Help  (Read 792 times)

0 Members and 1 Guest are viewing this topic.

Offline hendrachubbyTopic starter

  • Full Member
  • ***
  • Posts: 49
  • Helpful? 0
DC Motor Control Program Help
« on: October 06, 2009, 07:40:15 AM »
Hello all,

I'm now program an ATmega2560 to control 5 DC Motor, I can control it one by one, but i can't control them simultaneously because i got trouble to combining my program.

here is my code to control the motor :

Code: [Select]
oid motor_control
(
    float duty_cycle_axis_1, int arah_axis_1,
    float duty_cycle_axis_2, int arah_axis_2,
    float duty_cycle_axis_3, int arah_axis_3,
    float duty_cycle_axis_4, int arah_axis_4,
    float duty_cycle_axis_5, int arah_axis_5
)
{   
    int input_1_axis_1, input_2_axis_1;
    int input_1_axis_2, input_2_axis_2;
    int input_1_axis_3, input_2_axis_3;
    int input_1_axis_4, input_2_axis_4;
    int input_1_axis_5, input_2_axis_5;
   
    //axis_1
    if (arah_axis_1 == kanan)
    {
        input_1_axis_1 = 1;
        input_2_axis_1 = 0;
    }
   
    if (arah_axis_1 == kiri)
    {
        input_1_axis_1 = 0;
        input_2_axis_1 = 1;
    }
    if (arah_axis_1 == stop)
    {
        input_1_axis_1 = 0;
        input_2_axis_1 = 0;
    }
       
    //axis_2
    if (arah_axis_2 == naik)
    {
        input_1_axis_2 = 1;
        input_2_axis_2 = 0;
    }
   
    if (arah_axis_2 == turun)
    {
        input_1_axis_2 = 0;
        input_2_axis_2 = 1;
    }
   
    if (arah_axis_2 == stop)
    {
        input_1_axis_2 = 0;
        input_2_axis_2 = 0;
    }
   
    //axis_3
    if (arah_axis_3 == naik)
    {
        input_1_axis_3 = 1;
        input_2_axis_3 = 0;
    }
   
    if (arah_axis_3 == turun)
    {
        input_1_axis_3 = 0;
        input_2_axis_3 = 1;
    }
    if (arah_axis_3 == stop)
    {
        input_1_axis_3 = 0;
        input_2_axis_3 = 0;
    }
   
    //axis_4
    if (arah_axis_4 == naik)
    {
        input_1_axis_4 = 1;
        input_2_axis_4 = 0;
    }
   
    if (arah_axis_4 == turun)
    {
        input_1_axis_4 = 0;
        input_2_axis_4 = 1;
    }
   
    if (arah_axis_4 == stop)
    {
        input_1_axis_4 = 0;
        input_2_axis_4 = 0;
    }
   
    //axis_5
    if (arah_axis_5 == kanan)
    {
        input_1_axis_5 = 1;
        input_2_axis_5 = 0;
    }
   
    if (arah_axis_5 == kiri)
    {
        input_1_axis_5 = 0;
        input_2_axis_5 = 1;
    }
    if (arah_axis_5 == stop)
    {
        input_1_axis_5 = 0;
        input_2_axis_5 = 0;
    }
   
    PORTA.0 = input_1_axis_1;
    PORTA.1 = input_2_axis_1;
    PORTA.2 = input_1_axis_2;
    PORTA.3 = input_2_axis_2;
    PORTA.4 = input_1_axis_3;
    PORTA.5 = input_2_axis_3;
    PORTA.6 = input_1_axis_4;
    PORTA.7 = input_2_axis_4;
    PORTF.2 = input_1_axis_5;
    PORTF.3 = input_2_axis_5;
   
    OCR5AH = MAX*duty_cycle_axis_1;
    OCR5AL = MAX*duty_cycle_axis_1;
    OCR5BH = MAX*duty_cycle_axis_2;
    OCR5BL = MAX*duty_cycle_axis_2;
    OCR5CH = MAX*duty_cycle_axis_3;
    OCR5CL = MAX*duty_cycle_axis_3;
    OCR1AH = MAX*duty_cycle_axis_4;
    OCR1AL = MAX*duty_cycle_axis_4;
    OCR1BH = MAX*duty_cycle_axis_5;
    OCR1BL = MAX*duty_cycle_axis_5;
}

so when i need to move all of them i just call :

Code: [Select]
motor_control(1,kiri,1,naik,1,naik,1,naik,1,turun); 

now i got problem because all of the motor using an encoder, so when i need to run the first motor with 1000 pulse of encoder i usually call this :

Code: [Select]
#asm ("sei");
while( encoder_axis_1 <= 3000 )
{        motor_control(0.7,kiri,0,stop,0,stop,0,stop,0,stop);  }
motor_control(0,stop,0,stop,0,stop,0,stop,0,stop);
encoder_axis_1 = 0;
#asm ("cli");

so the trouble is how to combine the encoder counting to motor_control function. moving all of the motor ( 5 motor ) simultaneously and each motor moving with different encoder pulse, any idea ?

 


Get Your Ad Here