go away spammer

Author Topic: Motor driver + Arduino mega = Nothing happening  (Read 4137 times)

0 Members and 1 Guest are viewing this topic.

Offline starscorchedTopic starter

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
Motor driver + Arduino mega = Nothing happening
« on: July 08, 2009, 02:44:58 AM »
Hi

I've been trying for sometime now to get two motors running through the arduino mega board. It just isnt happening. Would be grateful for suggestions/advice! Details below:

Two 12V, 1A DC motors through this motor driver (MC33887 Dual motor driver)  and 7.2v battery > http://www.pololu.com/catalog/product/712


According the MC33887 datasheet :
Quote
IN1 = Logic input control of OUT1 (i.e., IN1 logic HIGH = OUT1 HIGH)

IN2 = Logic input control of OUT2 (i.e., IN2 logic HIGH = OUT2 HIGH)

EN = Enable control of device (i.e., EN logic HIGH = full operation, EN logic LOW = Sleep Mode)

OUT1, OUT2 = Output 1 and Output 2 of H-Bridge

D2 = Active LOW input used to simultaneously tri-state disable both H-Bridge outputs. When D2 is Logic LOW, both outputs are tri-stated.

D1 = Active HIGH input used to simultaneously tri-state disable both H-Bridge outputs. When D1 is Logic HIGH, both outputs are tri-stated.

Furthermore, it has this info regarding IN1, IN2, D1 and D2

Quote
LOGIC INPUT CONTROL AND DISABLE  (IN1, IN2, D1, AND D2):
These pins are input control pins used to control the outputs. These pins are 5.0 V CMOS-compatible inputs with hysteresis. The IN1 and IN2  independently control OUT1 and OUT2, respectively. D1 and D2 are complementary inputs used to tri-state disable the H-Bridge outputs. When either D1 or D2 is SET (D1 = logic HIGH or D2 = logic LOW) in the disable state, outputs OUT1 and OUT2 are both tri-state disabled; however, the rest of the circuitry is fully operational and the supply IQ  (standby) current is reduced to a few milliamperes.


My code to test drive both motors:

Code: [Select]
int motor1Input1 = 4 ;    // Motor1 inputs connected to pin 4 & 2
int motor1Input2 = 2;
int motor1Pwm= 9;         // Motor1 PWM pin
int motor2Input1= 7;      // Motor2 inputs connected to pin 7 & 5
int motor2Input2= 5;
int motor2Pwm= 11;        // Motor2 PWM pin
int ledPin = 13;          // LED on pin 13

void setup()                    
{
  pinMode(motor1Input1, OUTPUT);      // sets all pins as output
  pinMode(motor1Input2, OUTPUT);
  pinMode(motor2Input1, OUTPUT);
  pinMode(motor2Input2, OUTPUT);
  pinMode(ledPin, OUTPUT);
//  pinMode(motor2Pwm, OUTPUT); > Disabled this line as analogWrite doesnt need pinMode to be defined
//  pinMode(motor1Pwm, OUTPUT); > Same as above

}

void loop()
{
  digitalWrite(motor1Input1, HIGH);   // Motor1 on
  digitalWrite(motor1Input2,LOW);
  analogWrite(motor1Pwm,255);  // Motor1 PWM Pulse

  
  digitalWrite(motor2Input1, HIGH);   // Motor2 on
  digitalWrite(motor2Input2,LOW);
  analogWrite(motor2Pwm,255);  // Motor2 PWM Pulse
  digitalWrite(ledPin,HIGH); // LED test  
}


The connection schematics and truth table are attached below.

Any suggestions? Perhaps the code is all wrong...

Thanks
« Last Edit: July 08, 2009, 05:39:49 AM by starscorched »

Offline sonictj

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
    • Tim's Workshop
Re: Motor driver + Arduino mega = Nothing happening
« Reply #1 on: July 08, 2009, 11:57:37 AM »
can you show "your" wiring so we can see how you configured everything. Your code looks ok, but here is a suggestion to save on memory don't make constant integer variables.

example:
int ledPin =13;
this is constant so why not write
#define ledPin 13
(notice no semicolon)
« Last Edit: July 08, 2009, 12:04:44 PM by sonictj »

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Motor driver + Arduino mega = Nothing happening
« Reply #2 on: July 08, 2009, 02:04:45 PM »
According to the truth table, if D1 is disconnected, nothing works. You need to tie it LOW (to GND) for the driver to work. Personally, I would tie D2 HIGH and apply PWM on one of the input pins, with the other input pin setting the direction. So if the direction input pin is Low, the width of the High period of the PWM signal will vary the speed of the motor spining one way and if the direction pin is High, the Low period of the PWM signal will vary the speed of the motor spinning the other way (inverse PWM).
Check out the uBotino robot controller!

Offline starscorchedTopic starter

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
Re: Motor driver + Arduino mega = Nothing happening
« Reply #3 on: July 08, 2009, 04:35:15 PM »
I got it working finally! Figured out that D1 does indeed have to be connected. And that a faulty capacitor across the motor terminals was to be dumped!

Thanks for the valuable tip sonictj.btw, that pic (connection schematic) was how i had it connected.

Robotx, I tried what you suggested. It works alright, but i dont understand how thats very different from applying PWM to D2, and changing the state of the input pins to change direction? Please excuse if it sounds like a mighty dumb question!! Thanks for the info :)

 


Get Your Ad Here