Thursday, April 2, 2015

L293DNE Motor Driver

I used the L293DNE a while back in a prototype robot and thought it might be worthwhile documenting it.  I've since replaced the L293DNE with a Pololu TB6612FNG board and am now using 6V motors instead of the 3V Tamiya models.

Here is a picture of the prototype with a MSP430F5529 on top running things:



Here is the test code and a description of the circuit for those that are interested:

/*
This is a motor control circuit using a TI L293DNE motor
controller used with a MSP432-F5529LP to drive
a toy Tamiya tank with two motors. 


Note that the Tamiya motors operate at 3V and the feed is
routed through LD1117AV33's to get the voltage down. 


Note: Do not use PWM below about 50% or motors can stall -
suggest using PWM to balance motor speed only.

L293DNE
-------
1      MCU 39 (P2.4) - Enable pin
2      MCU 2 (P6.5) - Left Motor Logic pin 1
3      Left Motor Terminal 1
4      Heat sink / ground
5      Heat sink / ground
6      Left Motor Terminal 2
7      MCU 3 (P3.4) - Left Motor Logic pin 2
8      Motor Power Supply - 5.0V reduced to 3.3V for Tamiya
9      MCU 40 (P2.5) - Enable pin
10     MCU 4 (P3.3) - Right Motor Logic pin 1
11     Right Motor Terminal 1
12     Heat sink / ground
13     Heat sink / ground
14     Right Motor Terminal 2
15     MCU 5 (P1.6) - Right Motor Logic pin 2
16     IC Power Supply - 5.0V (used separate supply than LP)


LD1117AV33 - connect all motor terminal through these (4)
----------
1      5.0 V
2      GND
3      3.3 V


Tamiya Motors
-------------
Connect terminals to 3.3 V output from LD1117AV33 above


Capacitors
----------
See LD1117AV33 datasheet
suggests 10uF on output and 100nF on input


Frank Milburn   22 Feb 2015
*/

const int leftMotor1Pin = 2;
const int leftMotor2Pin = 3;
const int leftEnablePin = 39;

const int rightMotor1Pin = 4;
const int rightMotor2Pin = 5;
const int rightEnablePin = 40;

void setup()
{
  pinMode(leftMotor1Pin, OUTPUT);
  pinMode(leftMotor2Pin, OUTPUT);
  pinMode(leftEnablePin, OUTPUT);
  pinMode(rightMotor1Pin, OUTPUT);
  pinMode(rightMotor2Pin, OUTPUT);
  pinMode(rightEnablePin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Starting motor test");
 
}

void loop()
{
  Serial.println("Forward");            // start with left side
  digitalWrite(leftMotor1Pin, LOW);     // set leg 1 of H-bridge low
  digitalWrite(leftMotor2Pin, HIGH);    // set leg 2 of the H-bridge high
  digitalWrite(rightMotor1Pin, LOW);    // now right side  
  digitalWrite(rightMotor2Pin, HIGH);   
  digitalWrite(leftEnablePin, HIGH);    // enable motors on
  digitalWrite(rightEnablePin, HIGH); 
  delay(2000);

  Serial.println("Stop");
  digitalWrite(leftEnablePin, LOW);     // disable the motors
  digitalWrite(rightEnablePin, LOW);
  delay(1000);
 
  Serial.println("Backwards");
  digitalWrite(leftMotor1Pin, HIGH);    // Reverse the motors
  digitalWrite(leftMotor2Pin, LOW);
  digitalWrite(rightMotor1Pin, HIGH);    
  digitalWrite(rightMotor2Pin, LOW);
  digitalWrite(leftEnablePin, HIGH);    // enable motors on
  digitalWrite(rightEnablePin, HIGH);
  delay(2000);
 
  Serial.println("Stop");
  digitalWrite(leftEnablePin, LOW);     // disable the motors
  digitalWrite(rightEnablePin, LOW);
  delay(1000); 
 
  Serial.println("Forward 3/4 speed");
  digitalWrite(leftMotor1Pin, LOW);     // Set both sides forward
  digitalWrite(leftMotor2Pin, HIGH);    
  digitalWrite(rightMotor1Pin, LOW);    
  digitalWrite(rightMotor2Pin, HIGH);
  analogWrite(leftEnablePin, 192);      // enable motors on at reduced speed with PWM
  analogWrite(rightEnablePin, 192);
  delay(2000);
     
  Serial.println("Stop");
  digitalWrite(leftEnablePin, LOW);     // disable the motors
  digitalWrite(rightEnablePin, LOW);
  delay(1000);
}

No comments:

Post a Comment