This is the robot I quickly built to demo the Low Voltage Motor Driver. If is based off the Mr. Basic platform and MSP-430 Launchpad. It has a 6.4V lithium battery as the main power source which feeds into the voltage regulators on the Launchpad.
For direction control a top mounted servo spins a Sharp gp2y0d810z0f IR sensor. The sensor has a single data line which is pulled low when a object comes within 10cm of the sensor.
Code (CCS V5)
Project File
main.c
/*
*main.c VER1.0 For LV Demo Robot
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*Parker Dillmann
*www.longhornengineer.com
*/
#include "msp430g2553.h"
#include "isr_motor_pwm.h"
#define SERVO_1 BIT0
#define IR_SENSOR BIT1
#define TURN_DELAY 1000
unsigned int servo_counter = 0;
unsigned int servo1pos = 1500;
unsigned int increment = 1;
unsigned int delay = 0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_8MHZ; //Set DCO to 8Mhz
DCOCTL = CALDCO_8MHZ; //Set DCO to 8Mhz
__enable_interrupt(); //Interrupts Enabled
// Setup Servo ports
P1OUT &= ~SERVO_1;
P1DIR |= SERVO_1;
// Setup IR sensor port
P1DIR &= ~IR_SENSOR;
P1REN |= IR_SENSOR;
// Setup Servo Interrupt
TA0CCTL0 = CCIE;
TA0CCR0 = 1500;
TA0CTL = TASSEL_2 + MC_1 + ID_3;
init_motors();
//repeat till judgement day
while(1)
{
if ((P1IN & IR_SENSOR) == 0x00)
{
if(servo1pos < 1500)
{
move_motors(-300,-10);
}
else
{
move_motors(-10,-300);
}
delay = TURN_DELAY;
}
else
{
if (delay == 0)
{
move_motors(90,90);
}
}
if(servo1pos > 2000)
{
increment = 0;
}
else if(servo1pos < 1100)
{
increment = 1;
}
if(delay == 0)
{
if(increment == 0)
{
servo1pos = servo1pos - 1;
}
else
{
servo1pos = servo1pos + 1;
}
}
if (delay > 0)
{
delay = delay - 1;
}
__delay_cycles(3000);
}
}
//Servo Interrupt
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
if(servo_counter == 0)
{
P1OUT |= SERVO_1;
TA0CCR0 = servo1pos;
servo_counter++;
}
else
{
TA0CCR0 = 20000 - servo1pos;
P1OUT &= ~(SERVO_1);
servo_counter = 0;
}
}



