Control of DC Motors: - Cegt201 Bradley

coalitionhihatElectronics - Devices

Oct 7, 2013 (3 years and 8 months ago)

79 views

LOW LEVEL DESIGN OF AN



AUTONOMOUS VEHICLE


ABSTRACT


“Gaucho” is a self
-
powered sidewalk machine modified to permit electronic
actuation of the steering. This design consists of a microcontroller and several sensors
mounted on the remote controlled
vehicle to gather information about the vehicle and the
information of the object in front of it. The key focus would be to detect mechanical
motions of the car like direction and speed of the vehicle. The ultimate goal of the project
is to transmit the i
nformation from the microcontroller board to the computer. Ultrasonic
sensors and gear tooth sensors are used to detect the surrounding objects and distance
traveled by the vehicle.



Metrowerks code warrior IDE is a powerful tool used for HC(S)12 process
ors.
IDE provides with some features called Processor Expert. Processor Expert (PE) is a tool,
which contains beans for individual modules of the micro
-
controller. The use of
processor expert feature is implemented in this project. Several areas like comm
unication
between the objects, control of the DC motors, control of linear actuator, serial
communication interface, interfacing of various sensors to the processor are included in
the project. The whole idea of the project is to control the Autonomous veh
icle by
passing messages serially from the laptop to the processor. A rechargeable battery of the
type normally used in RC cars & actuation of drive electronics is used to run the vehicle.



Contents:


Introduction

Micro
-
controller

BDM Interface

CodeWarrio
r IDE

Processor Expert

Embedded Beans

PWM Bean

Timer Capture Bean

BitIO Bean

AsynchroSerial Bean

Drive Motors

Linear Actuator and Steering control

Gear Tooth Sensors

Ultrasonic Sensors

Serial Communication Interface

RS
-
232

Results






Introduction:


The m
ain objective of the project is to control the Autonomous vehicle using a
Motorola
68HCS12 Micro
-
controller
.


Gaucho is a self powered sidewalk machine modified to permit electronic actuation of the
steering and drive.





The
above shown figure is the Autonomous vehicle that was controlled by the Micro
-
controller. The hardware interfacing between all the modules and the processor is done in
this project. The code is written with the help of Processor Expert and finally the Gauc
ho
is controlled by passing messages serially from the Laptop computer to the processor
through Serial Communication Interface.




The whole project overview of all the modules and how they are linked to the Micro
-
controller is shown below in this block d
iagram.




















Micro
-
controller:


The micro
-
controller that I have used in the project is 16
-
bit Motorola
68HC9S12DG256BCPV on EMAC’s IPAC board.


The MC9S12DG256B microcontroller unit (MCU) is a 16
-
bit device composed of
standard on
-
chip peri
pherals including a

16
-
bit central processing unit (HCS12 CPU)

256K bytes of Flash EEPROM

12.0K bytes of RAM

4.0K bytes of EEPROM

2 asynchronous serial communications interfaces (SCI)

three serial peripheral interfaces (SPI)

an 8 channel IC/OC enhanced

capture timer

two 16
-
channel 10
-
bit analog
-
to
-
digital converters (ADC)

an 8
-
channel pulse
-
width modulator (PWM)

89 discrete digital I/O channels (Port A, Port B, Port K and Port E)

20 discrete digital I/O lines with interrupt and wakeup capability

Fi
ve CAN 2.0 A, B software compatible modules (MSCAN12)

Multiplexed External Bus Interface

Module Mapping Control

Interrput control

Background Debug Mode

and an Inter
-
IC Bus.

BDM Interface:




Above shown is the figure of
P&E’s US
B HCS08/HCS12 MULTILINK Interface
, this
interface

provides access to the Background Debug Mode (BDM) on Freescale HCS08,
HC12 and HCS12 microcontrollers. It is the hardware interface between a USB port on a
Windows 2000 or XP machine and the standard 6 pin

“Berg” debug connector on the
target. By using the USB HCS08/HCS12 MULTILINK, the user can take advantage of
the background debug mode to halt normal processor execution and use a PC to control
the processor. The user can then directly control the target’
s execution, read/write
registers and memory values, debug code on the processor, and program internal or
external FLASH memory devices.



The above Figure is the Pinouts of the BDM connector that goes to the target processor
.

BDM module can operate asyn
chronously with the rest of the HCS12 system and access the on
-
board memory without stopping

processor unlike micro
-
controllers with JTAG debugging.

BDM
module can operate asynchronously with the rest of the HCS12 system and access the on
-
board
memory with
out stopping processor. But in the case of the micro
-
controllers with JTAG
debugging interface, the processor must be halt to do any operation like accessing the on
-
board
memory, setting breakpoints etc.


CodeWarrior IDE

CodeWarrior Development Studio is a

complete integrated development environment for
hardware bring
-
up through programming applications.

CodeWarrior IDE is a complete Integrated Development Environment which provides various
tools like




Real time debugger




Full chip simulator




Proces
sor Expert beans




Compiler




Linker




Assembler




Project Manager




Search Engine




Text Editor




Etc

Integrated Development Environment is an application that combines two kinds of tools:

a)

Tools used to manage files like Project Manager, Editor, S
earch Engine, Source Browser,
Build system etc.

b)

Tools used to generate executable file like


Compiler, Assembler, Simulator, Debugger, Editor, Browser etc, and provides interface to all of
them through a single graphical user interface (GUI) to the program
mer.


Compiler is a program that translates a high
-
level language like a C/C++ program (Source code)
to another language specific to a machine (Target code).


Assembler is a low
-

level program that converts an assembly program to a machine language
(bits
of 0 and 1)


Simulator is the tool that represents the real world by a computer program.


Debugger is the tool that tests and debugs the software. A typical remote debugger runs on a
host computer and connects to the target using serial port/USB port/Ethe
rnet port or over a
network. The debugger allows us to download the code into the target for immediate execution.
The execution can be run continuously or step by step thus allowing the programmer to view the
data and fix the bugs/errors.


Processor Expert
:

Processor Expert is designed for rapid application development of embedded applications for a
wide range of micro
-
controllers and micro
-
processor systems
.
Processor Expert works with an
extensible beans library of supported micro
-
processors, peripherals,

virtual devices
.

Processor Expert suggests, connects and generates driver for the embedded system hardware,
peripherals or algorithms. This allows the user to concentrate on the creative part of the whole
design process.

Processor Expert Beans are referr
ed to as Standard Beans, Complex Beans & Software Beans.

Standard Beans (or simple beans) refer to the basic on
-
chip modules such as parallel ports,
timers, A/D converters, and simple serial interfaces as well as simple functions using
them.Software beans
are implementation of functions such as math functions, filtering functions,
motor control functions and flow control fucntions.

The main task of
Processor Expert
is to manage CPU and other hardware resources and
to allow virtual prototyping and design.

Co
de generation from beans, the ability to maintain
user and generated code, and an event based structure significantly reduce the programming
effort in comparison with classic tools.


Embedded Beans:

Embedded Beans

encapsulate functionality of basic element
s of embedded systems like
CPU core, CPU on
-
chip peripherals, standalone peripherals, virtual devices, and pure
software algorithms and change these facilities to properties, methods, and events (like
objects in OOP).
Embedded Beans

are well tested softwar
e and that is why they can save
months of work of the expert programmer.

These components were selected to cover the most commonly required functionality used
for microcontroller applications


from handling port bit operations, external interrupts,
and ti
mer modes up to serial asynchronous/synchronous communications, A/D converter,
I2C, CAN and etc.

A bean provides clear interface that a user controls in design time by using Beans
Inspector. The Beans Inspector has several pages for bean properties, method
s and
events.

By setting properties, a user defines the future behavior of the bean in runtime.







PWM Bean:

The PWM Bean implements a pulse
-
width modulation generator that generates a signal
with variable duty cycle and fixed period.

The fixed period
of 10ms is selected and
variable pulse width for different duty cycle is also selected. Output pin in Port P is
selected to get the desired PWM signal at that pin.

The PWM Bean is configured according to the above said requirements and the desired
output s
ignal is fed into 2 Motors and Linear Actuator.

The Bean Inspector window is shown below in which the bean is to be configured
according to the requirements.


Period is selected as 10ms and pulse width as 5ms for 50% duty cycle, Pulse width can be
changed

here for different duty cycle. The output pin is selected as PP0 from where the
PWM signal is obtained and fed to the Motors.


Timer Capture Bean
:

The distance of the object in front of it is
determined by calculating th
e pulse width of the echo
pulse com
ing from the Ultrasonic Sensors.
To calculate the pulse width, the timer module is used
in the processor.

This bean implements the capture function of the timer.

On the selected edge of
the input signal, the current content of the counter register is writt
en into the capture register and
the OnCapture event is called.

The period of the PWM signal is obtained by capturing the values
of 2 consecutive Falling or Rising edges of the PWM and subtracting the higher value from the
lower value.

T
he Pulse width of t
he signal is obtained by capturing the values of one rising and
next falling edge of the PWM and subtracting them.


The name of the bean, the capture register,
and
the capture input pin
is selected to feed the pulse
signal to that pin. The Edge of the pu
lse rising or falling is selected to start capturing at that
particular edge. Capturing the values at 2 consecutive rising or falling edges gives the Period of
the pulse signal. Capturing at one rising edge and next falling edge gives the value of pulse wi
dth.

Interrupt is enabled here to capture the signal.


BitIO Bean
:

This “BitIO” Bean implements an 1
-
bit input/output. It uses one bit/pin of a port.

This bean has a
subroutine called Putval(value). If direction is
input,
it saves the value to a memory o
r a register
and this value will be written to the pin after switching to the output mode.

If direction is
output,
it

writes the value to the pin.

This bean is used as a direction signal for motors and the linear actuator.


AsynchroSerial Bean:

This bean
"AsynchroSerial" implements an asynchronous serial communication. The bean
supports different settings of parity, word width, stop
-
bit and communication speed and user can
select interrupt or polling handler.

Communication speed can also be changed in runt
ime.

The
bean requires one on
-
chip asynchronous serial channel.

The baud rate selected to transfer data
is 19200 bits per second.


The Bean inspector window is shown below, in which name of bean, channel where
communication is performed, parity bits, stop

bits, baud rate and the transmitter and receiver is
also enabled to receive and send the characters from the laptop to the processor.

Interrupt service is enabled to perform that task when any character is to be sent or received first.









Control o
f DC Motors
:

DC Motors are controlled using a high power H
-
Bridge DC Motor Driver Board, D200
Model manufactured by Tecel Microcontrollers.

The below shown figure is D200 Multiwatt DC Motor Driver Board made by Tecel
Microcontrollers.





The Features of the H
-
bridge DC Motor Driver Board are as follows:

Power Semiconductors:


Four 110A MOSFETS

Rated Current:




10A Without Heat sinks

Max Current:




60A with Proper Heat sinks Installed

Board's Size:




2.5" x 2.5" (6.35cm x 6.35cm).


Components Type:


100% Solid State, No Relays

It has Filter Capacitors, VTS Diodes and snubber circuit ready on board. The voltage
requirements for this driver board are 5 volts for the digital and MOSFET Bias circuits and any
voltage up to 55 volts for

Motor B+.

Besides the Motor B+, the D200 requires a regulated 5 Volt supply for 2 reasons:

1)

For the on board digital circuitry.

This should pose no problem, since all digital and
microcontroller circuits, will be used in conjunction with the D200, are p
owered by a regulated 5
Volt supply.

2)
The on board DC
-
DC converter.

This circuitry generates 3 independent 10
-
volt supplies for
the purpose of supplying the MOSFET's gates with 10 volts no matter what the motor B+ is at in
the range of 0 to 55 volts.



C
onnections of DC Motor Driver board


The below shown is the connections from the Motor and Power supply to the driver
board.





Motor B+ goes to the 24volts power supply and GND to ground.

The 2 pink lines goes to the Motor termina
ls.

The EN, IN1, IN2 are the control lines from the Processor ports.

The

5V supply
required by the control board and the D200 is obtained by means of a 5V
regulator.







Enable

IN1

IN2

Action

H

L

L

Stop

H

L

H

Forward

H

H

L

Reverse

H

H

H

Stop

L

X

X

OFF






The above shown is the truth table of the control signals from the processor to the DC
motor board.

To control the speed of the vehicle PWM signal is fed to Enable input and the IN1 and
IN2 have inputs from “BitIO” Bean.




Control Steering


I
wanted to be able to control the steering via the onboard microcomputer. This
would involve being able to control the position of the linear actuator and determine the
linear actuator position. I have chosen a packaged h
-
bridge component, LMD18200, to
cont
rol the position of the linear actuator. Since it could adequately handle 12 V from the
battery and the maximum 6 A current ne
eded by the linear actuators so I have
decided to
use this component.

From the circuit we determined that we needed to provide a

5 V square wave to the
component and deliver a direction and brake signal from the microcomputer.

Using processor Expert and embedded beans technique I could generate the PWM signal
and the direction signal from the processor. These signals are fed to th
e H
-
bridge from
the respective ports of the processor as shown in the fig below.

Experiments showed that a 5 kHz frequency would be sufficient to drive the linear
actuator. The linear actuator had a potentiometer feedback to determine its position. I
have
connected with the feedback (white wire) returning to the A/D converter for
processing.


LMD 18200

The LMD18200 is a 3A H
-
Bridge designed for motion control applications. The device is
built using a multi
-
technology process that combines bipolar and CMOS
control circuitry
with DMOS power devices on the same monolithic structure. Ideal for driving DC and
stepper motors; the LMD18200 accommodates peak output currents up to 6A. An
innovative circuit, which facilitates low
-
loss sensing of the output current ha
s been
implemented.







Figure
















The above figure shows the driver test circuit of the H
-
bridge with the linear actuator.
Pins 2 and 10 are connected to the actuator motor, direction input from the processor is
fed at pin 3, PWM signal fro
m the processor is fed to pin 5 as input to this circuit, and the
brake signal is grounded at pin 4. The other pin connections are as shown in the figure
above.

PWM signal and the Direction signal are the control signals for controlling the steering.






The above diagram shows the potentiometer circuit of linear actuator.





The above graph shows the values of ADC obtained from the linear actuator.










Gear Tooth Sensors



The relative vehicle position was tracked by measuring the distance travele
d by the vehicle. I did
this using a Hall effect sensor also called Gear Tooth Sensors. Figure below shows a picture of a
Hall Effect sensor mounted on the inner part of the vehicle wheel. We chose this sensor for this
application because it was a durable
sensor. Since it was mounted on the inner part of the wheel,
it would experience a lot of vibrations. Our technician mounted two Hall effect sensors on the
vehicle. One was mounted on the front right wheel, and the other was mounted on the front left
wheel
. Since the accuracy of the distance measurement did not need to be exact for this
application, only the front right wheel Hall Effect sensor was used. The right wheel sensor was
used because it was more likely to be on concrete than the left wheel. In the

future, both Hall
Effect sensors could be used for more accuracy.





Fig: Hall Effect sensor mounted on inner part of vehicle wheel




The Hall Effect sensor detected the motion of a target containing iron. It has 25 sc
rews
mounted on the inner part of the vehicle wheel, which can be seen in Figure. These screws
served as the iron targets. Each time one of these screws passed the Hall Effect sensor; the Hall
Effect sensor produced a TTL pulse. Figure below shows the outp
ut of the Hall Effect sensor in
response to these screws. I have sent the output TTL signal from the Hall Effect sensor to an
external interrupt on the microcomputer, and after every external interrupt, the distance count was
incremented. The circumference

of the wheel was measured to be 4 feet, so after the Hall Effect
sensor produced its 26
th
pulse, the wheel had gone through one full rotation. In other words, the
vehicle had traveled 4 feet. By keeping track of the number of pulses from the Hall Effect s
ensor
through the external interrupt, the microcomputer software kept track of the distance traversed by
the vehicle. In the future, these sensors could also be used to measure the speed of the vehicle,
since the frequency of the TTL signal output from the

Hall Effect sensor was proportional to the
speed of

the vehicle.



Counting the number of pulses gives the distance traveled by the vehicle. These Gear
Tooth Sensors are also used to calculate the speed of the vehicle.




Ultrasonic Sensors:

SRF04 is us
ed as the Ultrasonic rangers to find the distance in front of the vehicle, this is
shown below.



The SRF04 was designed to be just as easy to use as the Polaroid sonar, requiring a short
trigger pulse and providing an echo pulse. Your controller only has

to time the length of
this pulse to find the range.

The connections to the SRF04 are shown below:



This SRF04 just needs a supply of a short 10uS pulse to the trigger input to start the
ranging. The SRF04 will send out an 8 cycle burst of ultrasound at

40khz and raise its
echo line high. It then listens for an echo, and as soon as it detects one it lowers the echo
line again. The echo line is therefore a pulse whose width is proportional to the distance
to the object. By timing the pulse it is possible
to calculate the range in
inches/centimeters or anything else. If nothing is detected then the SRF04 will lower its
echo line anyway after about 36mS.






The timing diagr
am for the Ultrasonic ranger is shown below.



SRF04 provides an echo pulse proport
ional to distance.

The pulse width from the capture
bean measured in number of ticks is converted in to uS.

If the width of the pulse is
measured in uS, then uS/58 gives distance in cms, and uS/148 gives distance in inches.

This distance tells the distance

of an object in front of the vehicle.


Serial Communication Interface
:

The need to exchange data between the MCU and peripheral devices can be satisfied by
using parallel data transfer.The Serial Communication Interface (SCI) was designed to
transfer data

in asynchronous mode that utilizes the industrial standard EIA
-
232 protocol.

The EIA
-
232 was originally called RS
-
232.

RS
-
232 standard was established in 1960 by EIA for interfacing b
etween the computer
and a modem.
Computers and terminals are called DTE.

Modems, bridges and routers are
called DCE.

RS
-
232 is applicable to transfer data rated up to 20,000 bits per second.




The above shown is the pin configuration of RS
-
232 connecting to the PC.

The TD (transmit data) wire

is the one through which data
fr
om a DTE device is
transmitted to a DCE device.

The RD (receive data) wire is the one on which data is received by a DTE device, and the
DCE device keeps this line in a mark condition when idle.

DCD, DSR, DTR, RTS, CTS are the hand shaking signals.

Carri
er Detect is used by a
modem to signal that it has made a connection with another modem, or has detected a
carrier tone. RTS and CTS are used when "hardware flow control" is enabled in both the
DTE and DCE devices. Similarly is the case with DTR and DSR.


The

above shown is the

expected waveform from the UART when using the common 8
Data bits, No Parity and 1 Stop Bit format. The RS
-
232 line, when idle is in the Mark
State (Logic 1). A transmission starts with a start bit which is (Logic 0). Then each bit
is
sent down the line, one at a time. The LSB (Least Significant Bit) is sent first. A Stop Bit
(Logic 1) is then appended to the signal to make up the transmission.


Communication is performed using HyperTerminal
.
This terminal program is an
application
that will enable a PC to communicate directly with a modem.

The COM port
and its settings like the baud rate, data bits, parity bit, stop bits are set.


The commands that I have
used for controlling the vehicle are




F


Forward direction




B


Backwar
d direction




R


Turn Right




L


Turn Left




s


To Stop

One more character follows F and B to tell the speed of the vehicle.

Two more characters follow R and L to turn the car to a particular angle.

To stop the car immediately “s” is used.







Mai
n code:

/** ###################################################################

** Filename : trypwm.C

** Project : trypwm

** Processor : MC9S12DG256BCPV

** Version : Driver 01.05

** Compiler : Metrowerks HC12 C Compiler

** Da
te/Time : 11/7/2005, 7:01 PM

** Abstract :

** Main module.

** Here is to be placed user's code.

** Settings :

** Contents :

** No public methods

**

** (c) Copyright UNIS, spol. s r.o. 1997
-
2002

** UNIS, spol.

s r.o.

** Jundrovska 33

** 624 00 Brno

** Czech Republic

** http : www.processorexpert.com

** mail : info@processorexpert.com

** ###################################################################*/

/* MODULE trypwm */


/* In
cluding used modules for compilling procedure */

#include "Cpu.h"

#include "Events_Dist.h"

#include "Events_cap_USS.h"

#include "Events.h"

#include "PWM_Right_EN.h"

#include "Bit_Right_IN1.h"

#include "Bit_Right_IN2.h"

#include "Bit_Left_IN1.h"

#include "B
it_Left_IN2.h"

#include "PWM_Left_EN.h"

#include "Dis_EInt.h"

#include "PWM_Ultasonicsensor.h"

#include "Cap_USSensorsignal.h"

#include "Dir_actuator_Bit.h"

#include "PWM_Actuator.h"

#include "serialcomm.h"

#include "ADConv.h"

//#include "ADConv.c"

/* Incl
ude shared modules, which are used for whole project */

#include "PE_Types.h"

#include "PE_Error.h"

#include "PE_Const.h"

#include "IO_Map.h"

//#include "math.h"


void readchars(char* cp)

{


int i;


byte ch;



for(i=0;i<3;i++)



{



serialcomm_Recv
Char(&ch);



*cp++ = ch;



}


return;

}

void main(void)

{

byte ret;

word value[1];

int x,y;

int x1=0,y1=0,y2=0,y3=0;

char cha[3];

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/


PE_low_level_init();

/*** End of Processor
Expert internal initialization. ***/

/*Write your code here*/



serialcomm_Enable();


while(1)


{


ADConv_Measure(1);


ADConv_GetValue(&value);


serialcomm_Init();


readchars(cha);


x1 = (cha[1]
-
48);


x = 33 * (25 + x1);





y1 = (cha[2]
-

48);


y2 = (cha[1]
-

48);


y3 = 10 * y2;


y = 452 + (9 * (y3 + y1));


if (cha[0] == 'F')


{



Bit_Right_IN1_PutVal(0);



Bit_Right_IN2_PutVal(1);



Bit_Left_IN1_PutVal(0);



Bit_L
eft_IN2_PutVal(1);



PWM_Right_EN_SetRatio16(x);



PWM_Left_EN_SetRatio16(x);


}


else if (cha[0] == 'B')


{



//x1 = (cha[1]
-
48);



//x = 33 * (25 + x1);




Bit_Right_IN1_PutVal(1);



Bit_Right_IN2_PutVal(0);




Bit_Left_IN1_PutVal(1);



Bit_Left_IN2_PutVal(0);



PWM_Right_EN_SetRatio16(x);



PWM_Left_EN_SetRatio16(x);



}




else if (cha[0] == 'L')


{



Dir_actuator_Bit_PutVal(1);



PWM_Actuator_SetRatio16(28000);




if (value[0] == y)



PWM_Actuator_SetRatio16(0);



}


else if (cha[0] == 'R')


{



Dir_actuator_Bit_PutVal(1);



PWM_Actuator_SetRatio16(28000);



if (value[0] == y)



PWM_Actuator_SetRatio16(0);


}


else if (
cha[0] == 's')


{




Bit_Right_IN1_PutVal(0);


Bit_Right_IN2_PutVal(0);


PWM_Actuator_SetRatio16(0);




Bit_Left_IN1_PutVal(0);


Bit_Left_IN2_PutVal(0);


PWM_Actuator_SetRati
o16(0);


}

}