LV Motor Driver Demo Robot

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
 *Version: 1.0
 *Parker Dillmann
 *The Longhorn Engineer (c) 2013 
 *www.longhornengineer.com
 *
 *Check bottom of file for License.
 *
 *main.c file for the tiny robot.
 *
*/

#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;
    }
}

/*
┌──────────────────────────────────────────────────────────────────────────────────────┐
│                           TERMS OF USE: MIT License                                  │
├──────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this  │
│software and associated documentation files (the "Software"), to deal in the Software │
│without restriction, including without limitation the rights to use, copy, modify,    │
│merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    │
│permit persons to whom the Software is furnished to do so, subject to the following   │
│conditions:                                                                           │
│                                                                                      │
│The above copyright notice and this permission notice shall be included in all copies │
│or substantial portions of the Software.                                              │
│                                                                                      │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   │
│INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         │
│PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    │
│HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION     │
│OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE        │
│SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                │
└──────────────────────────────────────────────────────────────────────────────────────┘
*/