Tuesday, August 16, 2011

MSP430 uC to Toy Tank


---
The goal was to learn how to program and interface the MSP430 microcontroller with a toy tank and make it drive autonomously in a square after a button is pressed. The project demonstrates simple control of two DC motors (output) and the ability to process a button press (input) with the MSP430. There was no goal to create a pretty robot and I guess I got that done as well. ;)

The material list:
$12.00 toy tank,
$4.30 TI MSP430 LaunchPad,
$2.50 SN754410NE Quad Half H-Bridge

The program is written in C and uploaded into the MSP430 via the Code Composer Studio 4.1 software.

Get your own MSP430 LaunchPad micro controller here for only $4.30.

A few early build pics:
Original Tank (with AirSoft cannon)
---
Here it is five minutes later...
---
The remote control was removed from the tank. The motor wires were hooked straight into the motor driver chip that was controlled by the MSP430 LaunchPad.
---
Below is the source code for the project:
=================
//MSP430 rogram to make tank drive in a square after button push. June 11, 2011
//After the square is complete the tanks waits for a button push to repeat process.
#include msp430g2231.h

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
P1DIR |= 0x40; // Set P1.6 to output direction

volatile long i;
volatile int j;

// RED LED in RIGHT motor. GREEN LED is LEFT motor

P1OUT = 0x41; // Stop motors (both LEDs ON) and
while ((P1IN & 0x08)); // wait for button press on P1.3


for (;;)
{

for (j=1; j<5 data-blogger-escaped-br="br" data-blogger-escaped-j="j"> {
P1OUT = 0x00; // RIGHT and LEFT OFF 'FORWARD'
for (i=0; i<100000 data-blogger-escaped-a="a" data-blogger-escaped-br="br" data-blogger-escaped-delay="delay" data-blogger-escaped-i="i" data-blogger-escaped-little="little">
P1OUT ^= 0x40; // LEFT ON (turn LEFT)
for (i=0; i<20000 data-blogger-escaped-a="a" data-blogger-escaped-br="br" data-blogger-escaped-delay="delay" data-blogger-escaped-i="i" data-blogger-escaped-little="little">
P1OUT =0x00; // Both OFF
for (i=0; i<50000 data-blogger-escaped-a="a" data-blogger-escaped-br="br" data-blogger-escaped-delay="delay" data-blogger-escaped-i="i" data-blogger-escaped-little="little">
} //end J loop

P1OUT =0x41; // Stop motors (both LEDs ON) and
while ((P1IN & 0x08)); // wait for button press


} //endless loop
} //main
-----