Lab 4Pre: MSP4301232 archival (2006) version of embedded coding
(continued from successful LabVIEW

2011-: 4Pre can be done only on "sink" computer with IAR software...

(4) Find a green connector card CB-68LP already hooked up to a MSP-FET 120 demo board with a MSP430F1232 28 pin chip in place.

See pinout of the F1232 below (in the case of Lab4lam you MUST use the F1232 chip, not the F123... same pinout, different A-D method...)

You may want to make sure you see the following connections of LabVIEW to MSP430:
D0 screw 52 to MSP430 pin 21 (P1.0) port 1/bit 0 is the LEFT motor direc control
D1 screw 17 to MSP430 pin 22 (P1.1) OUT: direc control for Right stepping motor
D2 screw 49 to MSP430 pin 17 (P3.6) output to inhibit motor, Left
D3 screw 47 to MSP430 pin 18 (P3.7) "   Right
D4 screw 19 to MSP430 pin 24 (P1.3) IN signal from lever switch on rover, Left
D5 screw 51 to MSP430 pin 23 (P1.2) "   Right lever switch
D6 screw 16 to MSP430 pin 11 (P3.0) IN signal from V-switch to start movement sequence
D7 screw 48 to MSP430 pin 12 (P3.1) (future wireless input) back up command
Green GND wire of MSP430 board to pin 53 (GND) of the LabVIEW connector card.
(P1.4-7 on the demo board are not available to the user)

Connect the CB-68LP to the 6024E cable. Make sure the MSP-FET 120 board is connected to its cable coming from the computer printer port. If the default Lab4Pre06.c "rebuilt" source code is already in the F123X chip on the board, then the following will be true:

1. The code will run an infinite loop [while(1)] that is continually waiting for D6 (start) to be toggled back and forth. In that WAIT FOR START state the 4 indicator lights on the left of the front panel are dark.

The left-most lights, L0 and L1, represent the directions of the left and right motors respectively, with both ON meaning forward, (if the L2 and L3 lights are also ON, representing ON-OFF on the motor controls).

2. After the START signal is received, all 4 lights will come on (green) and cannot be influenced for the next 3 seconds. L2 and L3 ON means both motors are uninhibited.

3. If no other switches are flipped, the code will run about 25 seconds, and between 15 to 20 seconds one of the lights L2, L3 will go out. After 25 seconds all lights will go out again while the code waits for another START flick.

4. If after 3 seconds ON the "left" switch (D4) is flicked ON and OFF you will see the second green light go off for 1 sec; if the "right" switch (D5) is flicked the first green light will go off for 1 second.
5. If both D4 and D5 are turned ON, the "back up" signal (both L0 and L1 OFF) will be seen until D4 and D5 are off.
6. if D6 is flicked a second time before the 25 seconds are up, then the motors will be inhibited (both L2 and L3 off) until the cycle is over.

IF you do not see the default code already at work in the MSP-LabVIEW combination, then you need to download compiled default code to the demo board:

The source code is Lab4Pre06.c and is in a read-only file in the EN123 IP folder. Copy and rename the C code in your own IP folder. Start up IAR Workbench 4. (desktop icon with green screwdriver crossed with wrench) (2006) ONLY THE FOUR LABVIEW COMPUTERS IN 095 AND THE NORTH COMPUTER IN 222A HAVE REV 4.0 OF THE IAR SOFTWARE WE WANT.

1. Start IAR Workbench 4. (2006: only on the 4 machines in 095)

2. Under File menu (or otherwise) create a new workspace. Don't try to name it yet!

3. From the Project menu create a project in the workspace. Name and save the project in your IP folder. Add the renamed MyLab4Pre06.c to the project, MyLab4.

4. With the name of the project highlighted, go to the Options part of the Project menu. Under the General category pick the particular MSP microcomputer in your board, likely MSP430F1232 or MSP430F123. Under the Debugger category of Options look at the Driver window and select FET Debugger. Hit OK.

5. Now is a time to save the workspace, with yet another name, in your IP folder.

6. Click on the MyLab4Pre06.c link and see the code. For now just hit Rebuild All under the Project menu, and see 0 Errors (maybe several warnings, all about unused variable names...)

7. Now under the Project menu click on Debug. If all is well with the computer, the cable, the board, the chip and the project options, you should see messages flash by that say "Erasing Main Memory" and "Downloading Application" if the download is successful.

8. IAR now puts you in the debugger. If you are sure about your code, you can just hit Go then Stop Debugging, and the microcomputer will be left in its infinite loop, waiting for a start signal. If you are downloading the default code, you should now see button-press features described above, in red.

So far, so good.

If you had problems downloading, make sure the cable from the printer port is connected to the JTAG connector, and that a MSP430F1232 chip is in the socket, properly oriented with the dimple at pin 1. Otherwise, call for help from JD.

Now your final challenge for Lab4Pre:
Conventions: D6 represents the V-switch on the back of the rover, and flipping it to its center position is the start signal. Let D4, D5 represent proximity switches for the front left and right sides of rover; Let L0 and L1 represent the directions of the wheels left and right. Both lights ON means rover going forward. For now, let L2 and L3 ON represent signals to uninhibit the left and right motors respectively. (Inhibit means the motor stops and "relaxes": offers no resistance to turning).

Modify your version of the default code so that when a left or right wall is detected (after being on for 3 seconds) the rover
1. Stops for one second (4 cycles)
2. Backs up for one second
3. Stops for another second
4. Turns to the center
(CW for left, CCW for right wall) for 3 cycles (each cycle is about 250 msec: 100 cycles for 25 seconds...)
5. Stops again for one second
6. Goes Forward until it hits another wall or time is up or (see below) D7 in switched ON.

Also, arrange that switch D7 turned ON causes the rover to
1. Stop one second
2. Go backwards until the D7 is turned OFF.
If D7 is OFF then the rover will not go backwards.
See suggested code below:
tstP3 = P3IN; // read port 3 and call it tstp3, a local variable
tstP3 &= 0x02; // mask out all but p 3.1, D7
while (tstP3 == 0x02) // where D7 is sent to pin 12 on the MSP430 chip
{
your backup code goes here...including some form of the line below...
P1OUT = mask_op(P1OUT, mask_zone, 0x00);
// also, inside the while loop keep checking on backup status by repeating
tstP3 = P3IN;
tstP3 &= 0x02;

}

Possible FTQ:
Explain how the C assignment statement works.
Explain how a While loop in C works.
Explain what base 16 notation is in the C language, and what the hex letter C is in base 10.

Free Advice: See Quickie C file for understanding of some default code. Consider describing your problem as a series of STATE changes: Forward to Inhibit to Reverse to Inhibit to Turn to Inhibit to Forward. Study the default code and its comments for what and how the C instructions work. Attend to assignment statement format, and if statement structure.

Consult the yellow IAR User Guide for information about the features of the debugger, including single-stepping through code.