Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
dryanhuston
PostPosted: Jul 26, 2012 - 07:36 AM
Wannabe


Joined: Mar 19, 2010
Posts: 52
Location: California

I don't know if this is a hardware issue or software. So if its not hardware will a mod move it to the correct forum.

I have an ATmega1284P driving 2 L298 Dual Full Bridge Drivers on a custom circuit. Currently I am running 4 FA-130 motors. I am using general I/O's for the direction and 4 PWM pins to set the duty cycle output of the L298's.

My issue is that when I program the AVR to output the same PWM signal, not all the motors spin at the same rate. I am 98% sure my software is set properly. I am using timer1 and timer2, mostly because of hardware design, which are configured the same.

Does anyone have a solid place to start for trouble shooting.

Or tips, suggestions, incite.

_________________
I am not encumbered by the restraints of the adult mind.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jul 26, 2012 - 01:11 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21274
Location: Orlando Florida

To be able to help, we need to see the schematic, and the c source.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
dryanhuston
PostPosted: Jul 26, 2012 - 06:02 PM
Wannabe


Joined: Mar 19, 2010
Posts: 52
Location: California

I am using a 18.432 crystal. The PCB has been changed around aref and avcc to allow for internal voltage reference. And pins 1 and 15 on both L298 now have .5ohms 3 watt resistors to ground. I do not have a schematic but I do have my PCB design.

I know I do not have great comments so if I need to comment anything let me know.

Code:

void setup(void){
   /** Timer1 Setup **/
   TCCR1A |= (1 << WGM10) | (1 << COM1A1) | (1 << COM1B1);
   TCCR1B |= (1 << CS10) | (1 << CS12);
   /** Timer2 Setup **/
   TCCR2A |= (1 << WGM20) | (1 << COM2A1) | (1 << COM2B1);
   TCCR2B |= (1 << CS20) | (1 << CS21) | (1 << CS22);
}
void motor_output_on(){
   DDRD |= (1 << DDD0) | (1 << DDD1) | (1 << DDD2) | (1 << DDD3) | (1 << DDD4) | (1 << DDD5) | (1 << DDD6) | (1 << DDD7);
   DDRC |= (1 << DDC0) | (1 << DDC1) | (1 << DDC6) | (1 << DDC7);
}
void motor_output_off(){
   DDRD &= ~(1 << DDD0) & ~(1 << DDD1) & ~(1 << DDD2) & ~(1 << DDD3) & ~(1 << DDD4) & ~(1 << DDD5) & ~(1 << DDD6) & ~(1 << DDD7);
   DDRC &= ~(1 << DDC0) & ~(1 << DDC1) & ~(1 << DDC6) & ~(1 << DDC7);
}
void right_front(int speed, int direction){
   if (direction == 0){ // Forward
      OCR2A = speed;
      PORTC |= (1 << DDC7);   // C = H
      PORTC &= ~(1 << DDC6);   // D = L
   } else if (direction == 1){ // Reverse
      OCR2A = speed;
      PORTC &= ~(1 << DDC7);   // C = L
      PORTC |= (1 << DDC6);   // D = H
   } else if (direction == 2){ // Fast Motor Stop
      OCR2A = speed;
      PORTC |= (1 << DDC6) | (1 << DDC7); // C = D
   } else if (direction == 3){ // Free Running Motor Stop
      OCR2A = 0; // C = X, D = X
   }
}
void right_rear(int speed, int direction){
   if (direction == 0){ // Forward
      OCR2B = speed;
      PORTC |= (1 << DDC0);   // C = H
      PORTC &= ~(1 << DDC1);   // D = L
   } else if (direction == 1){ // Reverse
      OCR2B = speed;
      PORTC &= ~(1 << DDC0);   // C = L
      PORTC |= (1 << DDC1);   // D = H
   } else if (direction == 2){ // Fast Motor Stop
      OCR2B = speed;
      PORTC |= (1 << DDC1) | (1 << DDC0); // C = D
   } else if (direction == 3){ // Free Running Motor Stop
      OCR2B = 0; // C = X, D = X
   }
}
void left_front(int speed, int direction){
   if (direction == 0){ // Forward
      OCR1BL = speed;
      PORTD |= (1 << DDD3);   // C = H
      PORTD &= ~(1 << DDD2);   // D = L
   } else if (direction == 1){ // Reverse
      OCR1BL = speed;
      PORTD &= ~(1 << DDD3);   // C = L
      PORTD |= (1 << DDD2);   // D = H
   } else if (direction == 2){ // Fast Motor Stop
      OCR1BL = speed;
      PORTD |= (1 << DDD2) | (1 << DDD3); // C = D
   } else if (direction == 3){ // Free Running Motor Stop
      OCR1BL = 0; // C = X, D = X
   }
}
void left_rear(int speed, int direction){
   if (direction == 0){ // Forward
      OCR1AL = speed;
      PORTD |= (1 << DDD1);   // C = H
      PORTD &= ~(1 << DDD0);   // D = L
   } else if (direction == 1){ // Reverse
      OCR1AL = speed;
      PORTD &= ~(1 << DDD1);   // C = L
      PORTD |= (1 << DDD0);   // D = H
   } else if (direction == 2){ // Fast Motor Stop
      OCR1AL = speed;
      PORTD |= (1 << DDD0) | (1 << DDD1); // C = D
   } else if (direction == 3){ // Free Running Motor Stop
      OCR1AL = 0; // C = X, D = X
   }   
}


_________________
I am not encumbered by the restraints of the adult mind.
 
 View user's profile Send private message  
Reply with quote Back to top
KitCarlson
PostPosted: Jul 27, 2012 - 03:18 AM
Resident


Joined: Feb 06, 2009
Posts: 835
Location: TN

Could it be that Timer1 is a 16 bit timer, and Timer2 is 8 bit?
Perhaps using 16 bit values on Timer1 will help. Try setting the OCR1 high registers instead of the low.

_________________
It all starts with a mental vision.
 
 View user's profile Send private message  
Reply with quote Back to top
ka7ehk
PostPosted: Jul 27, 2012 - 06:51 AM
10k+ Postman


Joined: Nov 22, 2002
Posts: 12055
Location: Tangent, OR, USA

Also, if you are using PWM as a simple proportional drive, rather than stepping, the motor speed will be a function of the motor (varies some from one to the next), the supply voltage, the circuit losses, and the load.

Are you sure that both PWMs have the same duty cycle? Can you check with a scope?

Jim

_________________
Jim Wagner
Oregon Research Electronics, Consulting Div.
Tangent, OR, USA

"The only thing standing between us and victory is defeat" P.G.Wodhouse in Wooster & Jeeves series
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits