Controlling DC motors using MSP430 Launchpad and L293D

Pinterest icon

msp430 launchpad interfaced with L293D  controlling two dc motors

In this tutorial we will control two DC brushed motors using MSP430 Launchpad (MSP430G2553) and L293D Motor Driver IC (Robot Shield). L293D is a quadruple high-current half-H driver IC which can be used for controlling DC brushed motors,solenoids,relays etc.The IC contains 4 half H drivers which can be combined together to create two full H bridge circuits for controlling two DC brushed motors.The L293D is designed to provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V,Here we will be running the motors at 12V.

In this tutorial we will be using MSP430 Motor Control Booster Pack  (also known as RobotShield V1.0) which contains a L293D Motor driver IC as well as a RS485 Driver chip which can be used to control the motors remotely or to build a Robot.

Buy MSP430 Motor Control Booster Pack from here  Buy MSP430 Launchpad Shield for Motor Control from here

The shield is designed to be used with the MSP430 Launchpad (MSP430G2553) development board from Texas Instruments.You can purchase the booster pack from here.The figure below shows the shield along with the MSP430 Launchpad. 


link to xanthium enterprises repo on Github containing code for serial communication using CSharp and Dot net Framework 

All the C source files and Circuits used in this tutorial  can be downloaded from our GitHub Page.

Please use the codes in the MSP430-Booster-Pack-DC-Motor-Control " Folder in the Repository. 

If you are new to Github Check this article to download code .




Photo of MSP430 launchpad along with the Motor control shield based on L293D

Intro into L293D Motor Driver Chip

In this tutorial we are going to control a DC brushed motor using the L293D motor driver chip on the MSP430 Robot shield board .The L293D contains 4 half H bridge drivers that can be combined together for bidirectional control of two Motors.L293D operates on a 5V supply(VCC1,Pin16) and has a seperate input for the Motor supply (VCC2,Pin8).The motors I am using are rated at 12V so i am connecting the VCC2 pin of L293D to 12V input and VCC1 to 5V (supply for the chip L293D).In the case of Motor Control Booster Pack, just connect the 12V input to Screw terminal P2 (bottom left connector on the green board above),the 5V volt is automatically generated by the onboard voltage regulators.Please ensure that the polarities are correct while connecting 12V to P2.

block diagram of L293D motor driver chip

The above figure shows a simplified block diagram of the L293D chip.Here the two Orange triangles on the top represent a pair of half H bridge drivers which are  combined together to control the Right Motor M1.The Green triangles at the bottom represents the other two half H bridges (L293D has 4 half H bridge drivers)  that are combined together to control Motor M2.

The Pins 1A,2A,1&2_EN,3A,4A and 3&4_EN  are TTL logic compatible pins that are connected to the microcontroller pins for controlling the Motors while the Pins 1Y,2Y,3Y and 4Y are high voltage (12V to 36V) ,high current pins (upto 600mA ) which are connected directly to the motor coils .The L293D has integrated diodes to prevent back EMF's so no external diodes are required.

Controlling the Motor

A single L293D chip can be used for the bidirectional control of two DC motors (Start,Stop,Clockwise rotation,AntiClockwise rotation).In the above case of Motor M1 a full H bridge is formed by using the 2 half H bridge drivers (Orange triangles) controlled by pins 1A and 2A.

The enable pins of the drivers (Orange triangles) are connected together and brought outside the chip as a single pin 1&2_EN . Making the enable pin 1&2_EN logical HIGH would enable both the drivers and making it logical LOW would disable the two drivers. When the enable pin (1&2_EN ) is disabled ie at logical LOW the Motors connected to Pins 1Y and 2Y are disabled irrespective of the logic levels of 1A and 2A.

Rotational direction of the motor connected to L293D ic controlled by changing the direction of the current flowing through the motor pins (1Y,2Y or 3Y,4Y).

If you make 1A High and 2A Low ,current will from 1Y to 2Y and motor will rotate in one direction.If you make 1A LOW and 2A HIGH,current will from 2Y to 1Y and the motor will rotate in the opposite direction.

When both 1A and 2A are at the same logic levels ie both 1A and 2A HIGH or LOW ,no current flows and the motor stops.The enable pin of the corresponding half H bridges should be high(in this case 1&2_EN =1) for the actions said above to have any effect.

The following table shows the logic levels of 1A and 2A and the actions associated with it.Here H means logic High,L means logic Low and X means Dont care.The directions Forward and Reverse are relative and is intented to show that motor rotates in opposite directions.

L293D truth table

For controlling the second Motor ie Motor Left (M2) just replace 
1A with 3A,
2A with 4A ,

1Y with 3Y
2Y with 4Y 


1&2_EN with 3&4_EN in the above table 

Circuit Diagram

The Port 2 of MSP430G2553 (on Launchpad) is interfaced with L293D motor control chip on the Robot Shield.P2.0 is used to enable the 1&2_EN pin of L293D and P2.6 is used to enable the 3&4_EN pin of L293D .Since by default P2.6 is used for crystal input you have to select port functions in the Port selection register to use P2.6 pin of MSP430.

interfacing MSP430G2553 launchpad with L293D motor Control chip

interfacing L293D with Dc motor circuit diagram

All the Port 2.0 pins that are used for controlling the L293D chip are also connected to LED's so that you can see the status of all the control pins which makes debugging quite easy.

Complete circuit diagram of the Motor Control Booster Pack can be downloaded from here.



The code for controlling the motors using Robot Shield is written in embedded C and is compiled using IAR embedded workbench for MSP430.The zip file containing the code contains two C files one for controlling a single motor (L293D-Single-Motor-Control.c) and other for controlling the two motors simultaneously (L293D-Dual-Motor-Control.c).Here we are going to discuss the first one ie controlling a single motor.

The program will run the motor connected to MOTOR_L (Connector P9)  in clockwise direction for a few seconds,stop,rotate the motor in opposite direction and stop.Here we are going to use the half H Bridge drivers associated with pins 3A and 4A as shown in the below figure.In Robot Shield the connection 3Y and 4Y are terminated at terminal block connector P9 or MOTOR_L.

H bridge circuit using L293D for controlling DC brushed motor

MSP430G2553 is connected to the L293D as shown in the below figure.Please note that only a section of the connection relevent to the program is shown (connection between MSP430 and L293D for controlling LEFT MOTOR) ,the full circuit is available here.

connection between msp430 and L293D for controlling the Left motor.

3Y and 4Y are terminated at the connector P9 or MOTOR_L. 

The code for controlling the Left motor is given below.

#include "msp430g2553.h"
void main()
  WDTCTL =  WDTPW + WDTHOLD;    // Stop the Watchdog
  void Delay(int j);
  P2SEL  &= ~BIT6;              // Clear P2.6 in P2SEL  (by default Xin)
  P2SEL2 &= ~BIT6;              // Clear P2.6 in P2SEL2
  P2DIR  |=  BIT3 + BIT4 + BIT6; // P2.3,P2.4,P2.6 all output
  P2OUT  &= ~BIT3 + BIT4 + BIT6; // Clear P2.3,P2.4,P2.6  
  // Rotate the Motor clockwise
  P2OUT |= BIT3; // P2.3 = 1,P2.4 = 0
  P2OUT |= BIT6; // P2.6 = 1 ,3&4_EN = 1,Motor is started
  Delay(10);     // Rotate motor for sometime
  // Stop the motor 
  P2OUT &= ~BIT3 + BIT4; // P2.3 = 0,P2.4 = 0
  Delay(5);              // Stop the motor for sometime 
  // Rotate the Motor Counter clockwise
  P2OUT &= ~BIT3; // P2.3 = 0
  P2OUT |=  BIT4; // P2.4 = 1
  P2OUT |= BIT6;  // P2.6 = 1 ,3&4_EN = 1,Motor is started
  Delay(10);      // Rotate motor for sometime
  P2OUT &= ~BIT6; // P2.6 = 0,3&4_EN = 0,Motor is stoped
}//End of Main

void Delay(int j)
  int i;

P2.6 is Xin by default so to access the port function you have to explicitly clear the registers in P2SEL and P2SEL2.

All the source codes can be downloaded from here.

Place the Robot shield on top of the MSP430 Launchpad board so that RS485 connector P4 is directly above the USB connector of the MSP430 Launchpad board as shown in the below figure.

msp430 launchpad motor control booster pack

Now connect the terminals of your DC motor to Connector name MOTOR_L.

Connect the Power supply (12V) to connector P2 (green connector(TBC),top left side in the above figure).Make sure that you observe correct polarities (+ve to +ve,-ve to -ve) while connecting the power cable(12V) to P2.Switch on the powersupply (12V) ,the two LED's Marked 5V and 3V near P2 will glow showing the Power supply is working OK.You can measure the voltages by removing the jumpers P12 and P11.

Now connect the Launchpad to your PC using USB cable and download the code into your controller.Run the code in your IDE and you can see the motor rotating.The LED's B1 and B2 will show the logic levels at Pins 3A and 4A ,Led D7 will show the status of the enable Pin 3&4_EN.

If you are interested you can check out our next article about implementing a PWM based speed control for DC motors.