O'Reilly logo

Microcontroller Programming and Interfacing Texas Instruments MSP430 by Daniel J. Pack, Steven F. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

352 10. SYSTEM LEVEL DESIGN
to the motors via a transistor (NPN, TIP35) with enough drive capability to handle the maximum
current requirements of each motor.The robot may be powered from onboard batteries using a 5 VDC
regulator for the sensors (7805) and a 3.3 VDC regulator for the motors and the microcontroller.
Alternatively, the robot may be powered by a 5 VDC power supply via an umbilical cable with a 3.3
VDC onboard regulator for the motors and the microcontroller.
10.5.4 STRUCTURE CHART
The structure chart for the robot project is provided in Figure 10.16.
10.5.5 UML ACTIVITY DIAGRAMS
The UML activity diagram for the robot is shown in Figure 10.17.
10.5.6 MICROCONTROLLER CODE
Provided below is the code for controlling the Blinky 602A robot in a maze. Here are some items
of interest related to the code:
Portions of the code were adapted from examples provided by Texas Instruments and written
by Smertneck and Goh.
The code has been compartmentalized into reusable functions.
Bit names to set register values are defined in the msp430x54x.h header file.
Thresholds and delays need to be experimentally determined since they are related to the
physical dimensions of the maze.
//****************************************************************
//include file****************************************************
#include "msp430x54x.h"
//function prototypes*********************************************
void hold_watchdog(void);
void initialize_ports(void);
void readADC12(unsigned char);
void determine_robot_action(void);
void perform_robot_action(void);
//Global Variables*************************************************
unsigned int lt_sensor, ct_sensor, rt_sensor;
unsigned int turn_left=0, straight_ahead=1, turn_right=2, reverse=3;
unsigned int robot_action;
10.5. AUTONOMOUS MAZE NAVIGATING ROBOT 353
IR sensor
left
P7.4
IR sensor
middle
IR sensor
right
5 VDC 5 VDC
5 VDC
Sensor connection:
- Red: 5 VDC
- Yellow: Signal output
- Black: Ground
M
3 VDC
at 100 mA
+
-
1N4001
motor
current
3.3 VDC
TIP35
right motor/wheel
interface
240
4.1
CCR1
M
3 VDC
at 100 ma
+
-
1N4001
3.3 VDC
TIP35
motor
current
240
left motor/wheel
interface
P4.0
CCR0
pin 1
reset
JP4
JP5
LCD
crystal
joystick
accelerometer
5.0
6.7
7.5
7.7
3.4
3.6
4.0
4.2
4.5
4.7
5.5
8.5
5.1
7.4
7.6
Gnd
3.5
3.7
4.1
4.3
4.6
5.4
7.3
8.6
P7.5
P7.6
Sensor Input
L
0
0
0
0
1
1
1
1
C
0
0
1
1
0
0
1
1
R
0
1
0
1
0
1
0
1
Turn
Left
Turn
Right
Straight
Ahead
Reverse
0
0
0
1
0
0
0
0
0
0
1
0
0
0
1
0
1
1
0
0
1
1
0
0
0
0
0
0
0
0
0
1
Figure 10.15: Robot circuit diagram.
354 10. SYSTEM LEVEL DESIGN
ReadADC12
ch for
conv
left
IR sensor
right
IR sensor
middle
IR sensor
PWM_left
left
motor
PWM_right
right
motor
desired
motor
action
determine_robot
_action
sensor
data
robot
action
Figure 10.16: Robot structure diagram.
unsigned int threshold = 0x_______; //Experimentally determined
void main(void)
{
hold_watchdog();
initialize_ports();
while(1)
{
//Read sensor values
readADC12(0x04); //Read left_sensor
lt_sensor = ADC12MEM4;
readADC12(0x05); //Read center_sensor
ct_sensor = ADC12MEM5;
readADC12(0x06); //Read right_sensor
rt_sensor = ADC12MEM6;
determine_robot_action(); //Determine robot action
10.5. AUTONOMOUS MAZE NAVIGATING ROBOT 355
include files
global variables
function prototypes
initialize ports
initialize ADC12
initialize Timer B PWM
while(1)
read IR sensor inputs
(left, middle, right)
determine robot
action
issue PWM motor
control signals
Figure 10.17: Robot UML activity diagram.
perform_robot_action(); //Maneuver robot to avoid
//maze walls
delay(); //Experimentally determined
}
356 10. SYSTEM LEVEL DESIGN
}
//***********************************************************************
void hold_watchdog(void)
{
WDTCTL = WDTPW + WDTHOLD; //hold Watchdog Timer
}
//***********************************************************************
void initialize_ports()
{
//Port P4 - output for 74HCT154
P4DIR = 0xFF; //configure port P4 (0:input, 1:output)
P4SEL = 0x06; //P4 select (0:digital I/O, 1:alternate func)
P4OUT = 0x00; //P4 out - when input selects resistor
// (0:pulldown, 1: pullup)
P4REN = 0x00; //P4REN - resistor enable
// (0: disable resistor, 1: enable resistor)
//Port P7 - ADC
P7DIR = P7DIR & 0x8F; //configure port P7 (0:input, 1:output)
//P7.4, P7.5, 7.6 analog inputs, other pins
// unchanged
P7SEL = 0x70; //P4 select (0:digital I/O, 1:alternate func)
//P7.4, P7.5, P7.6 analog input
P7OUT = 0x00; //P4 out - when input selects resistor
// (0:pulldown, 1: pullup)
P7REN = 0x00; //P4REN - resistor enable
// (0: disable resistor, 1: enable resistor)
}
//***********************************************************************
//readADC12(unsigned char channel) This function provides a single
//ADC conversion on the specified channel.
//
//An external reference is used. The MSP430F5438 Experimenter Board is
//configured with AVcc, pin 11 connected to 3.3 VDC and the AVss, pin 12

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required