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

318 10. SYSTEM LEVEL DESIGN
Seaperch
Control System
five position
joystick
direction
motor
control
ROV
direction
motor
assertion
motor
interface
left
thruster
vertical
thruster
right
thruster
light emitting
diodes (LEDs)
interface
LED
assertion
left
LED
vertical
LED
right
LED
Figure 10.2: SeaPerch ROV structure chart.
10.1.5 MICROCONTROLLER CODE
To properly configure the joystick connection to Port P2 of the MSP430F5438 experimenter board,
we must study the port configuration in detail. Figure 10.5 provides a diagram of the internal
configuration of one pin associated with Port P2 and the registers used to configure the port.
Register P2DIR is used to set the direction of a P2 pin (0 for input, 1 for output). In this
example, we set port P2[7:1] to input and P2[0] to output since it is not in use.The P2SEL register
determines if the P2 pin will be used for digital input/output (0) or the alternate function of the
specific pin (1). For an input pin, the P2REN and P2OUT registers are used to enable the internal
resistor and select it for either pullup (1) or a pulldown (0) configuration. With the pin settings
provided in Figure 10.5, observe the logic settings.
We also must properly configure port P4. On the MSP430F5438 experimenter board, the
majority of the port P4 pins are routed to the Port X,Y header connector. Port P4[4] is hardwired
10.1. SUBMERSIBLE ROBOT 319
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
joystick dedicated connections:
- left/port P2.1
- right/starboard P2.2
- select/dive P2.3
- up/bow P2.4
- down/stern P2.5
RC
+
RB
5.0 VDC
left
RC
+
RB
5.0 VDC
left
RC
+
RB
5.0 VDC
left
4.3
4.5
4.6
left
vertical
right
M
DC motor
supply voltage
+
-
30K
IN1
IN2
LTC1157
MOSFET
driver
+
10 uF
3.3 VDC
G1
G2
M
+
-
MTD3055EL
power FET
30K
4.0
4.1
left
thruster
vertical
thruster
M
+
-
30K
IN1
IN2
LTC1157
MOSFET
driver
+
10 uF
3.3 VDC
G1
G2
4.2
right
thruster
Figure 10.3: SeaPerch ROV interface control.
320 10. SYSTEM LEVEL DESIGN
include files
global variables
function prototypes
initialize ports
while(1)
read joystick position
(bow, stern,
starboard, port, dive)
bow?
while bow
asserted?
assert left, right thruster
assert left, right LED
yes
bow
stern
starboard
dive
port
joystick
asserted
no
yes
dive?
while dive
asserted?
assert vertical thruster
assert vertical LED
yes
stern
:
starboard
:
port
no
yes
no
yes
no
no
Figure 10.4: SeaPerch ROV UML activity diagram.
10.1. SUBMERSIBLE ROBOT 321
Port P2
76543210
P2DIR = 0x01
00 00 00 01
P2SEL = 0x0100 00 00 01
P2OUT = 0xFE
P2REN = 0xFE
11 11 11 10
11 11 11 10
Port P4
76543210
P4DIR = 0xFF
P4SEL = 0x0000 00 00 00
P4OUT = 0x00
P4REN = 0xXX
XX XX XX XX
11 11 11 11
00 00 00 00
X: dont care (no impact on current design)
down/
stern
up/
bow
select/
dive
right/
starboard
left/
port
right
LED
vertical
LED
left
LED
right
vertical
vertical
vertical
left
vertical
External
port pin
Joystick
switch
Figure 10.5: Port P2. Figure used and adapted with permission of Texas Instruments.
322 10. SYSTEM LEVEL DESIGN
to the amplifier input. For this specific application, we configure all port P4 pins to output and
configure the associated port registers as shown in Figure 10.5.
The code to control the SeaPerch ROV is constructed using the UML activity diagram
provided in Figure 10.4 as a guide.
//***********************************************************************
#include "msp430x54x.h"
unsigned char new_port_p2;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //hold WDT
P2DIR = 0x01; //configure port P2 (0:input, 1:output)
P2SEL = 0x01; //P2 select (0:digital I/O, 1:alternate func)
P2OUT = 0xFE; //P2 out - when input selects resistor
// (0: pulldown, 1: pullup)
P2REN = 0xFE; //P2REN - resistor enable
// (0: disable resistor, 1: enable resistor)
P4DIR = 0xFF; //configure port P4 (0:input, 1:output)
P4SEL = 0x00; //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)
while(1)
{
new_port_p2 = (P2IN & 0xFE); //read port P2 - mask pin 0
switch(new_port_p2)
{
case 0x02: //left/port button pushed
P4OUT = 0x0C; //assert left LED signal and
break; //right motor

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