robot car project report

63
Team Members Zachary Fearnside William Shaw Zijun Lu Joshua Ndon Checked: 12.2.2016 Originator: Zachary Fearnside Released: 12.2.2016 Title: Filename: Project Writeup Final This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited. Technical White Paper for Battery-Operated Car Model X306 Date: Document Number: Rev: Sheet: 1 of 63 12/2/2016 1-4500-3-2016-1 F Technical White Paper for Battery-Operated Car Model X306 December 2016 Revision Description A.1 Zachary Fearnside setup project template and drew block diagrams A.2 Diego Barcenas wrote an initial copy of Scope A.3 William Shaw wrote first part of hardware section A.4 Zachary Fearnside wrote second part of hardware section A.5 Diego Barcenas edited entire hardware and added photos A.6 William Shaw wrote test portion A.7 Zijun Lu edited entire document A.8 Zijun Lu added photos throughout document B.1 Zachary Fearnside wrote block diagrams B.2 Diego Barcenas wrote hardware structural section B.3 William Shaw wrote testing section changes from previous section B.4 Zachary Fearnside edited previous red marks from last revision

Upload: william-shaw

Post on 08-Feb-2017

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Robot Car Project Report

Team Members Zachary Fearnside William Shaw Zijun Lu Joshua Ndon 0-0002-001-0001-00 Document Format Sheet

Checked: 12.2.2016

Originator: Zachary Fearnside

Released: 12.2.2016

Title: Filename: Project Writeup Final

This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Technical White Paper for Battery-Operated Car Model X306

Date: Document Number: Rev: Sheet:

1 of 63 12/2/2016

1-4500-3-2016-1 F

Technical White Paper for Battery-Operated Car Model X306

December 2016

Revision Description A.1 Zachary Fearnside setup project template and drew block diagrams A.2 Diego Barcenas wrote an initial copy of Scope A.3 William Shaw wrote first part of hardware section A.4 Zachary Fearnside wrote second part of hardware section A.5 Diego Barcenas edited entire hardware and added photos A.6 William Shaw wrote test portion A.7 Zijun Lu edited entire document A.8 Zijun Lu added photos throughout document B.1 Zachary Fearnside wrote block diagrams B.2 Diego Barcenas wrote hardware structural section B.3 William Shaw wrote testing section changes from previous section B.4 Zachary Fearnside edited previous red marks from last revision

Page 2: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

2 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

B.5 Diego Barcenas added additional photos of test section and structural section B.6 William Shaw edited abbreviations and new overview B.7 Zijun Lu wrote LCD hardware section B.8 Zijun Lu wrote propulsion hardware section C.1 Zijun Lu reorganized file structure C.2 Zachary Fearnside cleaned up revision section and fixed autoformatting of document for future use C.3 William Shaw fixed propulsion section C.4 Zachary Fearnside, William Shaw, and Zijun Lu looked over entire document and made small fixes D.1 Zachary Fearnside fixed previous errors. D.2 Zachary Fearnside added new test section on ADC and fixed file formatting. D.3 Joshua Ndon wrote software description D.4 Joshua Ndon wrote first portion of flowchart D.5 Zijun Lu wrote section on hardware and thumbwheel D.6 Zijun Lu edited ADC test section D.7 William Shaw wrote second portion of flowchart D.8 William Shaw edited document structure E.1 Zachary Fearnside added the hardware edits in E.2 Zijun Lu added the block diagram edits in E.3 William Shaw added the software description section edits in E.4 Joshua Ndon added the flowchart edits in E.5 Zachary Fearnside added serial port code E.6 Joshua Ndon added serial port flowchart E.7 William Shaw added the serial port software description E.8 Zijun Lu added additional photos in and fixed previous grammatical errors F.1 Zachary Fearnside added two code functions F.2 Joshua Ndon added two code functions F.3 William Shaw added one code functions F.4 Zijun Lu wrote the communication portions F.5 Zachary Fearnside wrote software descriptions and a flow chart F.6 Joshua Ndon wrote the remainder of the software descriptions F.7 William Shaw wrote the remainder of the flowcharts F.8 Zijun Lu compiled the remainder of the workload and did previous edits

Page 3: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

3 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Table of Contents 1. Scope ............................................................................................................................................................. 52. Abbreviations .................................................................................................................................................. 53. Overview ......................................................................................................................................................... 5

3.1 Processing Blocks ....................................................................................................................................... 53.2 Sensor Blocks ............................................................................................................................................. 63.3 Power Blocks .............................................................................................................................................. 63.4 User Interface Blocks .................................................................................................................................. 73.5 Propulsion Blocks ....................................................................................................................................... 73.6 Structural Blocks ......................................................................................................................................... 73.7 Communication Blocks ............................................................................................................................... 8

4. Hardware ........................................................................................................................................................ 84.1 Processing System ..................................................................................................................................... 84.2 Sensor System ............................................................................................................................................ 94.3 Power System ........................................................................................................................................... 114.4 User Interface ........................................................................................................................................... 124.5 Propulsion System .................................................................................................................................... 134.6 Structural System ...................................................................................................................................... 144.7 Communication System ............................................................................................................................ 17

5. Power Analysis ............................................................................................................................................. 176. Test Process ................................................................................................................................................. 18

6.1 U1 Testing ................................................................................................................................................. 186.2 Testing the Power System ........................................................................................................................ 196.3 Testing the Completed Power System ...................................................................................................... 196.4 Testing the LCD ........................................................................................................................................ 206.5 Testing the N-FETS and P-FETS ............................................................................................................. 216.6 Testing the ADC and Detection Systems .................................................................................................. 226.7 Testing the Serial Communication System ............................................................................................... 23

7. Software Description .................................................................................................................................... 26 7.1 Description of Main .................................................................................................................................... 26 7.2 Description of Ports ................................................................................................................................... 26 7.3 Description of Timers ................................................................................................................................. 26 7.4 Description of ADC .................................................................................................................................... 26 7.5 Description of Interrupts ............................................................................................................................. 27 7.6 Description of Serial Communication ......................................................................................................... 27

7.7 Description of Detect Black Line ............................................................................................................... 277.8 Description of Reset WiFi.......................................................................................................................... 277.9 Description of Check Dissociation ............................................................................................................ 277.10 Description of Status Report ................................................................................................................. 277.11 Description of Command Receiving ...................................................................................................... 27

8. Flowcharts .................................................................................................................................................... 288.1 Main Flowchart .......................................................................................................................................... 298.2 Port Initialization Flowchart ....................................................................................................................... 308.3 Timer Flowchart ........................................................................................................................................ 318.4 ADC Flowchart .......................................................................................................................................... 328.5 Interrupt Flowchart .................................................................................................................................... 338.6 Serial Flowchart ........................................................................................................................................ 348.7 Detect Black Line ...................................................................................................................................... 358.8 Reset WiFi ................................................................................................................................................. 368.9 Check Dissociation ................................................................................................................................... 378.10 Status Report ........................................................................................................................................ 388.11 Command Receiving ............................................................................................................................. 39

9. Software Listing ............................................................................................................................................ 409.1 Main .......................................................................................................................................................... 409.2 Ports .......................................................................................................................................................... 429.3 Timers ....................................................................................................................................................... 489.4 ADC ........................................................................................................................................................... 50

Page 4: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

4 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

9.5 Interrupts (ADC, Timer, and Port) ............................................................................................................. 529.6 Serial Code (Send and Receive Transmissions) ...................................................................................... 559.7 Miscellaneous Functions ........................................................................................................................... 57 i. Detect Black Line ...................................................................................................................................... 57 ii.Reset WiFi ................................................................................................................................................ 58 iii. Check Dissociation ................................................................................................................................... 58 iv. Status Report ............................................................................................................................................ 59 v.Command Receiving ................................................................................................................................ 60

Table of Figures Figure 1 - Total System Block Diagram ..................................................................................................................... 5Figure 2 - Power Block Diagram ............................................................................................................................... 6Figure 3 - Propulsion Block Diagram ......................................................................................................................... 7Figure 4 - Structural Block Diagram .......................................................................................................................... 8Figure 5 - Communication Block System .................................................................................................................. 8Figure 6 - FRAM Experimenter Board Overview ....................................................................................................... 9Figure 7 – Emitter and Detector Angling ................................................................................................................. 10Figure 8 – Circuit of Detector .................................................................................................................................. 10Figure 9 – Diagram of IR LED and IR phototransistor placement ........................................................................... 11Figure 10 - J2 and Switch Layout ............................................................................................................................ 11Figure 11 - Sepic Converter Circuit Diagram .......................................................................................................... 12Figure 12 - LCD Schematic ..................................................................................................................................... 12Figure 13 - Thumb Wheel ........................................................................................................................................ 13Figure 14 - J2 Pin Diagram and Interconnect .......................................................................................................... 13Figure 15 – Left Motor H Bridge .............................................................................................................................. 14Figure 16 – Right Motor H Bridge ............................................................................................................................ 14Figure 17 - Acrylic Drilling Pattern ........................................................................................................................... 15Figure 18 - Nylon Screws Connecting PCB to Standoffs ........................................................................................ 16Figure 19 - Steel Screws Connecting Standoffs to Acrylic Board ........................................................................... 16Figure 20 - Serial Port UCA1 ................................................................................................................................... 17Figure 21 - IOT (UCA0) Module .............................................................................................................................. 17Figure 22 - Capacity vs Power Drain Graph ............................................................................................................ 18Figure 23 - U1 Testing Point ................................................................................................................................... 19Figure 24 - PWS Testing ......................................................................................................................................... 19Figure 25 – J2 Testing Point ................................................................................................................................... 20Figure 26 – 3.3V Testing Point ................................................................................................................................ 20Figure 27 - LCD Displaying Test Message .............................................................................................................. 20Figure 28 – Q21 Test Point ..................................................................................................................................... 21Figure 29 – Q41 Test Point ..................................................................................................................................... 21Figure 30 - Total Serial Communication System ..................................................................................................... 23Figure 31 - Jumper Test Positioning 1 .................................................................................................................... 23Figure 32 - Jumper Test Positioning 2 .................................................................................................................... 24Figure 33 - Jumper Test Positioning 3 .................................................................................................................... 24Figure 34 - Jumper Test Positioning 4 .................................................................................................................... 25Figure 35 - Full Pin Connection Setup .................................................................................................................... 25

Page 5: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

5 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

1. Scope This document describes the electronic components of the battery-operated car system as well as the software to control it. The battery-operated car will be broken into subsystems and described in greater detail. The electronic car will have several capabilities: to move in the x-y plane, to be user controlled, to communicate over Wi-Fi, and to run on battery power. The main controller of the car will be a laptop issuing basic commands such as forward, reverse, left, and right. The car will also feature basic shock protection as well as the ability to traverse small obstacles using a two motor and three-wheel assembly. In addition, the car will be able to follow a line using a color sensor. The line specified for this model will be a black line on a white surface. This will be accomplished via a detector circuit on the underside of the vehicle.

2. Abbreviations Abbreviation Definition

UI user interface

BOC battery operated car

MCU microcontroller unit

PCB printed circuit board

PWS power system

I/O input and output

LED light emitting diode

FRAM ferroelectric random access memory

LCD liquid crystal display

DUT device under test

ADC analog-to-digital converter

3. Overview The system consists of a processor fed by a power regulating circuit.

Figure 3.0 – Total Block Diagram

3.1 Processing Blocks

The processing system’s main component is the processor which controls the system and is used as the “brain.” The processor is required to start up the system, configure it, and keep it running. This part of the system is contained on its own circuit board and receives a constant level of power from the power system. It also sends

Processing

Power

User Interface

Propulsion

Sensing

Communication

Figure 1 - Total System Block Diagram

Page 6: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

6 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

commands to the user interface. The processor is dependent on the timers to keep the many parts of the system synchronous. The system interfaces with the environment through the processing subsystem.

Figure 3.1 – Processing Block Diagram

3.2 Sensor Blocks The sensor subsystem interfaces with the outside world through a set of IR emitters and detectors. The IR emitter is pointed to bounce IR light off the surface below it. This IR light is reflected in differing quantities depending on both the composition and color of the floor below it. The detectors can find changes in the color of the surface under the vehicle. The detectors give off a voltage that corresponds with the darkness of the material below it. Through an ADC, the processor can read this voltage and take an action depending on the value it receives.

3.3 Power Blocks The power system takes an uncertain level of power from a set of AA batteries, converts it to a standard power that will run the rest of the system, and distributes it throughout the car. To ensure the batteries are not being drained all the time, there is a power switch which only lets the batteries connect to the rest of the system when it is in the on position. There is also a converter which does the actual task of converting the voltages from the batteries to a usable amount.

Figure 3.2 – Power Block Diagram

Figure 2 - Power Block Diagram

Switch

Batteries

Converter

Processor

ADC

Timers

IR Detector

IR Emitter

IR Detector Left

IR Emitter

IR Detector Right

Page 7: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

7 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

3.4 User Interface Blocks The user interface block contains 8 LEDs used to communicate the status of the BOC to the user. The 8 LEDs will blink in a pattern in which the lights slowly move to the inside of the board once it is powered. If the lights do not blink, then the user knows that either the power or processor subsystem is not working correctly. The LEDs main purpose is to inform the user which motor ports are currently activated including left forward, right forward, left reverse, and right reverse. In addition, a small LCD is located on the top of the board to display messages to the user. The LCD displays information on the current state of the car including what commands the car is currently operating on. The user can input commands into the system using the two switches located on the FRAM experimenter board called SW1 and SW2. These switches can be used to scroll through a menu which lets the user select what movement pattern they would like the car to perform. A more sophisticated input is the thumb wheel, and is configured to give the user the ability to scroll through a menu.

Figure 3.3 - User Interface Block Diagram

3.5 Propulsion Blocks The propulsion system contains 2 different motors, two LEGO car wheels, and a caster wheel. The motors are driven by commands given by the processor. Each motor drives one wheel to propel the car forward or backwards. The purpose of the caster wheel is to reduce the friction that would occur with a bipedal vehicle. A structural support exists to hold the motors, processor, and caster wheel together. This will be detailed further in the next section.

Figure 3.3 - Propulsion Block Diagram

3.6 Structural Blocks The structural system contains an acrylic board to which all other components are mounted. The processor system is connected to the acrylic board via four nylon standoffs, nylon screws, and metal screws. The caster wheel and motors are attached to the acrylic board using Zip Ties. Additional Zip Ties are used as a horizontal stabilizer for the motors and are attached to the nylon stand offs. The LEGO wheels are connected to the motors using LEGO cylinder to cross point adapters.

LEGO Wheel,

Left

Caster Wheel

LEGO Wheel,

Right

Motor, Left

Motor, Right

Figure 3 - Propulsion Block Diagram

LEDs

LCD

Switch 1

Switch 2

Thumb Wheel

Page 8: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

8 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 3.3 - Structural Block Diagram

3.7 Communication Blocks The communication system contains two serial communication ports, A0 and A1, and an IOT module capable of WiFi communication. The car will communicate can communicate with a computer over a mini-usb cord or over the IOT module. The control board communicates with the IOT device through port A1.

Figure 5 - Communication Block System

4. Hardware The following sections will detail each subsystem above in much more technical detail.

4.1 Processing System The processing subsystem is mainly comprised of an MCU. The MCU used is the MSP-EXP430FR5739 FRAM Experimenter Board which is contained on its own PCB. An MCU was chosen for its ability to be quickly integrated into the BOC and communicate with several peripherals. The board contains an emulation section which allows for quick programming and debugging of the system in case of technical difficulties. A diagram is provided below of the MSP-EXP430FR5739 FRAM Experimenter Board from Texas Instrument’s User Guide in figure 4.0.

Figure 4 - Structural Block Diagram

Screws

Nylon Standoffs

Acrylic Board

Zip Ties

A0 Tx/Rx Port

IOT WiFi Module

A1 Tx/Rx Port

Page 9: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

9 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 6 - FRAM Experimenter Board Overview

Not all of the capabilities of the FRAM Experimenter Board will be utilized. The MCU only controls LED0 to LED8 and blinks them to inform the user of the status of the board. The board is connected to a second board (the controller board) by four series of connectors. The connectors include two series of 1x12 pins, a series of 1x4 pins, and a series of 2x5 pins. The two twelve pin series are the VCC to P1.7 pins and the P1.0 to the pin at the top right portion of the middle section of the FRAM Experimenter Board. The 1x4 series of pins are the right four of the six pin series to the top left of the FR57xx chip in the center of the board. The other board consists of the power system. The MCU contains the ability to interact with the outside world through its detector, emitter, and ADC systems. The ADC system can convert the analog values from the sensor system into a usable digital value to take an action upon.

4.2 Sensor System

As shown in the figure Emitter and Detector Angling, the middle diode is the emitter and the outside diodes are detectors which will handle left and right black-line detection prospectively. The black line detector system consists of an infrared light emitting diode and infrared phototransistors as shown in the circuit diagram below. The conductance of the phototransistor will increase as the detecting infrared signal rises. By adding a pull-up resistor to the phototransistor’s collector, the voltage will fall when the infrared energy increases. If the IR LED and IR phototransistor are arranged side by side as shown in the reflection diagram below, the IR phototransistor can pickup reflected light from the IR LED. The amount of reflection varies by the objects color - anywhere from black to white. In short, Q1 is acting as a variable resistor, and as more energy is detected, the voltage divider gets larger and less energy is available at the node labeled V_DETECT_L and V_DETECT_R.

Simply comparing this voltage against a fixed threshold to determine if an object is present will work poorly, as the reflected IR energy is much weaker than changes in background IR intensity resulting from room lights, shadows, etc. Therefore a calibration method was created and is detailed in the software portion of the document. The basis

Page 10: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

10 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

of the system is to take an initial reading of both the white area and the black line and use this reading to select a representative value for the transition between black and white.

Figure 7 – Emitter and Detector Angling

Figure 8 – Circuit of Detector

Page 11: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

11 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 9 – Diagram of IR LED and IR phototransistor placement

4.3 Power System The power subsystem consists of three major components. The first major component are the batteries. The batteries are four AA batteries connected in series in a hard shell to improve durability of the connections. A series style connection was chosen to boost the total voltage of the system to a level that was more easily utilized by the converter in the later part of the subsystem. A single AA battery’s nominal voltage is 1.5V which would cause a 6.0V drop across the battery pack if each battery was at nominal voltage. This voltage is much more useful to us than a 1.5V system with higher current. The battery pack is connected to the controller board via J2 which is connected in series with the power switch, SW1. In figure 4.2, the connection point is shown. SW1 allows the user to open the power circuit to turn off the BOC and conserve power as there is not a standby mode. When SW1 is farther away from J2, the system is on and vice versa.

Figure 10 - J2 and Switch Layout

When SW1 is in the on position, the battery pack is connected to the converter. The converter system contains a Linear Technology LT1930A dc/dc converter which is configured by manipulating the resistors and capacitors

Page 12: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

12 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

between its pins. A schematic is displayed below in figure 4.2 and contains the values of the various resistors and capacitors required to get the 3.3V output that the processor subsystem and FRAM Experimenter Board requires to operate.

Figure 11 - Sepic Converter Circuit Diagram

In the figure, U1 is the LT1930A. With the circuit above, the boost converter performs as a sepic converter with the ability to regulate the raw input from the batteries to a stable input until the batteries are depleted.

4.4 User Interface The LEDs take commands from the software ran through the processor. They receive power from the power

system circuit and turn on and repeat a pattern showing the user that software and hardware are running properly. The LCD consists the display screen and back light. It can be preprogrammed to display up to four lines of text message with ten characters for each line on the display screen. Also the back light can be turned on or off by programming. As shown figure 4.3 the schematic below, the N-FET which installed at Q51 helped LCD subsystem to be connected onto the controlled board.

Figure 12 - LCD Schematic

The switches located on the control board are the last component of the user interface system and are configurable to either act as a Hi-to-Low or Low-to-Hi interrupt. These switches serve as a secondary option for inputting commands into the BOC. The primary purpose of these switches are for debugging both hardware and software issues in the car. The thumb wheel has 1024 discrete points that can be read by the onboard ADC; however, the thumb wheel resolution is too poor and it would be impossible to hit 1 specific point with any degree of accuracy.

Page 13: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

13 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

To combat this, the thumb wheel is split up into roughly 8 sections to give the user an easier time of selecting an option on the screen. The thumb wheel was installed shown on R3 in the figure below. The thumb wheel is a typical three-pins resistor with a rotatable dial. By rotating the dial, any number between 0 and 1023 can be read by the ADC.

Figure 13 - Thumb Wheel

4.5 Propulsion System The left and right motor H-Bridges (half bridges) are connected through pins 3.4, 3.5, 3.6, and 3.7 as shown in figure 4.4.1 below. Each half bridge is constructed from 4 N-FETs and 2 P-FETs to allow each wheel to be independently driven in either forward or reverse (The Left/Right Motor H-Bridge Schematics are shown below as figure 4.4.2 and 4.4.3). These two half bridges combine to create a full bridge. However, as an unfortunate side effect of using a full bridge is that the motor assembly can be significantly damaged by running them in both the forward and reverse direction at the same time. This issue is taken care of in the software, which prevents the output of port 3.4 and 3.6 being turned on simultaneously as well as 3.5 and 3.7. The test points TP1-TP8 are offered to debug any incorrect installation which is covered in more detail under the test section of the document. The diagrams for the half bridges are displayed below.

Figure 14 - J2 Pin Diagram and Interconnect

Page 14: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

14 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 15 – Left Motor H Bridge

Figure 16 – Right Motor H Bridge

4.6 Structural System The FRAM and PWS are mounted onto an 8”x5” piece of acrylic. This acrylic was drilled to allow the PCB, motors, and caster wheel to be attached to the board. The hole pattern is shown in Figure 4.3.1.

Page 15: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

15 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 17 - Acrylic Drilling Pattern

The PCB has four holes in the corner to be aligned with the acrylic. Four hex standoffs are used to mount the PCB and FRAM. They are screwed in from underneath by a steel screw to stay on the acrylic. The PCB is held in place with nylon screws that come in from above. Nylon screws were chosen to avoid shorting the controller board.

Page 16: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

16 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 18 - Nylon Screws Connecting PCB to Standoffs

Figure 19 - Steel Screws Connecting Standoffs to Acrylic Board

Holes on the left and right sides of the acrylic are used to hold the motors down. Using zip ties, they wrap around the motors and hold them in place. The caster wheel is held in place in a similar fashion. Four holes are drilled and two zip ties run through them to keep the caster in place. Directly underneath the FRAM and PCB are also two holes in the acrylic for a battery pack to be held. Two holes in the battery pack line up with the holes in the acrylic and can be used for zip ties.

Page 17: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

17 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

4.7 Communication System As we can see from Figure 19, the Serial Communication Module can be implemented to provide remote control ability via internet. A protocol is securely set up and enables the communication with the Serial Communication Module. As shown in Figure 20, the UCA1 IOT device is used to communicate between the PC and the control module through pin J8. On the other side, UCA0 IOT device is used to communicate between the Control Module and the IOT device.

Figure 20 - Serial Port UCA1

Figure 21 - IOT (UCA0) Module

5. Power Analysis

The battery pack holds 4 AA batteries which corresponds to roughly 6V when fresh. To measure the length of use of this car, the voltage and amperage of the car at standard operating conditions needed to be measured. These conditions were defined as the backlight off, the IOT module operating, the wheels moving at the standard normal rate, and the IR detector on. To find the power usage of the system, the car was hooked up to a power supply that ran at 5.5V and the amps drawn were measured as the car ran through its program. A current draw of 0.28A was observed. It was calculated that the car would run for approximately 1.43 hours.

Page 18: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

18 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Voltage at power supply = 5.5 V

Amps measured = 0.280 A

Power = V * A = 1.54 W

Each battery must supply a fourth of 1.54 W or a calculated value of 0.385 W. By referencing the figure below, that would correspond to roughly 0.4 ampere hours which drawn at a rate of 0.280 A would last 1.43 hours if four new AA batteries were used.

Figure 22 - Capacity vs Power Drain Graph

6. Test Process

This section details the process by which the car system was tested during development and assembly. Each subsection includes the testing process for a specific subsystem such as a piece of the power system or the driving system. Testing of the circuit is completed using an ohmmeter to test various pads on the board to ensure that there is an open on the ohmmeter. This is to ensure that we do not short the board due to bad soldering or otherwise. A Voltmeter is also used to ensure that the power system is working properly and not feeding too much power to the processor.

6.1 U1 Testing To ensure that the Buck Boost Converter, U1, was properly installed, an ohmmeter was used to test the pads pictured below. To check that the control board was soldered properly, an ohmmeter was used to read the resistance from points 1 to 2, 2-3 and so on until 4-5 is tested. If all tests resulted in an open, the testing process proceeded. If not, the solder was rechecked and U1 was tested to ensure it was not shorted.

Page 19: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

19 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 23 - U1 Testing Point

6.2 Testing the Power System Before soldering new connections onto the FRAM board, we tested the power system to ensure that it only fed 3.3 volts to the processor. The battery pack was connected to the processor and the power switch was turned on. The voltage between the square pad of J2 and the center pad of J8 was tested like in the picture below. If the voltmeter read 3.3V it meant the system was properly assembled. If the voltage test was failed, the parts were checked for poor solder connections.

Figure 24 - PWS Testing

6.3 Testing the Completed Power System After installing the board-to-board connections and J2, two more voltage tests were done. The board was repowered and the voltage across J2 and ground was tested to ensure it was 3.3V.

Page 20: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

20 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Figure 25 – J2 Testing Point

A jumper was then placed across J2 and the board was retested at the 3.3V test point. If the power system passed all of these tests it was running nominaly.

Figure 26 – 3.3V Testing Point

6.4 Testing the LCD Testing of the LCD was done by adding test code to the project to display the four lines pictured below. The message read “NCSU WOLFPACK ECE306 J CARLSON”. If this message displayed correctly, the soldering of the LCD was done correctly.

Figure 27 - LCD Displaying Test Message

Page 21: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

21 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

6.5 Testing the N-FETS and P-FETS Once the N-FETs Q21 and Q41 were installed, a jumper was placed between pin 6 and pin 12 and the voltage was measured across the test point as displayed in the picture. The voltage should be roughly the battery voltage across this test point. This voltage tested the validity of Q21.

Figure 28 – Q21 Test Point

The voltage was then measured at the test point displayed in the picture below after a jumper was placed across pin 5 and 12. This measurement tested the validity of Q41.

Figure 29 – Q41 Test Point

If the tests for Q21 and Q41 passed, then the remainder of the N-FETS and P-FETS could be installed. After installing Q23, Q13, Q21, Q22, Q11, Q12, Q443, Q33, Q41, Q42, Q31, and Q32, they were tested by measuring the voltages across TP1 (Test Point 1) to TP8. The voltage across the test points and ground were measured while various functions were occurring, specifically the functions that controller motor usage. The voltages desired were met and are displayed below in the table. The test points that corresponded to the device tested are also detailed below.

Page 22: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

22 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Table 1 - Test Point Per DUT Table 2 - Nominal Voltages per Test Point

If the voltages specified were not immediately met, the PWS was turned off to avoid further damage. If any test failed, the soldering was inspected and fixed before repowering the DUT.

6.6 Testing the ADC and Detection Systems Upon installation of the thumbwheel onto the control board, the ADC was configured as a 10-bit system and values were checked by using the two extreme positions of the thumbwheel. This would prove the capability of the ADC to read from 0 to 1023. After confirming that the ADC was connected to the thumbwheel and had the ability to read the two extreme values, code was inserted to place the current value of the thumbwheel onto the LCD display. The thumbwheel was then turned very slowly using the edge of a fingernail to check that there was no abnormal readings. The next step was to test the ability of the two IR detectors to read the IR level of a surface beneath them. The IR emitters and detectors were angled at such a way so that the emitted IR light would bounce back into the detectors. A reading was taken from the detectors on two surfaces: a white piece of printer paper and a piece of electrical tape. After proving that all the components of the system worked and were angled correctly, cylindrical IR shielding was applied to the detectors to improve their resistance to ambient light.

Page 23: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

23 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

6.7 Testing the Serial Communication System

Upon installation of the thumbwheel onto the control board, the ADC was configured as a 10-bit system and values were checke To test Serial A1 the pins on J8 were connected shown in the figure below, which connects UCA1TXD and UCA1RXD. By doing so it sets Serial A1 in loop back to communicate with itself.

To test Serial A0 the pins on J9 were connected shown in the figure below, which connects UCA0TXD and UCA0RXD. By doing so it sets Serial A1 in loop back to communicate with itself.

Figure 30 - Total Serial Communication System

Figure 31 - Jumper Test Positioning 1

Page 24: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

24 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

To test the PC communication the pins in the picture below were connected.

Figure 32 - Jumper Test Positioning 2

Figure 33 - Jumper Test Positioning 3

Page 25: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

25 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

To test normal mode J9 was connected as in the picture to the right. Connecting J9 like this connected UCA0TXD and UCA0RXD to the PC using the 9600 baud back door communications channel.

To test communication between Serial A0 and A1, J8 and J9 were connected like so in the picture below. To test this configuration Serial A0 and A1 must be communicating at the same baud rate. The baud rate used to test was 9600.

Figure 34 - Jumper Test Positioning 4

Figure 35 - Full Pin Connection Setup

Page 26: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

26 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

7. Software Description The code structure for the Model X306 is necessary to control its hardware. The software seamlessly and constantly checks its lines of code for changes in order to navigate the course. The car currently has the ability to rotate its wheels, and detect its environment due to the programming.

To navigate the black line, the car is configured to detect 4 states: Both detectors on the line, the right detector off the line, the left detector off the line and both detectors off the line. To goal is to have both detectors on the line, therefore when this state is achieved, the car moves forward. If the car goes off to either of the sides of the black line, the appropriate power for that side wheel will kick in to keep the car on course. Lastly if both detectors are off the line, an emergency backing function is trigger for the car to find the line again.

The code description is broken into subsections below to give a better idea of what each section of code accomplishes.

7.1 Description of Main

Main is the OS (Operating System) of the X306. It controls all the components, variables and logic of the X306. Main implements a Foreground/Background OS where functions are called based on the results of interrupts. Main is also responsible for the initialization of the X306 and calls the necessary functions. Main has an additional subdivision where one portion of main runs once and it occurs before the while always loop. In this portion of main, one time initializations as well as much of the system setup occurs. In the second part of main, the while always loop, the code enters a repetitive state where it follows a set structure continuously, unless an interrupt occurs.

7.2 Description of Ports

The ports file contains the functions necessary for the initial start-up configurations of the ports. There is a function for each port, 1-4 and J, that contains the configurations for the pins associated with the port. These port initialization functions are all called by a master function called initPorts which just calls each individual port config. Each pin on a port is reset at the beginning of the port configuration and is selected to ensure there is minimal unexpected actions occurring.

7.3 Description of Timers Timers contains the functions necessary for initial start-up configurations of the timers. There is a function for each timer configuration. Multiple timers are configured and used under the timer file. Each timer has a separate purpose. Timers A0 and A1 are used for general timing with A0 being the slower timer used to control the speed of the display update process. A1 is mostly responsible for being a fast timer which can count up for the 10 millisecond wait function. This function is invaluable as it lets the car wait for a period while actions are occurring or nothing needs to be done.

7.4 Description of ADC

The ADC file contains the initial start-up configuration of the ADC. A lower level of resolution was chosen to save time and processing power. The ADC generates a value and then must wait for several clock cycles (dependent on the resolution of the system) for the next value to be measured and passed onto the system. The ADC must handle three different values – the value of the left detector, the value of the right detector, and the value of the thumbwheel.

Page 27: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

27 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

7.5 Description of Interrupts The interrupt system is divided into three major parts: ADC, port, and timer based interrupts. The ADC interrupts handle the readings of each channel, A0, A1 and A3. Each of the reading values is set to a variable that can then be used outside of the interrupt. Each channel corresponds to a different real world analog signal that is being converted into a digital value. The ADC interrupt system controls the scheduling of the next value conversion by cycling between each one. The ports interrupt handles what is supposed to occur when a switch is pressed. The interrupt also handles how often a switch can be pressed. A debounce mechanism is in the ADC interrupt code which functions by reconfiguring the button once pressed and using a timer to wait out any possible debounces before reenabling the switch’s interrupt capability. Timer interrupts are used for periodic and sequencing tasks. By signaling volatile variables in the timer interrupts, Main can then call appropriate functions in a slightly delayed timeframe. Timer A0 is used to signal display updates and Timer A1 is used to handle switch pressing as well as a general 10 millisecond period. These timer interrupts can also be used to generate a PWM system which has been utilized by the X306 system.

7.6 Description of Serial Communication Serial communication contains the initialization, interrupts and transmission functions. The interrupts handle the receiving of data on either the A0 or the A1 side. The transmission function handles converting, incrementing and then transmitting received data. Our serial communication sends a split up integer which is originally 16 bytes but is eventually broken into two 8 byte signals before sending them through the transmission buffer. Once received the integers are reconstructed using pointers and casting.

7.7 Description of Detect Black Line Detect Black Line is a function that allows the car to find and navigate the black line. The car moves

forwards until it finds a black surface (the black line). When it detects the black line it then uses it’s detectors to differentiate white from black and travel across the line.

7.8 Description of Reset WiFi The Reset Wifi function has two sections: a software reset and a hardware reset. The software reset

involves sending a command to the IOT module which will cause it to perform the software reset. After waiting for a short period of time to allow the IOT module to boot back up, the IOT module is hardware reset by toggling the reset line from high to low.

7.9 Description of Check Dissociation The Check Dissociation function constantly runs throughout the program at a slow interval and scans the receive buffer from the IOT module. If the buffer ever contains the status code that correlates to the dissociation of the IOT device, it resets the IOT device and checks the IP of the module to ensure it hasn’t changed. The status code is then removed from the buffer so it cannot be accidentally picked up again.

7.10 Description of Status Report The function Status Report will get the SSID and IP of the IOT device and then display them on the LCD

display. This is performed by sending a status check command to the IOT device and reading the resulting data stream. The IP address is then parsed from this buffer.

7.11 Description of Command Receiving

The Wi-Fi Command Detect Function scans the inputted commands from via from the browser to IOT receiver, for the right validation code. After validation, it checks the following character to perform the desire function/command. Ex. ‘F’ to call the function to move forward, ‘B’ for reverser etc.

Page 28: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

28 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8. Flowcharts The following section will detail the structure of the major portions of the code to give the reader and audience an understanding of how the software is organized. The software is broken into several major parts: main, ports, timers, ADC, and interrupts. Each of these sections has been identified as a vital component and collectively represents most of the software.

Page 29: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

29 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.1 Main Flowchart

Update Display If 200 ms passed

Initialize Ports, Timers,

Clocks, LED, LCD

Display Information on

screen

While(ALWAYS)

Read ADC Value

Switch Pressed?

Execute Calibration and state functions

Null

No

Yes, Switch 1 Pressed

Yes, Switch 2 Pressed

Page 30: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

30 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.2 Port Initialization Flowchart

Initialize Port 1 for:

Left and Right Detect, LCD Backlite, and Thumb wheel

Initialize Port 2 for: serial

communication.

Initialize Port 3 for: IR LEDs and motors

Initialize Port 4 for: switch 1

and 2.

Initialize Port J

Initialize call from main.c

Return to main.c

Page 31: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

31 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.3 Timer Flowchart

Source: TASSEL_SMCLK

Resets TA0R, clock divider, count direction

Choose continuous up mode

Divide clock by 4

Disable overflow interrupt and clear it

Initialization call from main

Divide clock by an additional 8

Set the timer interval

CCR0 enable interrupt

Page 32: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

32 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.4 ADC Flowchart

Pause the ADC read capability

Read and store result

from left detector

Re-enable ADC read capability

Return to main. Wait for ADC to finish

converting next value

Re-enable ADC read capability

Initialization call from main

Read and store result from thumb

wheel

Pause the ADC read capability

Return to main. Wait for ADC to finish

converting next value

Return to main. Wait for ADC to finish

converting next value

Pause the ADC read capability

Read and store result from right detector

Re-enable ADC read capability

Page 33: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

33 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.5 Interrupt Flowchart

Disable Switch

Off Black Line

On black Line

Stay on Line Logic

Sequence = Circle

Sequence = Turn

Sequence = Adjust

Sequence = Post Turn

Sequence = Pause

Sequence = Start

Press

Enable

Enable

Timer B0

Start

Pause

Adjust

Turn

Post Turn

Circle

PWM

ADC

Update

Timer A0

Interrupts activated

from main: Switches

Sequence Value

Page 34: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

34 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.6 Serial Flowchart

No

Yes

Check for a received

number in main number

received?

Receive low and high order byte of integer

Increment received number

Display new number on LCD for one second

Send low and high order byte

of integer

Page 35: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

35 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.7 Detect Black Line

Yes Yes

No

Yes

Call from IOT command

On Black Line? Drive Forward

Move Car Left

Left detector on

Black?

Left detector on

White?

Move Car Right

No

No

Page 36: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

36 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.8 Reset WiFi

Start

Load “AT+CFUN = 1” into buffer

Send to IOT

Wait for One Second

TOGGLE RESET LINE

Wait 50 msec

END

Page 37: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

37 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.9 Check Dissociation

Start

End

End Clear buffer at “:8”

Reset Wi-Fi

Does Receive Buffer

contain a

Is it in the last

position?

Is the first position of the buffer

‘8”?

Is the next buffer

character ‘8’

No

Yes

Yes

Yes

Yes

No

No

No

Page 38: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

38 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.10 Status Report

Start Load “AT+S.STS” into buffer

Send to IOT

Load “AT+S.SSIDTXT” into buffer

Send to IOT

Set display line 4 as second half of ip address array

Parse information: SSID array = Info b/t (ip_ipaddr=) and (\n)

Load “AT+S.STS = ip_addr” into buffer

Parse information: Between first (‘) and second (‘) into

SSID array

Set display line 1 as SSID array

Send to IOT

Set display line 3 as first half of ip address array

END

Page 39: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

39 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

8.11 Command Receiving

Yes

No

Yes

Call from Main First Five

chars valid?

‘R’ Move Car Backward

‘F’ Move Car Forward

‘L’ Move Car Left

‘S’ Stop Car ‘I’ Set Car to

start Black Line Navigation

Sixth character

valid?

‘B’ Move Car Backward

No

Check IOT received

characters

Page 40: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

40 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

9. Software Listing

9.1 Main //------------------------------------------------------------------------------ // // Description: This file contains the Main Routine - "While" Operating System // The purpose of the program is to display a message which will change to a // second message upon pressing switch 2. The original message can be changed // to by pressing switch 1 again. // // // Zachary Fearnside // September 2016 // Built with IAR Embedded Workbench Version: V7.4.2.4369 (6.50.1) //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" // Global Variables volatile unsigned char control_state[CNTL_STATE_INDEX]; char led_smclk; volatile char one_time; volatile unsigned int five_msec_count; volatile char debounceCounter = DEBOUNCE; extern char display_line_1[MAX_DISPLAY_LENGTH]; extern char display_line_2[MAX_DISPLAY_LENGTH]; extern char display_line_3[MAX_DISPLAY_LENGTH]; extern char display_line_4[MAX_DISPLAY_LENGTH]; extern char *display_1; extern char *display_2; extern char *display_3; extern char *display_4; char LCDCounter; char OffCounter; char posL1; char posL2; char posL3; char posL4; volatile char toggle=RESET; volatile char LCD_Timer=LCD_START; char size_count; volatile char driveTimer = RESET; char big; char ADC_Select; volatile char movement_timer = STARTSTILL; char movement_state = STARTSTILL; int ADC_Thumb; int ADC_Left; int ADC_Right;

Page 41: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

41 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

char adc_char[5]; char previousState; char currentState; int BlackLine; int WhiteLine; char DisplayToggle = OFF; char LastOff; volatile char mSecCount; void main(void){ //------------------------------------------------------------------------------ // Main Program // This is the main routine for the program. Execution of code starts here. // The operating system is Back Ground Fore Ground. // // The list of globals declared in this function are listed below: // // control_state, Time_Sequence, led_smclk, one_time, Time_Sequence, // display_line_1, display_line_2, display_line_3, display_line_4, display_1, // display_2, display_3, display_4, posL1, posL2, posL3, posL4, , big, // wheel_timer. // // Locals: none // Returns: none //------------------------------------------------------------------------------ Init_Ports(); // Initialize Ports Init_Clocks(); // Initialize Clock System Init_Conditions(); Init_Timers(); // Initialize Timers Init_LEDs(); // Initialize LEDs Init_LCD(); // Initialize LCD Init_ADC(); // 1234567890 display_1 = "EMIT ON"; posL1 = LINE_1_START; display_2 = "WOLFPACK"; posL2 = LINE_2_START; display_3 = "ECE-306"; posL3 = LINE_3_START; display_4 = "FEARNSIDE"; posL4 = LINE_4_START; big = DISPLAY_SIZE_START; Display_Process(); //------------------------------------------------------------------------------ // Begining of the "While" Operating System //------------------------------------------------------------------------------ while(ALWAYS) { // Can the Operating system run Toggle_State(); if (toggle==STARTDRIVE){ UpdateState(); } if (LCDCounter == LCD_ON ){ Display_Process(); LCDCounter = RESET_STATE; }

Page 42: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

42 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

} } //------------------------------------------------------------------------------

9.2 Ports //------------------------------------------------------------------------------ // File name : ports.c // Description: This file contains the port initialization // // // Author: Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "macros.h" #include "msp430.h" #include "functions.h" void Init_Ports(void){ //============================================================================ // Function name: Init_Ports // // Description: This function calls the rest of the initialization functions. // // Passed : no variables passed // Locals: no variables declared // Returned: no values returned // Globals: N/A // // Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //============================================================================ Init_Port1(); Init_Port2(); Init_Port3(); Init_Port4(); Init_PortJ(); } void Init_Port1(void){ //============================================================================ // Function name: Init_Port1 // // Description: This function will initialize all pins in port 1. // // Passed : no variables passed // Locals: no variables declared // Returned: no values returned // Globals: N/A // RESET_I_O (0x00) // V_DETECT_R (0x01) // Voltage from Right Detector

Page 43: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

43 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

// V_DETECT_L (0x02) // Voltage from Right Detector // LCD_BACKLITE (0x04) // Control Signal for LCD_BACKLITE // V_THUMB (0x08) // Voltage from Thumb Wheel // SPI_CS_LCD (0x10) // LCD Chip Select // RESET_LCD (0x20) // LCD Reset // SIMO_B (0x40) // SPI mode - slave in/master out of USCI_B0 // SOMI_B (0x80) // SPI mode - slave out/master in of USCI_B0 // Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //============================================================================ P1SEL0 = RESET_I_O; // P1 set as I/0 P1SEL1 = RESET_I_O; // P1 set as I/0 P1DIR = RESET_I_O; // Set P1 direction to input P1OUT = RESET_I_O; P1SEL0 |= V_DETECT_R; // V_DETECT_R selected P1SEL1 |= V_DETECT_R; // V_DETECT_R selected P1SEL0 |= V_DETECT_L; // V_DETECT_L selected P1SEL1 |= V_DETECT_L; // V_DETECT_L selected P1SEL0 &= ~LCD_BACKLITE; // LCD_BACKLITE GPI/O selected P1SEL1 &= ~LCD_BACKLITE; // LCD_BACKLITE GPI/O selected P1OUT |= LCD_BACKLITE; // LCD_BACKLITEPort Pin set low P1DIR |= LCD_BACKLITE; // Set LCD_BACKLITE direction to output P1SEL0 |= V_THUMB; // V_THUMB selected P1SEL1 |= V_THUMB; // V_THUMB selected P1SEL0 &= ~SPI_CS_LCD; // SPI_CS_LCD GPI/O selected P1SEL1 &= ~SPI_CS_LCD; // SPI_CS_LCD GPI/O selected P1OUT |= SPI_CS_LCD; // SPI_CS_LCD Port Pin set high P1DIR |= SPI_CS_LCD; // Set SPI_CS_LCD output direction P1SEL0 &= ~RESET_LCD; // RESET_LCD GPI/O selected P1SEL1 &= ~ RESET_LCD; // RESET_LCD GPI/O selected P1OUT &= ~ RESET_LCD; // RESET_LCD Port Pin set low P1DIR |= RESET_LCD; // Set RESET_LCD output direction P1SEL0 &= ~SIMO_B; // SIMO_B selected P1SEL1 |= SIMO_B; // SIMO_B selected P1DIR |= SIMO_B; // SIMO_B set to Output P1SEL0 &= ~SOMI_B; // SOMI_B is used on the LCD P1SEL1 |= SOMI_B; // SOMI_B is used on the LCD P1OUT |= SOMI_B; // SOMI_B Port Pin set for Pull-up P1DIR &= ~SOMI_B; // SOMI_B set to Input P1REN |= SOMI_B; // Enable pullup resistor } void Init_Port2(void){ //============================================================================ // Function name: Init_Port2 //

Page 44: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

44 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

// Description: This function will initialize all pins in port 2. // // Passed : no variables passed // Locals: no variables declared // Returned: no values returned // Globals: N/A // RESET_I_O (0x00) // // USB_TXD (0x01) // // USB_RXD (0x02) // // SPI_SCK (0x04) // // UNKNOWNP23 (0x08) // // UNKNOWNP24 (0x10) // // CPU_TXD (0x20) // // CPU_RXD (0x40) // // UNKNOWN27 (0x80) // // Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //============================================================================ P2SEL0 = RESET_I_O; // P2 set as I/0 P2SEL1 = RESET_I_O; // P2 set as I/0 P2DIR = RESET_I_O; // Set P2 direction to input P2OUT = RESET_I_O; P2SEL1 |= USB_TXD; // P2SEL0 &= ~USB_TXD; // P2OUT |= USB_TXD; // P2DIR &= ~USB_TXD; // P2SEL1 |= USB_RXD; // P2SEL0 &= ~USB_RXD; // P2OUT &= ~USB_RXD; // P2DIR &= ~USB_RXD; // P2REN &= ~USB_RXD; // Disable pullup resistor P2SEL1 |= SPI_SCK; // P2SEL0 &= ~SPI_SCK; // P2OUT |= SPI_SCK; // P2DIR &= ~SPI_SCK; // //P2SEL0 &= ~UNKNOWNP23; // //P2SEL1 &= ~UNKNOWNP23; // //P2OUT &= ~UNKNOWNP23; // //P2DIR &= ~UNKNOWNP23; // //P2REN &= ~UNKNOWNP23; // Disable pullup resistor //P2SEL0 &= ~UNKNOWNP24; //P2SEL1 &= ~UNKNOWNP24; //P2OUT &= ~UNKNOWNP24; //P2DIR &= ~UNKNOWNP24; //P2REN &= ~UNKNOWNP24; P2SEL1 |= CPU_TXD; // P2SEL0 &= ~CPU_TXD; // P2OUT |= CPU_TXD; //

Page 45: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

45 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

P2DIR &= ~CPU_TXD; // P2SEL1 |= CPU_RXD; // P2SEL0 &= ~CPU_RXD; // P2OUT &= ~CPU_RXD; // P2DIR &= ~CPU_RXD; // P2REN |= CPU_RXD; // //P2SEL0 &= ~UNKNOWN27; //P2SEL1 &= ~UNKNOWN27; //P2OUT &= ~UNKNOWN27; //P2DIR &= ~UNKNOWN27; //P2REN &= ~UNKNOWN27; } void Init_Port3(void){ //============================================================================ // Function name: Init_Port3 // // Description: This function will initialize all pins in port 3. // // Passed : no variables passed // Locals: no variables declared // Returned: no values returned // Globals: N/A // RESET_I_O (0x00) // // XX (0x01) // // YY (0x02) // // ZZ (0x04) // // IR_LED (0x08) // // R_FORWARD (0x10) // // L_FORWARD (0x20) // // R_REVERSE (0x40) // // L_REVERSE (0x80) // // Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //============================================================================ P3SEL0 = RESET_I_O; // P3 set as I/0 P3SEL1 = RESET_I_O; // P3 set as I/0 P3DIR = RESET_I_O; P3OUT = RESET_I_O; P3SEL0 &= ~XX; P3SEL1 &= ~XX; P3OUT &= ~XX; P3DIR &= ~XX; P3REN &= ~XX; P3SEL0 &= ~YY; P3SEL1 &= ~YY; P3OUT &= ~YY; P3DIR &= ~YY; P3REN &= ~YY;

Page 46: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

46 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

P3SEL0 &= ~ZZ; P3SEL1 &= ~ZZ; P3OUT &= ~ZZ; P3DIR &= ~ZZ; P3REN &= ~ZZ; P3SEL0 &= ~IR_LED; P3SEL1 &= ~IR_LED; P3OUT &= ~IR_LED; P3DIR |= IR_LED; //P3SEL0 &= ~R_FORWARD; P3SEL0 |= R_FORWARD; P3SEL1 &= ~R_FORWARD; P3DIR |= R_FORWARD; //P3OUT &= ~R_FORWARD; //P3SEL0 &= ~L_FORWARD; P3SEL0 |= L_FORWARD; P3SEL1 &= ~L_FORWARD; P3DIR |= L_FORWARD; //P3OUT &= ~L_FORWARD; //P3SEL0 &= ~R_REVERSE; P3SEL0 |= R_REVERSE; P3SEL1 &= ~R_REVERSE; P3DIR |= R_REVERSE; //P3OUT &= ~R_REVERSE; //P3SEL0 &= ~L_REVERSE; P3SEL0 |= L_REVERSE; P3SEL1 &= ~L_REVERSE; P3DIR |= L_REVERSE; //P3OUT &= ~L_REVERSE; } void Init_Port4(void){ //============================================================================ // Function name: Init_Port4 // // Configure PORT 4 // Port 4 has only two pins // Port 4 Pins // SW1 (0x01) // Switch 1 // SW2 (0x02) // Switch 2 // Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //============================================================================ P4SEL0 = RESET_I_O; // P4 set as I/0 P4SEL1 = RESET_I_O; // P4 set as I/0 P4DIR = RESET_I_O; // Set P4 direction to input //P4OUT = RESET_I_O; // SW1 P4SEL0 &= ~SW1; // SW1 set as I/0

Page 47: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

47 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

P4SEL1 &= ~SW1; // SW1 set as I/0 P4DIR &= ~SW1; // Direction = input P4OUT |= SW1; // Configure pullup resistor P4REN |= SW1; // Enable pullup resistor // Interrupts P4IES |= SW1; // SW1 Hi/Lo edge interrupt P4IFG &= ~SW1; // IFG SW1 cleared P4IE |= SW1; // SW1 interrupt Enabled // SW2 P4SEL0 &= ~SW2; // SW2 set as I/0 P4SEL1 &= ~SW2; // SW2 set as I/0 P4DIR &= ~SW2; // Direction = input P4OUT |= SW2; // Configure pullup resistor P4REN |= SW2; // Enable pullup resistor // Interrupts P4IES |= SW2; // SW2 Hi/Lo edge interrupt P4IFG &= ~SW2; // IFG SW2 cleared P4IE |= SW2; // SW2 interrupt enabled //---------------------------------------------------------------------------- } void Init_PortJ(void){ //============================================================================ // Function name: Init_PortJ // // Description: This function will initialize all pins in port J. // // Port J Pins // LED1 (0x01) // LED 5 // LED2 (0x02) // LED 6 // LED3 (0x04) // LED 7 // LED4 (0x08) // LED 8 // XINR (0x10) // XINR // XOUTR (0x20) // XOUTR // Joshua Ndon // Date: Sept 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //============================================================================ PJSEL0 = RESET_I_O; // PJ set as I/0 PJSEL1 = RESET_I_O; // PJ set as I/0 PJDIR = RESET_I_O; // Set PJ direction to output PJOUT = RESET_I_O; //PJSEL0 &= ~LED1; //PJSEL1 &= ~LED1; //PJOUT &= ~LED1; //PJDIR |= LED1; // Set PJ Pin 1 direction to output //PJSEL0 &= ~LED2; //PJSEL1 &= ~LED2; //PJOUT &= ~LED2; //PJDIR |= LED2; // Set PJ Pin 2 direction to output //PJSEL0 &= ~LED3; //PJSEL1 &= ~LED3; //PJOUT &= ~LED3; //PJDIR |= LED3; // Set PJ Pin 3 direction to output //PJSEL0 &= ~LED4;

Page 48: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

48 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

//PJSEL1 &= ~LED4; //PJDIR |= LED4; // Set P3 Pin 4 direction to output //PJOUT &= ~LED4; // XT1 Setup // PJSEL0 |= XINR; // PJSEL0 |= XOUTR; }

9.3 Timers //------------------------------------------------------------------------------ // // Description: This file contains the timer functions // // // William Shaw // Oct 2016 // Built with IAR Embedded Workbench Version: V7.4.2.4369 (6.50.1) //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" extern volatile unsigned int Time_Sequence; extern volatile char one_time; extern volatile unsigned int five_msec_count; volatile extern unsigned int right_forward_rate; volatile extern unsigned int left_forward_rate; volatile extern unsigned int rig ht_reverse_rate; volatile extern unsigned int left_reverse_rate; void five_msec_sleep(unsigned int fivemsec){ //------------------------------------------------------------------------------ //Each count passed is at least x times 5 milliseconds five_msec_count = ZERO; while(fivemsec > (five_msec_count+1)); //------------------------------------------------------------------------------ } void Timer_code(void){ //------------------------------------------------------------------------------ // Timer A0 interrupt code //------------------------------------------------------------------------------ Time_Sequence++; one_time = ONE; if (five_msec_count < 1000){ five_msec_count++; } //------------------------------------------------------------------------------ } //------------------------------------------------------------------------------ // Timer A0 initialization sets up both A0_0 and A0_1-A0_2 void Init_Timer_A0(void) { TA0CTL = TASSEL__SMCLK; // SMCLK source TA0CTL |= TACLR; // Resets TA0R, clock divider, count direction

Page 49: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

49 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

TA0CTL |= MC__CONTINOUS; // Continuous up TA0CTL |= ID__4; // Divide clock by 4 TA0CTL &= ~TAIE; // Disable Overflow Interrupt TA0CTL &= ~TAIFG; // Clear Overflow Interrupt flag TA0EX0 = TAIDEX_7; // Divide clock by an additional 8 TA0CCR0 = TA0CCR0_INTERVAL; // CCR0 TA0CCTL0 |= CCIE; // CCR0 enable interrupt TA0CCR1 = TA0CCR1_INTERVAL; // CCR1 TA0CCTL1 |= CCIE; // CCR1 enable interrupt // TA0CCR2 = TA0CCR2_INTERVAL; // CCR2 // TA0CCTL2 |= CCIE; // CCR2 enable interrupt } //------------------------------------------------------------------------------ // Timer B0 initialization sets up both B0_0 and B0_1-B0_2 void Init_Timer_B0(void) { TB0CTL = TBSSEL__SMCLK; // SMCLK source TB0CTL |= TBCLR; // Resets TA0R, clock divider, count direction TB0CTL |= MC__CONTINOUS; // Continuous up TB0CTL |= ID__4; // Divide clock by 4 TB0CTL &= ~TBIE; // Disable Overflow Interrupt TB0CTL &= ~TBIFG; // Clear Overflow Interrupt flag TB0EX0 = TBIDEX_7; // Divide clock by an additional 8 TB0CCR0 = TB0CCR0_INTERVAL; // CCR0 //TB0CCTL0 |= CCIE; // CCR0 enable interrupt //TB0CCR1 = TB0CCR1_INTERVAL; // CCR1 //TB0CCTL1 |= CCIE; // CCR1 enable interrupt // TB0CCR2 = TB0CCR2_INTERVAL; // CCR2 // TB0CCTL2 |= CCIE; // CCR2 enable interrupt } //------------------------------------------------------------------------------ // Timer B1 initialization void Init_Timer_B1(void) { //------------------------------------------------------------------------------ // SMCLK source, up count mode, PWM Right Side //------------------------------------------------------------------------------ TB1CTL = TBSSEL__SMCLK; // SMCLK TB1CTL |= MC_1; // Up Mode TB1CTL |= TBCLR; // Clear TAR right_forward_rate= OFF; // Set Right Forward Off left_forward_rate= OFF; // Set Left Forward Off TB1CCR0 = WHEEL_PERIOD; // PWM Period TB1CCTL1 = OUTMOD_7; // CCR1 reset/set TB1CCR1 = left_forward_rate; // P3.4 Right Forward PWM duty cycle //TB1CCTL1 |= CCIE; // CCR1 enable interrupt TB1CCTL2 = OUTMOD_7; // CCR2 reset/set TB1CCR2 = right_forward_rate; // P3.5 Left Forward PWM duty cycle //TB1CCTL2 |= CCIE; // CCR2 enable interrupt

Page 50: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

50 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

//------------------------------------------------------------------------------ } //------------------------------------------------------------------------------ // Timer B2 initialization void Init_Timer_B2(void) { //------------------------------------------------------------------------------ // SMCLK source, up count mode, PWM Left Side //------------------------------------------------------------------------------ TB2CTL = TBSSEL__SMCLK; // SMCLK TB2CTL |= MC_1; // Up Mode TB2CTL |= TBCLR; // Clear TAR right_reverse_rate= OFF; // Set Right Forward Off left_reverse_rate= OFF; // Set Left Forward Off TB2CCR0 = WHEEL_PERIOD; // PWM Period TB2CCTL1 = OUTMOD_7; // CCR1 reset/set TB2CCR1 = left_reverse_rate; // P3.4 Right Forward PWM duty cycle //TB2CCTL1 |= CCIE; // CCR1 enable interrupt TB2CCTL2 = OUTMOD_7; // CCR2 reset/set TB2CCR2 = right_reverse_rate; // P3.5 Left Forward PWM duty cycle //TB2CCTL2 |= CCIE; // CCR1 enable interrupt //------------------------------------------------------------------------------ }

9.4 ADC //------------------------------------------------------------------------------ // // Description: This file contains ADC interrupts // // // Zijun Lu // Fall 2016 // Built with IAR Embedded Workbench Version: V7.3.1.3987 (6.50.1) //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" void Init_ADC(void){ ADC10CTL0 = RESET_STATE; // Clear ADC10CTL0 ADC10CTL0 |= ADC10SHT_2; // 16 ADC clocks ADC10CTL0 &= ~ADC10MSC; // Single Sequence ADC10CTL0 |= ADC10ON; // ADC ON - Core Enabled ADC10CTL1 = RESET_STATE; // Clear ADC10CTL1 ADC10CTL1 |= ADC10SHS_0; // ADC10SC bit

Page 51: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

51 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

ADC10CTL1 |= ADC10SHP; // SAMPCON signal sourced from sampling timer ADC10CTL1 &= ~ADC10ISSH; // The sample-input signal is not inverted. ADC10CTL1 |= ADC10DIV_0; // ADC10_B clock divider Divide by 1. ADC10CTL1 |= ADC10SSEL_0; // MODCLK ADC10CTL1 |= ADC10CONSEQ_0; // Single-channel, single-conversion ADC10CTL2 = RESET_STATE; // Clear ADC10CTL2 ADC10CTL2 |= ADC10DIV_0; // Pre-divide by 1 ADC10CTL2 |= ADC10RES; // 10-bit resolution ADC10CTL2 &= ~ADC10DF; // Binary unsigned ADC10CTL2 &= ~ADC10SR; // supports up to approximately 200 ksps ADC10MCTL0 = RESET_STATE; // Clear ADC10MCTL0 ADC10MCTL0 |= ADC10SREF_0; // V(R+) = AVCC and V(R-) = AVSS ADC10MCTL0 |= ADC10INCH_3; // Channel A3 Thumb Wheel ADC10IE |= ADC10IE0; // Enable ADC conversion complete interrupt } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // ADC10 interrupt service routine // ADC_Right_Detector; // A00 ADC10INCH_0 - P1.0 // ADC_Left_Detector; // A01 ADC10INCH_1 - P1.1 // ADC_Thumb; // A03 ADC10INCH_3 - P1.3 // ADC_Temp; // A10 ADC10INCH_10 Temperature REF module // ADC_Bat; // A11 ADC10INCH_11 - Internal volatile unsigned int Current_channel; volatile unsigned int ADC_Right; volatile unsigned int ADC_Left; volatile unsigned int ADC_Thumb; #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void){ switch(__even_in_range(ADC10IV,12)) { case SET0: break; // No interrupt case SET2: break; // conversion result overflow case SET4: break; // conversion time overflow case SET6: break; // ADC10HI case SET8: break; // ADC10LO case SET10: break; // ADC10IN case SET12: // Need this to change the ADC10INCH_x value. ADC10CTL0 &= ~ADC10ENC; // Turn off the ENC bit of the ADC10CTL0 switch (Current_channel++){ case SET0: ADC10MCTL0 = ADC10INCH_0; // Next channel A1 ADC_Right = ADC10MEM0; // Current Channel result for A0 HEXtoBCD_right(ADC_Right); break; case SET1: ADC10MCTL0 = ADC10INCH_3; // Next channel A3 ADC_Left = ADC10MEM0; // Current Channel result for A1 HEXtoBCD_left(ADC_Left);

Page 52: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

52 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

break; case SET2: ADC10MCTL0 = ADC10INCH_1; // Next channel A0 ADC_Thumb = ADC10MEM0; // Current Channel result for A3 HEXtoBCD_thumb(ADC_Thumb); Current_channel= RESET; //Channel count value needs to be set back to 0; break; default: break; } ADC10CTL0 |= ADC10ENC; // Turn on the ENC bit of the ADC10CTL0 ADC10CTL0 |= ADC10SC; // Start next sample. break; } } //------------------------------------------------------------------------------

9.5 Interrupts (ADC, Timer, and Port) //------------------------------------------------------------------------------ // // Description: This file contains the Port Interrupts // This function contains interrupt and sleep functions for passing time. // // Zachary Fearnside // September 2016 // Built with IAR Embedded Workbench Version: V7.4.2.4369 (6.50.1) //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" extern int ADC_Thumb; extern char ADC_Select; extern int ADC_Right; extern int ADC_Left; // ADC10 interrupt service routine // ADC_Right_Detector; // A00 ADC10INCH_0 - P1.0 // ADC_Left_Detector; // A01 ADC10INCH_1 - P1.1 // ADC_Thumb; // A03 ADC10INCH_3 - P1.3 // ADC_Temp; // A10 ADC10INCH_10 – Temperature REF module // ADC_Bat; // A11 ADC10INCH_11 - Internal #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void){ switch(__even_in_range(ADC10IV,12)) { case NO_INTERRUPT: break; // No interrupt case CONVERSION_RESULT_OVERFLOW: break; // conversion result overflow case CONVERSION_TIME_OVERFLOW: break; // conversion time overflow case ADC10HI: break; // ADC10HI case ADC10LO: break; // ADC10LO case ADC10IN: break; // ADC10IN case ADCREAD: // Need this to change the ADC10INCH_x value.

Page 53: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

53 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

ADC10CTL0 &= ~ADC10ENC; // Turn off the ENC bit of the ADC10CTL0 switch (ADC_Select++){ case ADC_INTERRUPT_LEFT: ADC10MCTL0 = ADC10INCH_1; // Next channel A1 ADC_Left = ADC10MEM0; // Current Channel result for A0 break; case ADC_INTERRUPT_RIGHT: ADC10MCTL0 = ADC10INCH_3; // Next channel A3 ADC_Right = ADC10MEM0; // Current Channel result for A1 break; case ADC_INTERRUPT_THUMB: ADC10MCTL0 = ADC10INCH_0; // Next channel A0 ADC_Thumb = ADC10MEM0; // Current Channel result for A3 ADC_Select = ADC_INTERRUPT_LEFT; break; default: break; } ADC10CTL0 |= ADC10ENC + ADC10SC; break; default: break; } } //------------------------------------------------------------------------------ // // Description: This file contains the Port Interrupts // This function contains interrupt and sleep functions for passing time. // // Zachary Fearnside // September 2016 // Built with IAR Embedded Workbench Version: V7.4.2.4369 (6.50.1) //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" volatile extern char debounceCounter; volatile extern char *display_4; volatile extern char toggle; #pragma vector=PORT4_VECTOR __interrupt void switch_interrupt(void){ //---------------------------------------------------------------------------- // This switch interrupt is called when either switch is pressed. Their functions // are near identical. The switch turns itself off, sets a variable to toggle // the interrupt capability of A0_0. The Switch also turns on a debounce control // timer. // // globals: debounceCounter // locals: none // returns: none //---------------------------------------------------------------------------- TA0CCTL1 |= CCIE;

Page 54: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

54 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

P4IE &= ~SW12; if ( debounceCounter == DEBOUNCE){ toggle++; } } //------------------------------------------------------------------------------ // // Description: This file contains the Timer Interrupts // This function contains interrupt and sleep functions for passing time. // // Zachary Fearnside // September 2016 // Built with IAR Embedded Workbench Version: V7.4.2.4369 (6.50.1) //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" extern volatile char LCD_Timer; extern volatile char driveTimer; extern volatile char debounceCounter; extern volatile char movement_timer; extern volatile char mSecCount; extern char LCDCounter; #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer0_A0_ISR(void){ //------------------------------------------------------------------------------ // This timer interrupt blinks the LCD 1 time every second. On for 500 msec / // Off for 500 msec. // globals: LCD_Timer // locals: none // returns: none //------------------------------------------------------------------------------ TA0CCR0 += TA0CCR0_INTERVAL; // Add Offset to TACCR0 LCDCounter++; } //---------------------------------------------------------------------------- // TimerA0 1-2, Overflow Interrupt Vector (TAIV) handler #pragma vector=TIMER0_A1_VECTOR __interrupt void TIMER0_A1_ISR(void){ //------------------------------------------------------------------------------ // This timer interrupt counts 1 msec at a time. After a certain amount of time // the capture register A0_1 resolves the debounce problems associated with the // switch. // globals: debounceCounter // locals: none // returns: none //------------------------------------------------------------------------------ switch(__even_in_range(TA0IV,14)){

Page 55: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

55 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

case NOCCR: break; // No interrupt case CCR1: // CCR1 not used TA0CCR1 += TA0CCR1_INTERVAL; // Add Offset to TACCR1 debounceCounter++; if (debounceCounter == DEBOUNCE_THRESHOLD){ P4IES &= ~SW12; // SW1 and SW2 to Lo/Hi edge interrupt P4IFG &= ~SW12; // Clear interrupts for SW1 and SW2 P4IE |= SW12; TA0CCTL1 &= ~CCIE; } if (debounceCounter == DEBOUNCE_THRESHOLD_2){ P4IES |= SW12; P4IFG &= ~SW12; P4IE |= SW12; TA0CCTL1 &= ~CCIE; debounceCounter = DEBOUNCE; } break; case CCR2: // CCR2 not used driveTimer++; TA0CCR2 += TA0CCR2_INTERVAL; // Add Offset to TACCR2 mSecCount++; break; case CCRO: // overflow break; default: break; } } #pragma vector = TIMER1_A0_VECTOR __interrupt void Timer1_A0_ISR(void){ //------------------------------------------------------------------------------ // This timer interrupt blinks the LCD 1 time every second. On for 500 msec / // Off for 500 msec. // globals: LCD_Timer // locals: none // returns: none //------------------------------------------------------------------------------ TA1CCR0 += TA1CCR0_INTERVAL; // Add Offset to TACCR0 mSecCount++; }

9.6 Serial Code (Send and Receive Transmissions) //------------------------------------------------------------------------------ // // Description: This file contains the Switch processes that controls the // effects of pressing both switch 1 and switch 2. // // Zachary Fearnside // September 2016 // Built with IAR Embedded Workbench Version: V7.4.2.4369 (6.50.1)

Page 56: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

56 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #include "msp430.h" #include "functions.h" #include "macros.h" extern volatile unsigned int usb_rx_ring_wr; extern volatile char USB_Char_Rx[SMALL_RING_SIZE]; extern volatile unsigned int usb_rx_ring_rd; extern char display_char[MAX_LENGTH_OF_DISPLAY]; extern char* display_2; void startTransmission(void){ //------------------------------------------------------------------------------ // Switches_Process checks for the current value of the two switches on the FRAM // Experimenter Board. If message 1 is displayed and switch 2 is pressed, then the // second message is displayed and vise versa. // // When the switches are pressed, the configuration mode of pin j.0 is also toggled // globals: none // Locals: none // Returned: none //------------------------------------------------------------------------------ display_2 = "0001"; Display_Process(); waitMSec(ONE_SECOND); display_2 = " "; Display_Process(); while (!(UCA1IFG & UCTXIFG)); UCA1TXBUF = LOW_ORDER_BYTE; while (!(UCA1IFG & UCTXIFG)); UCA1TXBUF = HIGH_ORDER_BYTE; //Setup transmitVal = 1, point to it. //load low order into transmitbuff (0x01), increment pointer //load high order bit into transmitubff (0x02), reset pointer //num2transmit = 2 //Display (transmitVal) //wait 1 sec //load into buff, wait, load into buff. proceed. //------------------------------------------------------------------------------ } void receiveTransmission(void){ int receivedVal; char* pointToReceivedVal; int* tempPoint; tempPoint = &receivedVal; pointToReceivedVal = (char*) tempPoint; *pointToReceivedVal = USB_Char_Rx[HALF_ONE_INT]; //usb_rx_ring_rd++; pointToReceivedVal++; *pointToReceivedVal = USB_Char_Rx[HALF_TWO_INT]; usb_rx_ring_wr--; usb_rx_ring_wr--; // if (++usb_rx_ring_rd >= (SMALL_RING_SIZE-1)){ // usb_rx_ring_rd = BEGINNING; // Circular buffer back to beginning

Page 57: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

57 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

// } receivedVal++; pointToReceivedVal--; HEXtoBCD(receivedVal); SendToDisplay(display_char,LINE_TWO); Display_Process(); waitMSec(ONE_SECOND); display_2 = " "; Display_Process(); while (!(UCA1IFG & UCTXIFG)); UCA1TXBUF = *pointToReceivedVal; pointToReceivedVal++; while (!(UCA1IFG & UCTXIFG)); UCA1TXBUF = *pointToReceivedVal; }

9.7 Miscellaneous Functions

i. Detect Black Line void blackLineNavigation (void){ //===================================================================== // Function name: blackLineNavigation // // Description: This function prompted by an IOT command finds the // black line // Joshua Ndon // Date: Fall 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //===================================================================== P3OUT |= IR_LED; waitForSeconds(COUNTONE); while (forceStop){

if(((ADC_Left_Detector < BLACKLINEV)&&(ADC_Right_Detector < BLACKLINEV))){

left_forward_rate = MID_SPEED; right_forward_rate = MID_SPEED; right_forward_on(); left_forward_on(); } else{ display_2 = "Intercept"; posL2 = L_SPACE_0; Display_Process(); stop(); waitForSeconds(COUNTONE); forceStop = RESETZERO; startLineNavigation = TRUE; break; }

}

Page 58: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

58 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

ii. Reset WiFi void resetWifi(void){

//--------------------------------------------------------------------- // resetWifi sends a reset command to the IOT device for a software // reset and then performs a hardware reset. // // globals: none // Locals: word // Returned: none //--------------------------------------------------------------------- char* word; word = "AT+CFUN=1"; sendWordIOT(word); waitMSec(TIME_BUFF_TRANSMISSION); waitMSec(TIME_BUFF_TRANSMISSION); PJOUT |= IOT_RESET; PJOUT &= ~IOT_RESET; waitMSec(50);

}

iii. Check Dissociation void checkDissociation(void){

char i; //------------------------------------------------------------------- // This function checks for the ":8" signaler of the dissociation // status message given out by the IOT. After confirming a dissociation // occurred, a reset is performed. // // globals: USB_Char_A1_Rx // Locals: I // Returned: none //------------------------------------------------------------------------ for(i=0;i<31;i++){ if( (USB_Char_A1_Rx[i] == ':') && (USB_Char_A1_Rx[i+1] == '8')){ P1OUT |= LCD_BACKLITE ; resetWifi(); checkIP(); USB_Char_A1_Rx[i] = '0'; USB_Char_A1_Rx[i+1] = '0'; P1OUT &= ~LCD_BACKLITE; } } if ((USB_Char_A1_Rx[31]==':') && (USB_Char_A1_Rx[0] == '8')){ resetWifi(); USB_Char_A1_Rx[31] = '0'; USB_Char_A1_Rx[0] = '0'; } }

Page 59: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

59 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

iv. Status Report

.. // status_report // William Shaw // locals: none // Retrieves the SSID of the connected network // Retrieves the IP of the IOT device // Displays them on the LCD display void status_report(void) { int i; char status[EIGHT] = "AT+S.STS"; for(i=ZERO;i<EIGHT;i++) // Sends out the command { transmit_A0(status[i]); transmit_A1(status[i]); } transmit_A1(0x0D); transmit_A0('\n'); get_ssid(); // get_ssid gets the ssid while(getting_ssid != ZERO); // wait till SSID has been recieved for(i=ZERO;i<TEN;i++) { display_1[i] = SSID[i]; // set display line 1 as the ssid } get_ip_add(); // get_ip_add gets the IP address while(getting_ip != ZERO); // wait till IP has been recieved display_2 = "ipaddr"; posL2 = ZERO; for(i=ZERO;i<EIGHT;i++) { display_3[i] = ip_address[i]; // Set display line 3 } posL3 = ZERO; for(i=ZERO;i<EIGHT;i++) { display_4[i] = ip_address[i+EIGHT]; // Set display line 4 } posL4 = ZERO; } // get_ssid // gets the ssid of the iot device and puts it into an array void get_ssid(void) { int i; char ssid[TWELEVE] = "AT+S.SSIDTXT"; // command to receive ssid for(i=ZERO;i<TWELEVE;i++) // sends the command { transmit_A0(ssid[i]); transmit_A1(ssid[i]); }

Page 60: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

60 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

transmit_A1(0x0D); transmit_A0('\n'); getting_ssid = ONE; // signals to the serial coms to put the ssid } // get_ip_add // gets the ip address of the IOT device and puts it in an array void get_ip_add(void) { int i; char ip[EIGHTTEEN] = "AT+S.STS=ip_ipaddr"; // command to receive for(i=ZERO;i<EIGHTTEEN;i++) // sends command { transmit_A0(ip[i]); transmit_A1(ip[i]); } transmit_A1(0x0D); transmit_A0('\n'); getting_ip = ONE; // signals to serial coms to put the ip address }

v. Command Receiving void commands_via_WIFI(void){ //===================================================================== // Function name: commands_via_WIFI // // Description: This function contains structure to receive an // integer from my WIFI // // Joshua Ndon // Date: Fall 2016 // Built with IAR Embedded Workbench Version: 6.50.1 //===================================================================== iot_rx_ring_wr = BEGINNING; for (int i = COUNTZERO; i <= COUNTNINE; i++){ iot_current_character_array[i] = IOT_Char_Rx[i]; } if (iot_current_character_array[COUNTZERO] == 'J'){ // display_4 = "Connected"; // posL4 = L_SPACE_0; if ((iot_current_character_array[COUNTONE] == '0') &&(iot_current_character_array[COUNTTWO] == '5') &&(iot_current_character_array[COUNTTHREE] == '1') &&(iot_current_character_array[COUNTFOUR] == '6')){ display_2 = "Wi-Fi CMDs"; posL2 = L_SPACE_0; performCommand = COUNTONE; // Perform Command switch (iot_current_character_array[COUNTFIVE]) { case 'F': // F case 'f': // f //forceStop = FALSE; startLineNavigation = FALSE;

Page 61: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

61 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

//fullPower(); left_forward_rate = varSpeed; right_forward_rate = varSpeed-COUNTTHOUSAND; left_reverse_rate = RESETZERO; right_reverse_rate = RESETZERO; display_2 = "Forward"; posL2 = L_SPACE_1; Display_Process(); left_forward_on(); right_forward_on(); secondDistance(iot_current_character_array[COUNTSIX]); stop(); display_2 = "Wi-Fi CMDs"; posL2 = L_SPACE_0; Display_Process(); break; case 'B': // B case 'b': // b startLineNavigation = FALSE; //halfPower(); left_forward_rate = RESETZERO; right_forward_rate = RESETZERO; left_reverse_rate = varSpeed; right_reverse_rate = varSpeed-COUNTTHOUSAND; display_2 = "Backward"; posL2 = L_SPACE_1; Display_Process(); left_reverse_on(); right_reverse_on(); secondDistance(iot_current_character_array[COUNTSIX]); stop(); display_2 = "Wi-Fi CMDs"; posL2 = L_SPACE_0; Display_Process(); break; case 'R': // R case 'r': // r startLineNavigation = FALSE; left_forward_rate = varSpeed; right_reverse_rate = varSpeed; display_2 = "Right"; posL2 = L_SPACE_1; Display_Process(); left_forward_on(); right_reverse_on(); secondDistance(iot_current_character_array[COUNTSIX]); stop(); display_2 = "Wi-Fi CMDs"; posL2 = L_SPACE_0; Display_Process(); break;

Page 62: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

62 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

case 'L': // L case 'l': // l startLineNavigation = FALSE; right_forward_rate = varSpeed; left_reverse_rate = varSpeed; display_2 = "Left"; posL2 = L_SPACE_1; Display_Process(); right_forward_on(); left_reverse_on(); secondDistance(iot_current_character_array[COUNTSIX]); stop(); display_2 = "Wi-Fi CMDs"; posL2 = L_SPACE_0; Display_Process(); break; case 'P': // P case 'p': // p // Increment speed code stop(); if (varSpeed < WHEEL_PERIOD){ varSpeed += COUNTTHOUSAND; } display_2 = "Speed++"; posL2 = L_SPACE_1; Display_Process(); break; case 'N': // N case 'n': // n // Decrement speed code if (varSpeed > COUNTTHOUSAND){ varSpeed -= COUNTTHOUSAND; } display_2 = "Speed--"; posL2 = L_SPACE_1; Display_Process(); break; case 'X': // X case 'x': // x // Reset stop(); //varSpeed = 2500 ; varSpeed = COUNTFIVETHOUSAND ; display_2 = "SpeedReset"; posL2 = L_SPACE_0; Display_Process(); break; case 'I': // I case 'i': // i display_2 = "BLK LN NAV"; posL2 = L_SPACE_0;

Page 63: Robot Car Project Report

Printed 12/02/16 5:20 PM

Date: Document Number: Rev: Sheet:

63 of 63 12/2/2016

1-4500-3-2016-1

F This document contains information that is PRIVILEGED and CONFIDENTIAL; you are hereby notified that any dissemination of this information is strictly prohibited.

Display_Process(); P1OUT |= LCD_BACKLITE; forceStop = TRUE; blackLineNavigation(); P1OUT &= ~LCD_BACKLITE; break; case 'S': // S case 's': // s stop(); startLineNavigation = FALSE; display_2 = "STOP"; posL2 = L_SPACE_1; Display_Process(); break; default: stop(); break; } for(int j = COUNTZERO; j < COUNTELEVEN; j++) { iot_current_character_array[j] = HEX00; IOT_Char_Rx[j] = HEX00; } } } oneSecCount = COUNTZERO; while ( oneSecCount <=(COUNTONE)){}; performCommand = RESETZERO; //----------------------------------------------------------------------------

}