Minor Report (Dj- Edit)
-
Upload
kumar-animesh-singh -
Category
Documents
-
view
218 -
download
0
Transcript of Minor Report (Dj- Edit)
-
8/13/2019 Minor Report (Dj- Edit)
1/55
MINOR PROJECT REPORT
ON
AIR GESTURE CONTROLLED ROVER(AGCRov)
Integrationof TI MSP430 MCU with MATLAB via Real Time Image Processing
Submitted in partial fulfilment of the requirementfor the award of degree of
Bachelor of Technology
in
ELECTRONICS & COMMUNICATION
Under the Sincere Supervision ofMR. MUKESH SAHU
MR. KALYAN SINGH
Submitted by:-DASHMEET KAUR(10413202810)
NAMRATA (12513202810)ARNAV MENDIRATTA (13013202810)
DAMANJEET SINGH MAAN (15213202810)
Guru Tegh Bahadur Institute of TechnologyG-8 Area, Rajouri Garden
Affiliated to Guru Gobind Singh Indraprastha University, Dwarka
New Delhi
Batch 20102014
-
8/13/2019 Minor Report (Dj- Edit)
2/55
DECLARATION
We hereby declare that all work presented in the dissertation entitled AIR GESTURE
CONTROLLED ROVER in the partial fulfilment of requirement for the award of the degree of
Bachelor of Technology in Electronics and Communication, Guru Tegh Bahadur Institute of
Technology, affiliated to Guru Gobind singh Indraprasth University is an authentic record of our own
work carried out under the guidance of our mentor, Mr. Mukesh Sahu and Mr. Kalyan Singh.
Date:
DASHMEET KAUR NAMRATA
(10413202810) (12513202810)
ARNAV MENDIRATTA DAMANJEET SINGH MAAN
(13013202810) (15213202810)
-
8/13/2019 Minor Report (Dj- Edit)
3/55
CERTIFICATE
This is to certify that the report entitled AIR GESTURE CONTROLLED ROVER submitted by
Dashmeet Kaur (10413202810), Namrata (12513202810), Arnav Mendiratta (13013202810), Damanjeet
Singh Maan (15213202810) in the partial fulfilment of the requirement for the award of the degree o
Bachelor of Technology in Electronics and Communications, Guru Tegh Bahadur Institute of
Technology, is the record of students own work carried out by them under my supervision.The matter
embodied in this report is original and has not been submitted for the award of any degree.
Date:
Mr. Vaneet Singh
(Head Of Department, Electronics and Communication)
Ms. Parul Dawar Mr. Kalyan Singh
(Project Coordinator,ECE) (Project Mentor)
Ms. Shivani Duggal Mr. Mukesh Sahu(Project Coordinator,ECE) (Project Mentor)
Mr. Amrish Maggo(Project Coordinator,ECE)
-
8/13/2019 Minor Report (Dj- Edit)
4/55
-
8/13/2019 Minor Report (Dj- Edit)
5/55
CONTENTS
1.About SOFTWARE 31.1 MATLAB R2010a(version 7.10) 3
1.1.1 What does MATLAB stand for? 31.1.2 Getting acquainted with MATLAB environment 31.1.3 Digital Image Processing in MATLAB 5
1.1.4 The process 7
1.1.5 Reading and displaying images 71.1.6 Making Mfile and function 8
1.1.7 Removing noise 11
1.1.8 Working in real time 13
1.1.9 Graphical User Interface 151.1.10Serial Communication in MATLAB 18
1.2 IAR EMBEDDED WORKBENCH 20
1.2.1 IAR Embedded Workbench Features 201.2.2 IAR Workbench IDE 20
1.2.3 An Extensible and Modular Environment 20
1.2.4 Project Management Features 20
2. About HARDWARE 222.1 MSPEXP430G2 22
2.1.1 Features 232.1.2 MSP430 Architecture 24
2.1.3 Pin Description and Terminal Functions 24
2.1.4MSP430 Universal Synchronous Asynchronous Receive/Transmit (USART) 27
Communication Interface
2.2 L293D Motor Control H-Bridge IC 322.3 MAX232 Serial Communication IC 34
2.4 USB to Serial Convertor 372.5 Serial Port 38
2.6 Webcam 40
3. Source Code 413.1 For MATLAB 41
3.2 For IAR Embedded Workbench 44
4. Conclusion 485. References 49
-
8/13/2019 Minor Report (Dj- Edit)
6/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
LIST OF FIGURES
Fig 1: MATLAB Welcome Screen 3
Fig 2: MATLAB Tool Box Showing current directory where files are being saved 4
Fig 3: MATLAB Help 4
Fig 4: MATLAB Command Window 5Fig 5: Types of Images: (a) A Binary Image (b) A Grayscale Image (c) A Color Image 6
Fig 6: Process Overview 7Fig 7: A test program in MATLAB 8
Fig 8(a): Sample Image for detection 9
Fig 8(b): Green Color detected in sample image Filteration 10Fig 9: A sample image for Filteration 10
Fig 9(a): Output of sample image when the program is executed 11
Fig 9(b): Filtered image 12
Fig 9(c): Filtered image 12
Fig 10: Snapshot of MATLAB window showing Camera Specifications 13
Fig 11: GUIDE Quick Start Box 16
Fig 12: Explanation of layout of the GUI Template 16
Fig 13: Using Push Button in GUI 17Fig 14: The program for Push Buttons created in GUI 17
Fig 15: TI MSP430G2 Launchpad 22
Fig 16: TI MSP430G2x53 Architecture Block Diagram 24Fig 17: Pin Summary for 20 pin MSP430 Devices 24
Fig 18(a): Connecting UART 28
Fig 18(b): UART Bits 28
Fig 19: The concept of H-Bridge 32Fig 20: A complete Schematic for L293D IC 33
Fig 21: MAX232 Driver/Receiver 34
Fig 22: MAX232(A) DIP Package 35Fig 23: DB9 Male Connector 38
Fig 24: RS232 Connections 39
Fig 25: Screenshot of Device Manager showing Serial Port detected at COM1 39Fig 26: Screenshot of GUI in working project 45
Fig 27: Air Gesture Controlled Rover 48
-
8/13/2019 Minor Report (Dj- Edit)
7/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
ABSTRACT
This project consists of a PC, a microcontroller that collects the data from the PC through MATLAB and
control the robot to move in different directions. The robot is fully controlled by the PC and the
commands from the PC are received by the microcontroller using UART peripheral of microcontroller.Image processing is generated using MATLAB (MATLAB R2010a version is used). For image
processing, the webcam captures the image and the image is viewed over the screen. The information
from image is manipulated; the data is transmitted from PC to microcontroller through serial interfacing.
The robot's hardware is a simple drive using two 200RPM DC gear motors mounted on a metal chassis
with a front castor wheel. On the back motors, plastic wheels are mounted. The motor to drive the circuit
uses L293D IC which has H bridge circuit to move the robot.
-
8/13/2019 Minor Report (Dj- Edit)
8/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
1. ABOUT THE SOFTWARE
1.1 MATLABThis version was released in 5
thMarch 2010 and is known as MATLAB 7.10, release name MATLAB
R2010a. The version is compatible with the Intel 32-bit microprocessor and for Mac.
1.1.1 What does MATLAB stand for?
MATLAB stands for MATrix LABoratory. Hence, as the name suggests, here one can play around with
matrices. Hence, an image (or any other data like sound, etc.) can be converted to a matrix and thenvarious operations can be performed on it to get the desired results and values.
Image processing is quite a vast field to deal with. User can identify colors, intensity, edges, texture or
pattern in an image. In this tutorial, we would be restricting ourselves to detecting colors (using RGB
values) only.
1.1.2 Getting acquainted with MATLAB environment
Following is a screenshot of the MATLAB interface. MATLAB offers an easy to use interface with four
main parts seen below.
Fig 1: MATLAB Welcome Screen
-
8/13/2019 Minor Report (Dj- Edit)
9/55
-
8/13/2019 Minor Report (Dj- Edit)
10/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Now once we are done with knowing the essential features of MATLAB, lets start typing something in
the command window, say: a=5 and press enter.
Fig 4: MATLAB Command Window
1.1.3 DIGITAL IMAGE PROCESSING IN MATLAB
Important terms and types of Images
Pixel: Pixels are the building blocks of an image. In other words, a pixel is the smallest possible image
that can be depicted on the screen.
Binary Image: An image that consists of only black and white pixels.
Gray scale Image: It contains intensity values ranging from a minimum (depicting absolute black) to a
maximum (depicting absolute white) and in between varying shades of gray. Typically, this range is
between 0 and 255.
*Note: In daily language what we refer to as black-and-white (as in old photos) are actually grayscale.
Color Image: Such an image is composed of the three primary colors, Red, Green and Blue, hence also
called an RGB image.
RGB value: All colors which we see around us can be made by adding red, blue and green components
in varying proportions. Hence, any color of the world can uniquely be described by its RGB value whichstands for red, blue and green values. This triplet has each value ranging from 0 to255 with 0 meaning
no component of that particular color and 255 meaning full component. For example, pure red color hasRGB value [255, 0, 0], pure white has [255, 255, 255], pure black has [0, 0, 0] and has RGB value [55,
162, 170].
-
8/13/2019 Minor Report (Dj- Edit)
11/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Fig 5(a) Fig 5(b)
Fig 5(c)Fig 5: Types of Images: (a) A Binary Image (b) A Grayscale Image (c) A Color Image
Representation of an Image in MATLAB
An image in MATLAB is stored as a 2D matrix (of size mxmxn) where each element of the matrixrepresents the intensity of light/color of that particular pixel. Hence, for a binary image, the value of
each element of the matrix is either 0 or 1 and for a grayscale image each value lies between 0 and 255.
A color image is stored as an mxnx3 matrix where each element is the RGB value of that particular pixel(hence its a 3D matrix). It can be considered as three 2D matricesfor red, green and blue intensities.
-
8/13/2019 Minor Report (Dj- Edit)
12/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
1.1.4 THE PROCESS
The basic overview of the process is follows:
Firstly the user points in front of the camera. In order to be detected, the users fingers arecovered by a color-coded band (red in our case).
Now the software program detects the users finger in the form of a colored band by the specificRGB values.
Fig 6: Process Overview
Once detected, the program replaces the picture of the band with a centroid. This enables to treatit as a point sourced object.
Now, the MATLAB program will detect the movement of this centroid for a subsequent numberof frames.
This number of frames to be captured can be changed according to the processor speed andcamera quality (We have used 10 frames per trigger).
1.1.5 Reading and displaying Images
imread(): To read an image and store in a matrix.
Syntax:
IM=imread(filename)
where IM is a matrix. If the file is in the current directory (as described above), then you only need to
write the filename, else you need to write the complete path. Filename should be with extension (.jpg,
.bmp,..). There are some default images of MATLAB like peppers.png, cameraman.tif, etc.
-
8/13/2019 Minor Report (Dj- Edit)
13/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
User can try reading them as
>>im=iread('peppers.png');
It is always advised to use a semi-colon (;) at the end of the statement of reading an image.
Imshow(): Displays the image.
Syntax:
imshow(filename)
or
imshow(im)
Example,
>>imshow('cameraman.tif);
1.1.6 Making M-files and functions
M-file
It is a provision in MATLAB where user can execute multiple commands using a single statement. Herethe group of commands is stored as a MATLAB file (extension .m).
Go to File->New->Blank M-file
MATLAB editor window opens where user can write the statements which user want to execute and
save the file.
Fig 7: A test program in MATLAB
Here we have saved the m-file by the name test.m. Now as you type
>>test
in MATLAB command window, all the above commands will execute.
-
8/13/2019 Minor Report (Dj- Edit)
14/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Comments: As we have comments in C/C++/ Java using double slash (//), in MATLAB we use symbol
% to write comments, i.e., statements that are not considered for execution. You can see comments in
green in the snapshot above.
Functions
Functions are written to organize the code efficiently and make debugging easier. The set of statements
within a function can be executed as and when required by just calling it, thereby avoiding repetitions.
The data which is needed within the function can be passed as arguments and then the required values
can be returned. User can return any no. of values and they can be matrices also.
A function is saved as an m-file with the same name as the name if the function.
For Example, the following function takes the input as a coloured image and returns a binary image
where the green pixels have been replaced as white, rest are black and also returns the total number of
green pixels.
Fig 8(a): Sample Image for detection
So, you first read the image and then call the function by typing in the command window
>> I=imread('shapes.bmp');
>>[img, n]=green(I);
>>nn =
28753
>>imshow(img);
-
8/13/2019 Minor Report (Dj- Edit)
15/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Fig 8(b): Green Color detected in sample image
As you can see, this is a binary image with white pixels at those coordinates which were green in input
image.
Consider the following picture, which is processed using Matlab commands given as follows:
Fig 9: A sample image for Filteration
So, we use the same function with the main conditional statement changed as:
functionbw=red(im)
[m,n,t]=size(im);
bw=zeros(m,n);
for i=1:m
for j=1:n
-
8/13/2019 Minor Report (Dj- Edit)
16/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
if(im(i,j,1)>150 &&im(i,j,2)
-
8/13/2019 Minor Report (Dj- Edit)
17/55
-
8/13/2019 Minor Report (Dj- Edit)
18/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
The use of making a binary file:
In most of problem statements of robotics based on image processing, we are required to find the
centroid, area, and no. of objects of a particular colour. MATLAB has in-built functions for these tasks
which operate on binary images only. Hence we create binary images corresponding to different colours
For example, in the problem statement Brooklyn Builder of Techkriti10, the image from the top
(overhead camera) looks somewhat like (again its an ideal image; the real one will be far different and
full of noise)
1.1.8 Working in Real Time
Getting Hardware information
Till now we have been working on images already saved on our computer. But in actual practice, we
need to work in real time, i.e., we need to take images continuously from the current environment using
a webcam and then process them. Hence, the Image Acquisition toolbox of MATLAB provides supportin this regard.
To start with working in real time, you must have a functional USB webcam connected to your PC and
its driver installed. MATLAB has built-in adaptors for accessing these devices. An adaptor is a
software that MATLAB uses to communicate with an image acquisition device. You can check if the
support is available for your camera in MATLAB by typing the following:
>>imaqhwinfo % stands for image acquisition hardware info
>>cam=imaqhwinfo;
>>cam.InstalledAdaptors
Fig 10: Snapshot of MATLAB window showing Camera Specifications
-
8/13/2019 Minor Report (Dj- Edit)
19/55
-
8/13/2019 Minor Report (Dj- Edit)
20/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
There are 5 supported formats in my camera. The numbers (160x120, 176x144.) denote the size of the
image to be captured by the camera.
Previewing video
One can preview the video captured by the camera by defining an object (say by the name vid) and
associate it with the device.
>>vid=videoinput('winvideo',1, 'YUY2_160x120')
or
>>vid=videoinput('winvideo',1, 'RGB24_160x120')
% depends on availability
It should give information somewhat like this
Fig 10(c): Snapshot of MATLAB window showing a summary of Input Video
1.1.9 Graphical user interface
GUIDE initiates the GUI design environment (GUIDE) tools that allows user to create or edit GUIs
interactively
Starting GUIDE
Start GUIDE by typing guideat the MATLAB command prompt. This command displays the GUIDE
Quick Start dialog box, as shown in the following figure.
-
8/13/2019 Minor Report (Dj- Edit)
21/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Fig 11: GUIDE Quick Start Box
From the GUIDE Quick Start dialog box, one can perform the following tasks:
Create a new GUI from one of the GUIDE templatesprebuilt GUIs that you can modify foryour own purposes.
Open an existing GUI.The Layout Editor
When you open a GUI in GUIDE, it is displayed in the Layout Editor, which is the control panel for allof the GUIDE tools. The following figure shows the Layout Editor with a blank GUI template.
Fig 12: Explanation of layout of the GUI Template
-
8/13/2019 Minor Report (Dj- Edit)
22/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
User can lay out their GUI by dragging components, such as panels, push buttons, pop-up menus, or
axes, from the component palette, at the left side of the Layout Editor, into the layout area. For exampleif user drag three push buttons into the layout area, it might look like this.
The illustration also shows how the GUIDE tool palette looks when user set a preference to showcomponent names, as described above.User can also use the Layout Editor (along with the Toolbar Editor and Icon Editor) to create menus and
toolbars, create and modify tool icons, and set basic properties of the GUI components.
Fig 13: Using Push Button in GUIAnd there is an auto generated program is like the following:
Fig 14: The program for Push Buttons created in GUI
-
8/13/2019 Minor Report (Dj- Edit)
23/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
1.1.10 SERIAL COMMUNICATION IN MATLAB
Serial Interface (RS-232) and MATLABMany devices and instruments connect to a computer through a serial interface. User can communicate
with any device or instrument that has a serial interface directly from MATLAB and Simulink withInstrument Control Toolbox.
The toolbox provides the tools that let user communicate with, configure and transfer data to or fromtheir serial device without writing code. Usercan generate MATLAB code for their serial device thatthey can reuse later to communicate with their device or develop graphical applications. User can also
communicate with their serial device using MATLAB scripts or create their own software drivers andencapsulate low-level serial commands into higher level commands that are easier to access.
Always Set:
User always have to set this to match what is specified in the documentation that came with their device.
BaudRateAlways Check:
The defaults here are usually OK, but user should check that they match whatever is specified in the
device documentation.
Terminator (sometimes have to change) 'LF' is linefeed, 'CR' is carrage return, etc FlowControl (defaults usually OK) Parity (defaults usually OK) DataBits (defaults usually OK) ByteOrder (more on this later)
Good Idea To Set:
User's device will work without setting these but user can set these to make their life easy later.
Tag:The tag is like giving the serial port object a nickname.If have a few different serial portsopen this a good way to keep track of them.Example, serialPort is configured to talk with a
garmin GPS.
set(serialPort, 'tag', 'GarminGPS')
TimeOut: If user try to read data from the serial port and there is no data in the buffer matlabwill keep trying to read for "Timeout" seconds (default 10 sec):
get(serialPort, 'Timeout')
ans =
10
This might really slow down the code. There are ways around this, but if there is no data there user
probably don't want to sit there for 10 seconds, so consider making it smaller. On the other hand, it does
-
8/13/2019 Minor Report (Dj- Edit)
24/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
take some time for messages to pass over the wire, so setting it to zero means user will probably miss a
lot of messages.
InputBufferSize: This specifies how long the buffer is.The default is 512 bytes. That might notbe long enough for the messages. Especially if user think the sensor will be streaming data back
more frequently than they plan on reading the buffer. Remember if the sensor tries to send dataand the buffer is full it will discard some old data and it will be gone forever. On the other hand
having unnecessarily large buffer can be cumbersome.
Closing Serial Port Objects
Concepts
When user is done with a serial port object it doesn't go away. Also, closing it, deleting it from memory
and clearing it from the workspace are three separate actions.
Example Code
For technical reasons user have to use this syntax to properly get rid of it:
delete(serialPort_new)clearserialPort_new
-
8/13/2019 Minor Report (Dj- Edit)
25/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
1.2 IAR Embedded Workbench
IAR Embedded Workbench is a development environment that includes a C/C++ compiler and debugger
and supports 30 different processor families.
1.2.1 The IAR Embedded Workbench FeaturesThe IDE is the framework where all necessary tools are seamlessly integrated:
The highly optimizing IAR C/C++ Compiler
The IAR Assembler The versatile IAR XLINK Linker
The IAR XAR Library Builder and the IAR XLIB Librarian
Apowerful editor
A project manager A command line build utility
IAR C-SPY Debugger, a state-of-the-art high-level language debugger.
IAR Embedded Workbench is available for many microprocessors and microcontrollers in the 8-, 16-,
and 32-bit segments, allowing user to stay within a well-known development environment also for the
next project. It provides an easy-to-learn and highly efficient development environment with maximumcode inheritance capabilities, comprehensive and specific target support. IAR Embedded Workbench
promotes a useful working methodology, and you can reduce your development time significantly by
using the IAR Systems tools. We call this concept Different Architectures. One Solution. If userwant
detailed information about supported target processors, contact the software distributor or IAR Systemsrepresentative, or visit the IAR Systems web site www.iar.com for information about recent product
releases.
1.2.2 IAR Embedded Workbench IDE for MSP430The IAR XLINK Linker can produce many output formats, allowing for debugging on most third-party
emulators.Support for RTOS-aware debugging and high-level debugging of state machines canalso be
added to the product.The compiler, assembler, and linker can also be run from a command line environment,if user want to
use them as external tools in an already established project environment.The IDE is a flexible integrated
development environment, allowing user to developapplications for a variety of target processors. Itprovides a convenient Windowsinterface for rapid development and debugging.
1.2.3 AN EXTENSIBLE AND MODULAR ENVIRONMENT
Although the IDE provides all the features required for a successful project, we also recognize the need
to integrate other tools. Therefore the IDE is easily adapted to work. The IAR Embedded WorkbenchIDE.
1.2.4 Project management FEATURESThe IDE comes with functions that will help user to stay in control of all projectmodules, for example, C
or C++ source code files, assembler files, include files, andother related modules. User create
workspaces and let them contain one or severalprojects. Files can be grouped, and options can be set onall levelsproject, group, orfile. Changes are tracked so that a request for rebuild will retranslate all
-
8/13/2019 Minor Report (Dj- Edit)
26/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
requiredmodules, making sure that no executable files contain out-of-date modules. This list shows
some additional features:
Project templates to create a project that can be built and executed out of the box fora smooth
development startup
Hierarchical project representation Source browser with a hierarchical symbol presentation Options can be set globally, on groups of source files, or on individual source files
The Make command automatically detects changes and performs only the requiredoperations
Text-based project files Custom Build utility to expand the standard tool chain in an easy way
Command line build with the project file as input.
-
8/13/2019 Minor Report (Dj- Edit)
27/55
-
8/13/2019 Minor Report (Dj- Edit)
28/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
2.1.1 Features
Low Supply-Voltage Range: 1.8 V to 3.6 V
Ultra-Low Power Consumption Standby Mode: 0.5 A
Off Mode (RAM Retention): 0.1 A
Five Power-Saving Modes Ultra-Fast Wake-Up From Standby Mode in Less Than 1 s 16-Bit RISC Architecture, 62.5-ns Instruction Cycle Time
Basic Clock Module Configurations
Internal Frequencies up to 16 MHz With Four Calibrated Frequency Internal Very-Low-Power Low-Frequency (LF) Oscillator
32-kHz Crystal
External Digital Clock Source
Two 16-Bit Timer_A with three Capture/Compare Registers Up to 24 Capacitive-Touch Enabled I/O Pins
Universal Serial Communication Interface (USCI)
Enhanced UART Supporting Auto Baud rate Detection (LIN) Active Mode: 230 A at 1 MHz, 2.2 V
On-Chip Comparator for Analog Signal Compare Function or Slope Analog-to-Digital (A/D)
Conversion 10-Bit 200-ksps Analog-to-Digital (A/D) Converter With Internal Reference, Sample-and-Hold
and Autoscan.
-
8/13/2019 Minor Report (Dj- Edit)
29/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
2.1.2 MSP430 Architecture
Fig 16: TI MSP430G2x53 Architecture Block Diagram
2.1.3 Pin Description Terminal Functions
Fig 17: Pin Summary for 20 pin MSP430 Devices
-
8/13/2019 Minor Report (Dj- Edit)
30/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Pin Description Table
PIN
NO.
TERMINAL I/O DESCRIPTION
1 DVCC NA
2 P1.0/TA0CLK/
ACLK/
A0
CA0
I/O
General-purpose digital I/O pin
Timer0_A, clock signal TACLK inputADC10 analog input A0(1)ACLK signal outputComparator_A+, CA0 input
3 P1.1/TA0.0/
UCA0RXD/
UCA0SOMI/
A1/CA1
I/O
General-purpose digital I/O pinTimer0_A,capture:CCI0Ainput,compare:Out0output/
transmitUSCI_A0 UART mode: receive data input
USCI_A0 SPI mode: slave data out/master in
ADC10 analog input A1(1)Comparator_A+, CA1 input
4 P1.2/TA0.1
UCA0TXD/
UCA0SIMO/A2/
CA2
I/O
General-purpose digital I/O pinTimer0_A, capture: CCI1A input, compare: Out1
output
USCI_A0 UART mode: transmit data output
USCI_A0 SPI mode: slave data in/master out
ADC10 analog input A2(1)Comparator_A+, CA2 input
5 P1.3/
ADC10CLK/A3/
VREF-/VEREF-/CA3/
CAOUT
I/O
General-purpose digital I/O pin
ADC10, conversion clock output(1)ADC10 analog input A3(1)
ADC10 negative reference voltage (1)Comparator_A+, CA3 input
Comparator_A+, output
6 P1.4/SMCLK/
UCB0STE/UCA0CLK/
A4/
VREF+/VEREF+/
CA4/
TCK
I/O
General-purpose digital I/O pin
SMCLK signal output
USCI_B0 slave transmit enableUSCI_A0 clock input/output
ADC10 analog input A4(1)
ADC10 positive reference voltage(1)
Comparator_A+, CA4 inputJTAG test clock, input terminal for device
programming and test
7 P1.5/ General-purpose digital I/O pin
-
8/13/2019 Minor Report (Dj- Edit)
31/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
TA0.0/
UCB0CLK/UCA0STE/
A5/
CA5/
TMS
I/O Timer0_A, compare: Out0 output / BSL receive
USCI_B0 clock input/outputUSCI_A0 slave transmit enable
ADC10 analog input A5(1)
Comparator_A+, CA5 input
JTAG test mode select, input terminal for deviceprogramming and test
8 P2.0/
TA1.0 I/O
General-purpose digital I/O pin
Timer1_A, capture: CCI0A input, compare:Out0 output
9 P2.1/
TA1.1I/O
General-purpose digital I/O pin
Timer1_A, capture: CCI1A input, compare
Out1 output
10 P2.2/
TA1.1I/O
General-purpose digital I/O pin
Timer1_A, capture: CCI1B input, compare: Out1
output
11 P2.3/
TA1.0I/O
General-purpose digital I/O pin
Timer1_A, capture: CCI0B input, compare: Out0output
12 P2.4/TA1.2 I/O
General-purpose digital I/O pin
Timer1_A, capture: CCI2A input, compare:
Out2 output
13 P2.5/TA1.2 I/O
General-purpose digital I/O pin
Timer1_A, capture: CCI2B input, compare: Out2output
14 P1.6/TA0.1
A6/CA6/UCB0SOMI/
UCB0SCL/
I/O
General-purpose digital I/O pin
Timer0_A, compare: Out1 output
ADC10 analog input A6(1)Comparator_A+, CA6 inputUSCI_B0 SPI mode: slave out master in
USCI_B0 I2C mode: SCL I2C clockJTAG test data input or test clock input during
-
8/13/2019 Minor Report (Dj- Edit)
32/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
TDI/TCLK programming and test
15 P1.7/
A7/CA7/CAOUT/
UCB0SIMO/
UCB0SDA/TDO/TDI
I/O
General-purpose digital I/O pin
ADC10 analog input A7(1)Comparator_A+, CA7 inputComparator_A+, output
USCI_B0 SPI mode: slave in master out
USCI_B0 I2C mode: SDA I2C dataJTAG test data output terminal or test data input
during programming
16 RST/NMI/
SBWTDIO
I
Reset
Nonmaskable interrupt input
Spy-Bi-Wire test data input/output duringprogramming and test
17 TEST/SBWTCK I
Selects test mode for JTAG pins on Port 1.
Spy-Bi-Wire test clock input during
programming and test
18 XOUT/P2.7 I/O
Output terminal of crystal oscillator(3)
General-purpose digital I/O pin
19 XIN/P2.6/
TA0.1 I/O
Input terminal of crystal oscillator
General-purpose digital I/O pin
Timer0_A, compare: Out1 output
20 DVSS NA Ground reference
2.1.4MSP430 Universal Synchronous Asynchronous Receive/Transmit(USART)
Communication Interface
The universal synchronous/asynchronous receive/transmit communicationinterface of the MSP430family can operate in two different modes: synchronousand asynchronous.MSP430 has Universal Serial
Communication Interface (USCI) Module also for serial communication. Depending on derivative of the
MSP430 we can either use USCI or USART and enable one of the modes of operation such as UARTSPI, I2C, etc.
Using UARTUART is simple to connect and it uses 2 lines: TX (Transmit) and RX (Receive). No clock isrequired
because its asynchronous.RS232 is a common connection between PC and devices, and it can be easily converted to RS232 using
a level converter. Another popular solution is to connect the UART of the MSP430 to a USB to UART
converter when interfaced to another module that uses UART, you will need to cross connect the lines.
-
8/13/2019 Minor Report (Dj- Edit)
33/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
The TX of one device will connect to the RX of another device, while the RX will be connected to the
TX of the second device.
Fig18(a): Connecting UART
Fig18(b):UART Bits
UART sends bit serially, one bit after the other, as opposed to parallel. However user dont usually sendindividual bits because of the fact that they convey little information by themselves. Rather, the UART
uses a buffer that is one byte (8 bits) long to which information is written. On a deeper level, the module
sends more than just the byte a user places in the buffer. UART typically sends a start bit, seven or eight
data bits, an even/odd/no parity bit, an address bit (address-bit mode), and one or two stop bits. Theextra bits depend on the configuration of the UART module, but the most common configuration is 8
data bits, one stop bit and no parity. Extra bits that are sent are ultimately discarded and not stored at the
destination buffer. The result of the parity check is however available. Figure 18(b) shows the bit
arrangement in the MSP430s UART Module.
Configuring the UART
Before user can use the UART successfully to send data, both the host computer and the UARTModule must be configured. Because the communication is asynchronous, if the two are not configured
correctly then errors will occur because the interpretation of the timing of the bits will be off.
To better explain how to configure the UART module, the following code is used as an example.
-
8/13/2019 Minor Report (Dj- Edit)
34/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Listing: Configuring UART
1 P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
2 ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD3 UCTL0 |= CHAR; // 8-bit character
4 UTCTL0 |= SSEL0; // UCLK = ACLK = 32.768kHz
5 UBR00 = 0x03; // 32.768kHz/9600 - 3.416 UBR10 = 0x00;7 UMCTL0 = 0x4a; // Modulation
8 UCTL0 &= SWRST; // Initialize USART state machine
9 IE1 |= URXIE0 + UTXIE0; // Enable USART0 RX/TX interrupt
The code above demonstrates that the following steps are needed:
1. Select the I/O pins for UART
2. Enable UART TX, RX, or Both3. Select the character format - 7 or 8 bits
4. Source the UART Module with a clock of a certain frequency
5. Set the baud generator correctly so as to get a correct baud rate from the clock sourced6. Enable the UART module state machine
7. Enable Interrupts if required
Enabling UART RX and TXThe UART module is very flexible. It can control the RX and TX functionalities individually.In this
case we are enabling both. To do this the following code is used:
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXDOf course, for different UART modules we will need to use different register settings.
Selecting Clock
Just like most modules in the MSP430, a clock must be chosen for the UART, and this is arguably themost critical task. Remember that the UART module sends bits every x amount of time. The timing for
the bits is determined from the baud rate, which is derived from a division of the clock time. User wil
assume the clock has already stabilized and is working. Also, it should operate at a specific frequency.In general, the clock frequency dictates the maximum baud rate allowed. ACLK, which is the auxiliary
clock and is usually 32kHz or less (although in some cases it can be sourced from an external high
frequency crystal). This means that in reality, and to keep errors low, user should select a baud rate of9600 baud or less. Higher baud rates require a higher clock and this is normally sourced from SMCLK
and MCLK, which themselves are sourced by the internal DCO or an external high frequency crystal. A
crystal is always preferable because it has much better frequency stability and would almost guarantee
better performance as far as error rates. Its only drawback is the added price and space requirements. Toselect the clock source for BRCLK user need to set the SSELx bits (bits 5 and 4) of the UTCTL1 (for
USART1) or UTCTL0 (for USART0).Bits 5 and 4 will cause the following selection:
Binary Hex Define Clock Source00 0x00 SSEL0 UCLKI
01 0x10 SSEL1 ACLK
10 0x20 SSEL2 SMCLK11 0x30 SSEL3 SMCLK
-
8/13/2019 Minor Report (Dj- Edit)
35/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
The define Column indicates an easy to use definitions defined in the header file msp430x16x.hthat
simplifies reading the code.
To select the 32kHz ACLK source we simply do:UTCTL0 |= SSEL0; // UCLK = ACLK = 32.768kHz
If we wanted to select SMCLK we could do:
UTCTL0 |= SSEL1; // UCLK = ACLK = 32.768kHzUTCTL0 |= SSEL1; // UCLK = SMCLK
Setting the Baud Rate Generator
The baud rate we get is derived from the clock sourced to the UART module. Standard baud rates areused and include:
1200
2400
960019200
57600
115200230400
Using desired baud rate and clock rate we can calculate the divisors required to generate the baud rate.
These calculators use the same methodology that will be presented.
Given a baud rate b = 9600 and a clock speed c = 32768 we have:divisor = c/b = 32768/9600 = 3.413
The integer part of this divisor is easily implementable and you can see so in the code:
UBR00 = 0x03; // 32.768kHz/9600 -> 3 integer part16-bit Integer divisors are possible because there are two registers, UBR00 and UBR01, both 8-bit.
UBR00 contains the upper byte while UBR00 contains the lower byte (lower 8 bits). In this case 3 is not
greater than 255 so that we place 0x00 in the upper byte and 3 (or its hex equivalent 0x03) on the lower
byte. However, we need to get as close as possible to 3.413 or else our baudrate will be off and wewould like it to be as close as possible. In cases where there is no fractional part we ideally dont need to
deal with it, but it occurs in most every case because the clock used is never perfect. Using the
modulation register we can approximate the fractional part of 3.413 to some degree of accuracy. Tocalculate the number of bits we need to set in the modulation register we multiply the fractional part by
8: 8 * 0:413 = 3:304 Rounding gives us 3, so that tell us 3 of the 8 bits in the modulation register need to
be set. To determine which bits to turn on we to successively multiply the fractional part: The importantthing to note is whether, for every addition of one to the multiplying factor, wejump to the next integer.
For example, multiplying by 2 resulted in 0.826 which has an integer of 0. Multiplying by 3 means
1.239 which has an integer part of 1. Because they are not the same we say that we set it that bit because
it carried. On the other hand from 3 to 4 we still have 1 as the integer part, so we dont set. Notice thatwe have a total of 8 multiplications so we can set the 8 bits of the modulation register. Starting from the
multiplication by 2, we consider the first bit to be 0 because multiplication by 1 previously has the same
integer as multiplying by 2. The second multiplication by 3 changes the integer part so we do set that
one. The multiplication by 4 doesnt so we dont set that bit.Note that when we first multiplied 8 * 0.413 = 3.304 we said that we needed to have 3 bits set (1) when
rounding down in the register and from the table it is apparent that we have obtained only 3 bits set. All
we need to do is to consider that we start with the bits, from the bottom or top. The answer is that the bi
-
8/13/2019 Minor Report (Dj- Edit)
36/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
for which we multiplied by 2 is the Least Significant i.e. we start from the bottom of the table and go up,
resulting with the following:
01001010 = 0x4A
Enabling the Module
Once all the settings are complete, we can enable the module as follows:
UCTL0 &= SWRST; // Initialize USART state machine
Enabling InterruptsAlthough it is possible to perform UART operations like as receiving bytes using polling techniques, it
is most commonly done using interrupts and these must be enabled. The UART reset state does not have
to be enabled to turn them on or off. This can be done as follows:
IE1 |= URXIE0 + UTXIE0; // Enable USART0 RX/TX interrupt
Both interrupts are enabled.
Sending and Receiving Information with the UARTNow that the UART is correctly configured and the hardware is set (including the PC software), we can
send data using the UART. This is in fact very simple for single bytes. Each UART module contains two
buffers, a receive buffer and a transmit buffer. For the sending buffer, the user places data (a byte in thiscase) and the module sends it by serializing it and sending the appropriate bits. For the receive buffer it
is the opposite, the bits are deserialized and converted into a byte.
To send a byte of data we simple put it in TXBUF0 or TXBUF1:
TXBUF0 = 0x41;
TXBUF1 = 0x41;
The UART module takes the data put into the buffer and sends it automatically without any further
intervention. Sending multiple bytes isnt much harder. We simply have to ensure that the sending of theprevious byte was finalized before putting new information in the buffer, and this is done by checking
the appropriate flag:
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
The MSP430 will keep executing the while loop (do nothing because of the colon) until the sending flag
has been cleared.
Since the UART buffer is one byte(when it is configured to use 8 bits), we can send any number from 0
to 255, or 0x00 to 0xFF. A major use of sending data is to send readable information. ASCII is a
standard encoding supported by terminal emulators and the C compilers for the MSP430, which allowsus to send readable characters. In this case ASCII maps a byte with a specific value to a specific
character. For example, the lowercase a corresponds to 0x61 while b corresponds to 0x62. It isnot
necessary to learn the ASCII table. Any compiler will automatically replace a with the correspondingnumber without the user needing to explicitly specify that value.
-
8/13/2019 Minor Report (Dj- Edit)
37/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
2.2 L293D Motor Control H-Bridge IC
The first thing comes to mind when making a robot is making the robot move on the ground. And there
are always two options in front of the designer whether to use a DC motor or a stepper motor. When it
comes to speed, weight, size, cost... DC motors are always preferred over stepper motors. There are
many things which user can do with your DC motor when interfaced with a microcontroller. For
example user can control the speed of motor, user can control the direction of rotation, user can also do
encoding of the rotation made by DC motor i.e. keeping track of how many turns are made by their
motors etc. So one can see DC motors are no less than a stepper motor.
Usually H-bridge is preferred way of interfacing a DC motor. These days many IC manufacturers have
H-bridge motor drivers available in the market like L293D is most used H-Bridge driver IC. H-bridge
can also be made with the help of transistors and MOSFETs etc. rather of being cheap, they only
increase the size of the design board, which is sometimes not required so using a small 16 pin IC is
preferred for this purpose.
The name "H-Bridge" is derived from the actual shape of the switching circuit which control the motion
of the motor. It is also known as "Full Bridge". Basically there are four switching elements in the H-
bridge as shown in the figure below.
Fig 19: The concept of H-Bridge
In figure above there are four switching elements named as "High side left", "High side right", "Low
side right", "Low side left". When these switches are turned on in pairs motor changes its directionaccor15dingly. Like, if we switch on High side left and Low side right then motor rotate in forwarddirectio16n, as current flows from Power supply through the motor coil goes to ground via switch low
side right.17
Similarly, when we switch on low side left and high side right, the current flows in opposite direction
and motor rotates in backward direction.
-
8/13/2019 Minor Report (Dj- Edit)
38/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
A simple schematic for interfacing a DC motor using L293D is shown below
Fig 20: A complete Schematic for L293D IC
-
8/13/2019 Minor Report (Dj- Edit)
39/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
2.3 MAX232 Serial Communication IC
Max232 is primary used for people building electronics with an rs232 interface. Serial RS-232 (V.24)
communication works with voltages (between -15V ... -3V are used to transmit a binary '1' and +3V ..
+15V to transmit a binary '0') which are not compatible with today's computer logic voltages. On the
other hand, classic TTL computer logic operates between 0V ... +5V (roughly 0V ... +0.8V referred to aslowfor binary '0', +2V ... +5V for highbinary '1' ). Modern low-power logic operates in the range of 0V
... +3.3V or even lower.
So, the maximum RS-232 signal levels are far too high for today's computer logic electronics, and the
negative RS-232 voltage can't be grokked at all by the computer logic. Therefore, to receive serial datafrom an RS-232 interface the voltage has to be reduced, and the 0and 1voltage levels inverted. In the
other direction (sending data from some logic over RS-232) the low logic voltage has to be "bumped
up", and a negative voltage has to be generated, too.
RS-232 TTL Logic
------------------------------------------------15V ... -3V +2V ... +5V 1+3V ... +15V 0V ... +0.8 0
Fig 21: MAX232 Driver/Receiver
The MAX232 from Maxim was the first IC which in one package contains the necessary drivers (two)
and receivers (also two), to adapt the RS-232 signal voltage levels to TTL logic. It became popularbecause it just needs one voltage (+5V) and generates the necessary RS-232 voltage levels (approx. -
10V and +10V) internally. This greatly simplified the design of circuitry. Circuitry designers no longer
need to design and build a power supply with three voltages (e.g. -12V, +5V, and +12V), but could just
provide one +5V power supply, e.g. with the help of a simple 78x05 voltage regulator. The MAX232has a successor, the MAX232A. The ICs are almost identical, however, the MAX232A is much more
often used (and easier to get) than the original MAX232, and the MAX232A only needs external
capacitors 1/10th thecapacity of what the original MAX232 needs.
MAX232(A) is just a driver/receiver. It does not generate the necessary RS-232 sequence of marks andspaces with the right timing, it does not decode the RS-232 signal, it does not provide a serial/parallel
conversion. All it does is to convert signal voltage levels. Generating serial data with the right timingand decoding serial data has to be done by additional circuitry, e.g. by a 16550 UART or one of these
small micro controllers.
http://commons.wikimedia.org/wiki/File:Max232.jpg -
8/13/2019 Minor Report (Dj- Edit)
40/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Fig 22: MAX232(A) DIP Package
Pin Description Table for MAX232(A) DIP Package Pin Layout
PIN Name Purpose Signal VoltageCapacitor Value
MAX232Capacitor Value
MAX232A
1 C1++ connector forcapacitor C1
capacitor should stand atleast 16V 1F 100nF
2 V+output of voltage
pump
+10V, capacitor should
stand at least 16V1F to VCC 100nF to VCC
3 C1-- connector for
capacitor C1
capacitor should stand at
least 16V1F 100nF
4 C2++ connector for
capacitor C2
capacitor should stand at
least 16V1F 100nF
5 C2-- connector for
capacitor C2
capacitor should stand at
least 16V1F 100nF
6 V-output of voltage
pump / inverter
-10V, capacitor should
stand at least 16V1F to GND 100nF to GND
7 T2out Driver 2 output RS-232
8 R2in Receiver 2 input RS-232
http://commons.wikimedia.org/wiki/File:MAX232_Pinout.svg -
8/13/2019 Minor Report (Dj- Edit)
41/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
9 R2out Receiver 2 output TTL
10 T2in Driver 2 input TTL
11 T1in Driver 1 input TTL
12 R1out Receiver 1 output TTL
13 R1in Receiver 1 input RS-232
14 T1out Driver 1 output RS-232
15 GND Ground 0V 1F to VCC 100nF to VCC
16 VCC Power supply +5V see above see above
V+(2) is also connected to VCC via a capacitor (C3). V-(6) is connected to GND via a capacitor (C4).
And GND(15) and VCC(16) are also connected by a capacitor (C5), as close as possible to the pins.
A Typical ApplicationThe MAX232(A) has two receivers (converts from RS-232 to TTL voltage levels) and two drivers
(converts from TTL logic to RS-232 voltage levels). This means only two of the RS-232 signals can be
converted in each direction.
Typically a pair of a driver/receiver of the MAX232 is used for
TX and RXMAX232 to RS232 DB9 Connection as a DCE
MAX232 Pin No. MAX232 Pin Name Signal Voltage DB9 Pin
7 T2out RTS RS-232 8
8 R2in CTS RS-232 7
9 R2out CTS TTL n/a
10 T2in RTS TTL n/a
11 T1in TX TTL n/a
12 R1out RX TTL n/a13 R1in TX RS-232 3
14 T1out RX RS-232 2
15 GND GND 0 5
-
8/13/2019 Minor Report (Dj- Edit)
42/55
-
8/13/2019 Minor Report (Dj- Edit)
43/55
-
8/13/2019 Minor Report (Dj- Edit)
44/55
-
8/13/2019 Minor Report (Dj- Edit)
45/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Now we can access the serial port from MATLAB by defining a serial port object, lets say by the name
ser as
>>ser=serial ('COM1','BaudRate',9600);This defines the Baud rate as 9600 bps. You can use any Baud rate, but make sure that the same Baud
rate has been configured in the onboard receiver microcontroller also. 9600 bps is the default baud rate.
Now we open the serial port and send data through it.>>fopen(ser);
>>fwrite(ser,'A'); % Move robot left
>>fwrite(ser,'E'); % Pick objectAs the microcontroller interprets the serial data from the PC, it suitably controls the motors through its
output pins, which are connected, to the motor driver or H-bridge (like L293 or L298).
2.6 Webcam
A webcam is a video camera that feeds its image in real time to a computer or computer network. Unlike
an IP camera (which uses a direct connection using ethernet or Wi-Fi), a webcam is generally connected
by a USB cable, FireWire cable, or similar cable.
The webcam have certain properties.
-
8/13/2019 Minor Report (Dj- Edit)
46/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
3. SOURCE CODE
3.1 FOR MATLAB
functionvarargout = Minortest1(varargin)
% MINORTEST1 MATLAB code for Minortest1.fig% MINORTEST1, by itself, creates a new MINORTEST1 or raises the existing% singleton*.%% H = MINORTEST1 returns the handle to a new MINORTEST1 or the handle to% the existing singleton*.%% MINORTEST1('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in MINORTEST1.M with the given input arguments.%% MINORTEST1('Property','Value',...) creates a new MINORTEST1 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before Minortest1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application% stop. All inputs are passed to Minortest1_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Minortest1
% Last Modified by GUIDE v2.5 21-Oct-2013 11:25:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @Minortest1_OpeningFcn, ...'gui_OutputFcn', @Minortest1_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);ifnargin&&ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});end
ifnargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT
% --- Executes just before Minortest1 is made visible.functionMinortest1_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure
-
8/13/2019 Minor Report (Dj- Edit)
47/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to Minortest1 (see VARARGIN)
% Choose default command line output for Minortest1handles.output = hObject;
axes(handles.axes1);imshow('blank.jpg');axes(handles.axes2);imshow('blank.jpg');set(handles.edit1,'String','');handles.t=0;handles.vid=videoinput('winvideo',1,'YUY2_1280x720');set(handles.vid,'ReturnedcolorSpace','rgb');set(handles.vid,'FramesPerTrigger',1);set(handles.vid,'TriggerRepeat',inf);triggerconfig(handles.vid,'manual');% Update handles structureguidata(hObject, handles);
% UIWAIT makes Minortest1 wait for user response (see UIRESUME)% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.functionvarargout = Minortest1_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structurevarargout{1} = handles.output;
% --- Executes on button press in Start.functionStart_Callback(hObject, eventdata, handles)% hObject handle to Start (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)start(handles.vid);fori=1:20trigger(handles.vid);
handles.im=getdata(handles.vid,1);axes(handles.axes1);imshow(handles.im);endguidata(hObject, handles);
% --- Executes on button press in Trigger.functionTrigger_Callback(hObject, eventdata, handles)% hObject handle to Trigger (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)[x y k]=impixel(handles.im);
-
8/13/2019 Minor Report (Dj- Edit)
48/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
s=size(handles.im);thr=0.34;r_min=k(1)-thr*(k(1));g_min=k(2)-thr*(k(2));b_min=k(3)-thr*(k(3));r_max=k(1)+thr*(k(1));g_max=k(2)+thr*(k(2));b_max=k(3)+thr*(k(3));while(1)trigger(handles.vid);handles.im1=getdata(handles.vid,1);im_r=handles.im1(:,:,1);im_g=handles.im1(:,:,2);im_b=handles.im1(:,:,3);im_new=zeros(s(1),s(2));fori=1:s(1)forj=1:s(2)if(im_r(i,j)>=r_min&&im_r(i,j)=g_min&&im_g(i,j)=b_min&&im_b(i,j)
-
8/13/2019 Minor Report (Dj- Edit)
49/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
fprintf(b1,'%c','B');fclose(b1);delete(b1);clearb1;elseif(strcmp(p,'3'))
l1=serial('COM12');fopen(l1);fprintf(l1,'%c','L');fclose(l1);delete(l1);clearl1;elseif(strcmp(p,'4'))
r1=serial('COM12');fopen(r1);fprintf(r1,'%c','R');fclose(r1);delete(r1);clearr1;endend
guidata(hObject, handles);
% --- Executes on button press in Stop.
functionStop_Callback(hObject, eventdata, handles)% hObject handle to Stop (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)stop(handles.vid);delete(handles.vid);clearhandles.vid;guidata(hObject, handles);
functionedit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a doubleguidata(hObject, handles);
% --- Executes during object creation, after setting all properties.functionedit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end
-
8/13/2019 Minor Report (Dj- Edit)
50/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Fig 26: Screenshot of GUI in working project
3.2 FOR IAR EMBEDDED WORKBENCH
#include "msp430g2553.h"
// Hardware-related definitions
#define UART_TXD 0x02 // TXD on P1.1 (Timer0_A.OUT0)
#define UART_RXD 0x04 // RXD on P1.2 (Timer0_A.CCI1A)
#define UART_TBIT_DIV_2 (1000000 / (9600 * 2)) // Conditions for 9600 Baud SW UART,SMCLK = 1MHz#define UART_TBIT (1000000 / 9600)
// Globals for full-duplex UART communication
unsignedinttxData; // UART internal variable for TX
unsigned char rxBuffer; // Received UART character
voidTimerA_UART_tx(unsigned char byte); // Function prototypes
voidTimerA_UART_print(char *string);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DCOCTL = 0x00; // Set DCOCLK to 1MHz
BCSCTL1 = CALBC1_1MHZ;DCOCTL = CALDCO_1MHZ;
P1OUT = 0x00; // Initialize all GPIO
-
8/13/2019 Minor Report (Dj- Edit)
51/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
P1SEL = UART_TXD + UART_RXD; // Timer function for TXD/RXD pins
P1DIR = 0xFF & ~UART_RXD; // Set all pins but RXD to output
P2DIR |= 0xFF;
P2OUT &= 0x00;
// ConfiguresTimer_A for full-duplex UART operationTA0CCTL0 = OUT; // Set TXD Idle as Mark = '1'TA0CCTL1 = SCS + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture, Int
TA0CTL = TASSEL_2 + MC_2; // SMCLK, start in continuous mode
_BIS_SR(GIE); // Enable CPU interrupts
TimerA_UART_print("G2553 TimerA UART\r\n"); // Send test message
TimerA_UART_print("READY.\r\n");
while(1){ // Wait for incoming character
_BIS_SR(LPM0_bits); // Enter low poser mode
TimerA_UART_tx(rxBuffer); // Transmit the received data
if (rxBuffer=='F' || rxBuffer=='f')P2OUT = 0x0A;
else if (rxBuffer=='B' || rxBuffer=='b')
P2OUT = 0x06;
else if (rxBuffer=='L' || rxBuffer=='l')P2OUT = 0x01;
else if (rxBuffer=='R' || rxBuffer=='r')
P2OUT = 0x08;else
P2OUT = 0x00;
}}
voidTimerA_UART_tx(unsigned char byte) { // Outputs one byte using the Timer_A UART
while (TACCTL0 & CCIE); // Ensure last char got TX'd
TA0CCR0 = TAR; // Current state of TA counter
TA0CCR0 += UART_TBIT; // One bit time till first bit
TA0CCTL0 = OUTMOD0 + CCIE; // Set TXD on EQU0, Int
-
8/13/2019 Minor Report (Dj- Edit)
52/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
txData = byte; // Load global variable
txData |= 0x100; // Add mark stop bit to TXData
txData= 1; // Shift right 1 bittxBitCnt--;
}
#pragma vector = TIMER0_A1_VECTOR // Timer_A UART - Receive Interrupt Handler
__interrupt void Timer_A1_ISR(void) {
static unsigned char rxBitCnt = 8;
static unsigned char rxData = 0;
switch (__even_in_range(TA0IV, TA0IV_TAIFG)) { // Use calculated branching
-
8/13/2019 Minor Report (Dj- Edit)
53/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
case TA0IV_TACCR1: // TACCR1 CCIFG - UART RX
TA0CCR1 += UART_TBIT; // Add Offset to CCRx
if (TA0CCTL1 & CAP) { // Capture mode = start bit edge
TA0CCTL1 &= ~CAP; // Switch capture to compare mode
TA0CCR1 += UART_TBIT_DIV_2; // Point CCRx to middle of D0}
else {
rxData>>= 1;
if (TA0CCTL1 & SCCI) // Get bit waiting in receive latch
rxData |= 0x80;
rxBitCnt--;
if (rxBitCnt == 0) { // All bits RXed?
rxBuffer = rxData; // Store in global variable
rxBitCnt = 8; // Re-load bit counter
TA0CCTL1 |= CAP; // Switch compare to capture mode
_BIC_SR(LPM0_EXIT); // wake up from low power mode.
}}
break; }}
Fig 27: Air Gesture Controlled Rover
-
8/13/2019 Minor Report (Dj- Edit)
54/55
-
8/13/2019 Minor Report (Dj- Edit)
55/55
AIR GESTURE CONTROLLED ROVER (AGCRov)
5.REFERENCES
1. www.e2e.ti.com2. www.mathworks.com3. www.msp430.com4. www.embeddedrelated .com5. http://www.instructables.com/id/MATLAB-to-PIC-serial-interface/6. http://www.magna-power.com/applications/interfacing-matlab-through-rs2327. http://mbed.org/cookbook/Interfacing-with-Matlab