Arduino Forum

Using Arduino => Motors, Mechanics, Power and CNC => Topic started by: sunfffd on Mar 26, 2012, 08:10 pm

Title: L298P motor shield wont work properly
Post by: sunfffd on Mar 26, 2012, 08:10 pm
Hi guys,

I'm trying to build a simple 2-wheel robot and trying to get my L298P motor driver to work properly.
However, the sketch only work partially, here's my setup and sketch.

Code: [Select]

int motorLE = 7;
int motorLI = 6;
int motorRE = 5;
int motorRI = 4;

void setup() {               
  pinMode(motorLI, OUTPUT); 
  pinMode(motorRI, OUTPUT);
}

void loop() {
  int value;
  for(value = 0 ; value <= 250; value+=5)
  {
    digitalWrite(motorRI,LOW);
    analogWrite(motorRE, value);
    digitalWrite(motorLI,LOW);   
    analogWrite(motorLE, value);
    delay(100);
  }
}



- Arduino Mega 2560, using a 12V power supply

- L298P motor controller board, using a 7.4V Lipo battery, connected to the VSS and Ground
- 2x tamiya motors

There is a Input and Enable for each motor, I connected them to my PWM ports on the 2560.

The motors wont move if I dont short the VMS=VSS pins together (can anyone tell me why?), so well then I connected them.

Now the motors are working, but only under certain conditions:







MotorA InputMotorB InputResult
LOWLOWMotors move in the same direction
HIGHHIGH Both Motors stopped moving, one of them shaking
LOWHIGHMotors move in the opposition direction
LOWLOWBoth Motors stopped moving


And if I run the sketch above, only one motor will change its speed according to the loop, the other just keep spinning at the same speed.

I tried different wiring and codes but still cant crack this, any clue?
Title: Re: L298P motor shield wont work properly
Post by: dxw00d on Mar 26, 2012, 08:41 pm
Do you have a link to your motor board?
Title: Re: L298P motor shield wont work properly
Post by: sunfffd on Mar 26, 2012, 08:45 pm
HI here's the board spec, hope it helps..

http://emartee.com/product/42002/L298P%202A%20Motor%20Drive%20Shield%20%20Arduino%20Compatible
Title: Re: L298P motor shield wont work properly
Post by: SurferTim on Mar 26, 2012, 09:50 pm
Unless you are using a Mega, digital pin 7 does not have PWM. This is from the reference under analogWrite:
Quote
On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13.


You might want to try switching the pins around, like use 5 and 6 for the PWM.

Title: Re: L298P motor shield wont work properly
Post by: sunfffd on Mar 27, 2012, 05:17 pm
I'm using a Mega,
nonetheless I also tried to use pin 3,5 for analogWrite, but not successful

Title: Re: L298P motor shield wont work properly
Post by: SurferTim on Mar 27, 2012, 05:41 pm
Quote
MotorA Input   MotorB Input   Result
LOW   LOW   Motors move in the same direction
HIGH   HIGH    Both Motors stopped moving, one of them shaking
LOW   HIGH   Motors move in the opposition direction
LOW   LOW   Both Motors stopped moving

And if I run the sketch above, only one motor will change its speed according to the loop, the other just keep spinning at the same speed.

I tried different wiring and codes but still cant crack this, any clue?


That truth table is good, but missing two pins. Those are the inputs for direction? How are the two enable pins set for those results?

edit: I would not use the PWM until I got the motors working correctly strictly on-off and the correct direction. Use digitalWrite() as an on-off switch. How does that do?
Title: Re: L298P motor shield wont work properly
Post by: sunfffd on Mar 27, 2012, 06:48 pm
Quote

That truth table is good, but missing two pins. Those are the inputs for direction? How are the two enable pins set for those results?

edit: I would not use the PWM until I got the motors working correctly strictly on-off and the correct direction. Use digitalWrite() as an on-off switch. How does that do?



Hi , first, yes the input pins are for direction, the enable pins are set to a constant speed like analogWrite(motorRE, 200).

And second, thanks for your suggestion on testing with digitalWrite() first!  

The two motors now work correctly as I tested with the following sketch

Code: [Select]

int motorLE = 7;
int motorLI = 6;
int motorRE = 5;
int motorRI = 4;
int forward = 0;

void setup() {                
 pinMode(motorLI, OUTPUT);  
 pinMode(motorRI, OUTPUT);
 pinMode(motorLE, OUTPUT);
 pinMode(motorRE, OUTPUT);
}

void loop() {
 int value;
 
 if (forward ==0){
     digitalWrite(motorRI, HIGH);
     digitalWrite(motorLI, HIGH);
     forward = 1;
   }else{
     digitalWrite(motorRI, LOW);
     digitalWrite(motorLI, LOW);
     forward = 0;
   }
 digitalWrite(motorLE, HIGH);
 digitalWrite(motorRE, HIGH);

}


So the question now is if my motor board is supporting the PWM signals correctly?
Title: Re: L298P motor shield wont work properly
Post by: SurferTim on Mar 27, 2012, 07:09 pm
Quote
So the question now is if my motor board is supporting the PWM signals correctly?


That is the next question. I would use the same testing procedure on the speed. Change the PWM cycle time on only one of the motors. Run it slowly up to full speed and back down to stopped with the PWM. Then try the other motor. Don't mess with the direction, just the speed. How does that do?


Title: Re: L298P motor shield wont work properly
Post by: sunfffd on Mar 28, 2012, 12:58 pm


That is the next question. I would use the same testing procedure on the speed. Change the PWM cycle time on only one of the motors. Run it slowly up to full speed and back down to stopped with the PWM. Then try the other motor. Don't mess with the direction, just the speed. How does that do?



Not sure if I fried my motor board today,
and looks like the left motor channel got some problem, it only spins one way, when the sketch switch the input and tells it to reverse, the motor power led is on but it isnt spinning in reverse.

My arduino was powered by USB before when I tested the motor board, and the motor board connects to the 5V and GND of the arduino, with external lipo on the other side

Today I tried to plug a 12V DC power supply on the arduino board, then one channel start to behave strangely.

Then I tried switching digital pins and motors, it seems that one motor channel is having trouble going backwards
Title: Re: L298P motor shield wont work properly
Post by: SurferTim on Mar 28, 2012, 01:44 pm
Quote
Then I tried switching digital pins and motors, it seems that one motor channel is having trouble going backwards


Sounds like one of the L298P internal MOSFETs has failed.
Title: Re: L298P motor shield wont work properly
Post by: sunfffd on Mar 28, 2012, 03:25 pm

Quote
Then I tried switching digital pins and motors, it seems that one motor channel is having trouble going backwards


Sounds like one of the L298P internal MOSFETs has failed.



looks like so, is there anyway to verify it?

or is there any other better motor driver i should try?
Title: Re: L298P motor shield wont work properly
Post by: sunfffd on Apr 03, 2012, 05:08 pm
got a new board, both motors working with PWM now
case solved!