Project Report(2)

93
USART USART IMPLEMENTATION 1 | Page

Transcript of Project Report(2)

Page 1: Project Report(2)

USART

USART IMPLEMENTATION

Abstract1 | P a g e

Page 2: Project Report(2)

USART

“Design two autonomous bots. The first robot has to explore the arena and find out the location of the mines. It has to inform the second robot about the mines it has detected in the arena. The second robot has to cross the arena avoiding the mines and reach the end point.” We are making two autonomous bots: a mine detector robot and a mine avoider bot. Both of the autonomous bots are mobile bots with a mechanism to move. Both of them need to have a mechanism to follow the white lines that guides their path. The mine detector robot has to explore the arena, sense the mines and inform the mine avoider robot about the position of the mines. For this it has to have a mechanism to sense the mines i.e., a metal detector and detect the intersection of the white lines where the mines are placed. Then, the mine detector robot has to transfer the information to the mine avoider bot. For this they need to be configured for serial transmission. In this tutorial we will be focusing on using USART on the AVR platform. USART can be learnt once the user is comfortable with programming microcontrollers. It is better to start with programming a basic line follower before building USART communication. The mine avoider robot has to cross the arena and reach the finishing point avoiding the mines placed at the intersection of white lines using the information given by the mine detector bot.

Project name:

2 | P a g e

Page 3: Project Report(2)

USART

Implementation of a USART based communication between two lines following robots.

Requirements:

1) Voltage regulator 78052) IR led3) IC LM3244) IC L293D5) AT-MEGA 16 Micro-controller6) RF module7) Motors

Description of the project:

This project focuses on avoidance of land mines at the various sites such as battle field and the Maoist affected areas. In this project the model has been proposed as to how the goal can be achieved without any human interferences or any human controlling the vehicle. We have build two line follower robot in this project, one for mines detection and another for traversing the field avoiding those mines. Here the first robot is equipped with a metal detecting system, whose function is to just detect the presence of the mines in the field and store its location. The detailed function of the first robot is as such: the first robot traverses the whole track i.e a matrix of size four (4*4). While traversing the track the first robot has to detect the metal plates present in the track and store their locations as per the track.

On reaching the end it will transfer all the data about the metal points to the second robot. Now, the second robot will start its journey on the track. The second robot just start from the initial point and while

3 | P a g e

Page 4: Project Report(2)

USART

traversing the whole track it has to avoid those metal points and reach to the end of the track.

Track details:

Size: 4*4

Width of track: 2 cm

Length of the track: 120 cm

Length of extended part: 20 cm

Track type: white track on black back ground.

Figure 1

4 | P a g e

Page 5: Project Report(2)

USART

INTRODUCTION TO LINE FOLLOWERLine follower is a machine that can follow a path. The path can be visible like a black line on a white surface (or vice-versa) or it can be invisible like a magnetic field. The object of a Line Follower is to follow a line that is drawn, painted or taped on the surface where it moves. It should follow this line even though the line curves, turns or goes through certain types of obstacles. The better the robot, the more accurate it will be and the faster it will be able to move while following the line.

Figure 2 (a line following robot)

Why build a line follower?

Sensing a line and maneuvering the robot to stay on course, while constantly correcting wrong moves using feedback mechanism forms a simple yet effective closed loop system. As a programmer you get an opportunity to ‘teach’ the robot how to follow the line thus giving it a human-like property of responding to stimuli.Practical applications of a line follower: Automated cars running on roads with embedded magnets; guidance system for industrial robots moving on shop floor etc.Some other applications:

• Industrial automated equipment carriers• Automated cars.• Tour guides in museums and other similar applications.• Second wave robotic reconnaissance operations.

5 | P a g e

Page 6: Project Report(2)

USART

BLOCK DIAGRAM OF LINE FOLLOWER

Figure 3

6 | P a g e

PIC 16F873Microcontroller

H - BridgeDC Motor Control

LeftMotor

Right Motor

Clock4 MHz

Main Power Supply

Motor Power Supply

HEX Inverte

r

Sensor Array

Analog Comparato

rs

Threshold

Voltage

Priority Encoder

NOR Gate

Page 7: Project Report(2)

USART

Figure 4

The robot uses IR sensors to sense the line; an array of 8 IR LEDs (Tx) and sensors (Rx), facing the ground has been used in this setup. The output of the sensors is an analog signal which depends on the amount of light reflected back, this analog signal is given to the comparator to produce 0s and 1s which are then fed to the uC.

Starting from the center, the sensors on the left are named L1, L2, L3, L4 and those on the right are named R1, R2, R3, R4.Let us assume that when a sensor is on the line it reads 0 and when it is off the line it reads 1. The uC decides the next move according to the algorithm given below which tries to position the robot such that L1 and R1 both read 0 and the rest read 1.

7 | P a g e

Page 8: Project Report(2)

USART

Algorithm: 1. L= leftmost sensor which reads 0; R= rightmost sensor which reads 0.If no sensor on Left (or Right) is 0 then L (or R) equals 0; Ex:

2. If all sensors read 1 go to step 3,Else,If L>R Move LeftIf L<R Move RightIf L=R Move ForwardGo-to step 4

3. Move Clock-wise if line was last seen on Right Move Counter Clock-wise if line was last seen on Left Repeat step 3 till line is found.

4. Go-to step 1.

8 | P a g e

Page 9: Project Report(2)

USART

Sensor array

Sensor: A sensor is a device that measures a physical quantity and converts it into a signal which can be read by an observer or by an instrument.

Figure 5

The resistance of the sensor decreases when IR light falls on it. A good sensor will have near zero resistance in presence of light and a very large resistance in absence of light. We have used this property of the sensor to form a potential divider. The potential at point ‘2’ is Rsensor / (Rsensor + R1). Again, a good sensor circuit should give maximum change in potential at point ‘2’ for no-light and bright-light conditions. This is especially important if you plan to use an ADC in place of the comparator.To get a good voltage swing , the value of R1 must be carefully chosen.

9 | P a g e

Page 10: Project Report(2)

USART

If Rsensor = a when no light falls on it and Rsensor = b when light falls on it. The difference in the two potentials is:Vcc * { a/(a+R1) - b/(b+R1) }

Relative voltage swing = Actual Voltage Swing / Vcc= Vcc * { a/(a+R1) - b/(b+R1) } / Vcc= a/(a+R1) - b/(b+R1)

10 | P a g e

Page 11: Project Report(2)

USART

DETECTION OF INTERSECTION AND FOLLOWING LINE

As the white lines are the only guide to the bots’ path, both of them need to have a line follower mechanism. The mine detector bot must be capable of detecting the intersection of white lines which is the place where it should be searching for mines. The mine avoider bot should detect the same to know its position and the square it is in. Now, detection of the line intersection can be done with the IR proximity detector. But, debugging the sensor becomes very hectic, as you can't see which emitter is actually emitting, while the bot runs. So, an alternative method can be using visible light instead of Infra Red. In this case, you can always see when the light is being emitted and hence the debugging becomes easier. So, we can use an LED-LDR combination i.e. Light Emitting Diode and Light Dependent Resistor Combination. LED is simply a small bulb-like thing which emits light on being provided DC power. LDR, as the name suggests, is a resistor whose resistance depends on the intensity of the light incident on it. The resistance is inversely proportional to the intensity of the light. It generally varies around the 10k Ohm range. So, using a 10k Ohm resistor in series with the LDR should be a wise choice. This works on almost the same principle as the IR proximity detector. But, there is a slight difference. The difference comes in the calibration and the way it detects the white area. Basically, a small intense red/white LED in series with a 120 ohm resistor is sufficient for the light emission. Brighter LEDs make better sensors so try to get as bright LEDs as you can. Now, for detection of the line intersection, we have to use a certain property which differentiates black color from white. We use the fact that the white surface reflects more light than the black surface. Light is emitted from the LED, reaches the surface and is reflected back, to be received by the LDR. So, the voltage drop across the 10k resistor will be greater when the sensor is facing the white surface. We connect this across the comparator, again with a preset value attached to the negative terminal.

11 | P a g e

Page 12: Project Report(2)

USART

Hence, we get a high output for the white surface, and we have detected the line intersection!!! The calibration is a bit different in this case. Here, we keep the sensor above the white surface. Measure the voltage drop across the 10k resistor. Note the value as V1. Then repeat this with the sensor above the black surface. Note the value as V2. Turn the preset so that the voltage supplied to the negative terminal of the comparator is (V1 + V2)/2.

For line following you can use a series of LED-LDR sensor combination i.e., 3 to 6 LED-LDR sensors spread at a distance of more than 2cm. Say the sensors give an output 1 when they are on a white surface and an output 0 when they are on a black surface. When the centre sensor gives an output 1 and the ones on the side give an output 0 it means that the bot is in the middle of the line i.e., between 2 intersection points and it should move forward till the output is changed. This is the condition which the bot should target for line following. If the bot deviates from this condition, let’s suppose the right and the centre sensors gives an output 1 and the left sensors gives an output 0 this implies that the bot has shifted to the left and it must turn a little towards the right to keep the bot exactly at the centre of the white line. When the bot reaches an intersection of white lines all its sensors will give an output 1 which would imply that the bot has reached the intersection of two lines. You can even use the weights method for line following. For this you would need to assign weights to your sensors. The centre sensor is assigned a

12 | P a g e

Page 13: Project Report(2)

USART

weight 0. The one on the just right to it 1and the one on the just left to it -1 and so on for the rest of the sensors. For example if you are using 5 sensors the leftmost sensor is assigned the value -2, the sensor next to it is weighted as -1, the centre one is assigned the value 0, the fourth sensor from the left is weighted as 1 and the extreme right sensor as 2. The speed of the motors can then be changed in proportion to the sum of (output of the sensor*its weight) for all sensors. This value multiplied to proportionality constant is added to the speed of the left motor and subtracted from the speed of the right motor. To achieve very good and smooth line following you can implement PID control in your line following algorithm. PID stands for proportional integral differential. The PID controller algorithm involves three separate parameters; the proportional, the integral and derivative values. The proportional value determines the reaction to the current error, the integral value determines the reaction based on the sum of recent errors, and the derivative value determines the reaction based on the rate at which the error has been changing. The weighted sum of these three actions is used to adjust the process via a control element such as the position of a control valve or the power supply of a heating element. By tuning the three constants in the PID controller algorithm, the controller can provide control action designed for specific process requirements in this case line following. The PID control scheme is named after its three correcting terms, whose sum constitutes the manipulated variable (output) which in this case will be the PWM of the particular motors. The set-point is where you would like the measurement to be. Error is defined as the difference between set-point and the current measurement. (error) = (set-point) - (measurement) The variable being adjusted is called the manipulated variable which usually is equal to the output of the controller. The output of PID controllers will change in response to a change in measurement or set-point.

13 | P a g e

Page 14: Project Report(2)

USART

COMPARATOR (LM 324)

In electronics, a comparator is a device that compares two voltages or currents and switches its output to indicate which is larger. It is used in Analog-to-digital converter (ADCs).An operational amplifier (op-amp) has a well balanced difference input and a very high gain. This parallels the characteristics of comparators and can be substituted in applications with low-performance requirements. In theory, a standard op-amp operating in open-loop configuration (without negative feedback) may be used as a low-performance comparator. When the non-inverting input (V+) is at a higher voltage than the inverting input (V-), the high gain of the op-amp causes the output to saturate at the highest positive voltage it can output. When the non-inverting input (V+) drops below the inverting input (V-), the output saturates at the most negative voltage it can output. The op-amp's output voltage is limited by the supply voltage. An op-amp operating in a linear mode with negative feedback, using a balanced, split-voltage power supply, (powered by ± VS) its transfer function is typically written as: Vout = Ao(V1 − V2). However, this equation may not be applicable to a comparator circuit which is non-linear and operates open-loop (no negative feedback).

In practice, using an operational amplifier as a comparator presents several disadvantages as compared to using a dedicated comparator:[5]

1. Op-amps are designed to operate in the linear mode with negative feedback. Hence, an op-amp typically has a lengthy recovery time from saturation. Almost all op-amps have an internal compensation capacitor which imposes slew rate limitations for high frequency signals. Consequently an op-amp makes a sloppy comparator with propagation delays that can be as slow as tens of microseconds.

14 | P a g e

Page 15: Project Report(2)

USART

2. Since op-amps do not have any internal hysteresis an external hysteresis network is always necessary for slow moving input signals.

3. The quiescent current specification of an op-amp is valid only when the feedback is active. Some op-amps show an increased quiescent current when the inputs are not equal.

4. A comparator is designed to produce well limited output voltages that easily interface with digital logic. Compatibility with digital logic must be verified while using an op-amp as a comparator.

5. Some multiple-section op-amps may exhibit extreme channel-channel interaction when used as comparators.

6. Many op-amps have back to back diodes between their inputs. Op-amp inputs usually follow each other so this is fine. But comparator inputs are not usually the same. The diodes can cause unexpected current through inputs.

Figure 6

A dedicated voltage comparator will generally be faster than a general-purpose operational amplifier pressed into service as a comparator. A dedicated voltage comparator may also contain additional features such as an accurate, internal voltage reference, an adjustable hysteresis and a clock gated input.

15 | P a g e

Page 16: Project Report(2)

USART

DESCRIPTION

These circuits consist of four independent, high gain, internally frequency compensated operational amplifiers .They operate from a single power supply over a wide range of voltages. Operation from split power supplies is also possible and the low power supply current drain is independent of the magnitude of the power supply voltage.

Figure 7(LM 324 top view)

16 | P a g e

Page 17: Project Report(2)

USART

Figure 8(Schematic of LM 324)

symbol Parameter LM 324 unit

Vcc Supply voltage ±16 or 32 VVi Input voltage -0.3 to 32 V

Vid Differential input voltage +32 V

Ptot Power dissipation N suffix D suffix

500400

mWmW

Output short circuit duration note 1 infinity

Iin Input current note 6 50 mA

T oper Operating free air temperature range 0 to +70 ;ͦC

T stor Storage temperature range -65 to + 150 ;ͦC

Table (Absolute maximum rating) 1

Physical specification:

17 | P a g e

Page 18: Project Report(2)

USART

Figure 9

Figure 10

VOLTAGE REGULATOR18 | P a g e

Page 19: Project Report(2)

USART

A voltage regulator is an electrical regulator designed to automatically maintain a constant voltage level. A voltage regulator may be a simple "feed-forward" design or may include negative feedback control loops. It may use an electromechanical mechanism, or electronic components. Depending on the design, it may be used to regulate one or more AC or DC voltages. Electronic voltage regulators are found in devices such as computer power supplies where they stabilize the DC voltages used by the processor and other elements. In automobile alternators and central power station generator plants, voltage regulators control the output of the plant. In an electric power distribution system, voltage regulators may be installed at a substation or along distribution lines so that all customers receive steady voltage independent of how much power is drawn from the line.

The KA78XX/KA78XXA series of three-terminal positive regulator are available in the TO-220/D-PAK package and with several fixed output voltages, making them useful in a wide range of applications. Each type employs internal current limiting, thermal shut down and safe operating area protection, making it essentially indestructible. If adequate heat sinking is provided, they can deliver over 1A output current. Although designed primarily as fixed voltage regulators, these devices can be used with external components to obtain adjustable voltages and currents.

Measures of regulator quality

19 | P a g e

Page 20: Project Report(2)

USART

The output voltage can only be held roughly constant; the regulation is specified by two measurements:

Load regulation is the change in output voltage for a given change in load current (for example: "typically 15mV, maximum 100mV for load currents between 5mA and 1.4A, at some specified temperature and input voltage").

line regulation or input regulation is the degree to which output voltage changes with input (supply) voltage changes - as a ratio of output to input change (for example "typically 13mV/V"), or the output voltage change over the entire specified input voltage range (for example "plus or minus 2% for input voltages between 90V and 260V, 50-60Hz").

Other important parameters are:

Temperature coefficient of the output voltage is the change in output voltage with temperature (perhaps averaged over a given temperature range), while...

Initial accuracy of a voltage regulator (or simply "the voltage accuracy") reflects the error in output voltage for a fixed regulator without taking into account temperature or aging effects on output accuracy.

Dropout voltage is the minimum difference between input voltage and output voltage for which the regulator can still supply the specified current. A Low Drop-Out (LDO) regulator is designed to work well even with an input supply only a Volt or so above the output voltage. The input-output differential at which the voltage regulator will no longer maintain regulation. Further reduction in input voltage will result in reduced output voltage. This value is dependent on load current and junction temperature.

Absolute maximum ratings are defined for regulator components, specifying the continuous and peak output currents that may be used

20 | P a g e

Page 21: Project Report(2)

USART

(sometimes internally limited), the maximum input voltage, maximum power dissipation at a given temperature, etc.

Output noise (thermal white-noise) and output dynamic impedance may be specified as graphs versus frequency, while output ripple noise (mains "hum" or switch-mode "hash" noise) may be given as peak-to-peak or RMS voltages, or in terms of their spectra.

Quiescent current in a regulator circuit is the current drawn internally, not available to the load, normally measured as the input current while no load is connected (and hence a source of inefficiency; some linear regulators are, surprisingly, more efficient at very low current loads than switch-mode designs because of this).

Transient response is the reaction of a regulator when a (sudden) change of the load current (called the load transient) or input voltage (called the line transient) occurs. Some regulators will tend to oscillate or have a slow response time which in some cases might lead to undesired results. This value is different from the regulation parameters, as that is the stable situation definition. The transient response shows the behavior of the regulator on a change. This data is usually provided in the technical documentation of a regulator and is also dependent on output capacitance.

21 | P a g e

Page 22: Project Report(2)

USART

Figure 11

22 | P a g e

Page 23: Project Report(2)

USART

A simple voltage regulator can be made from a resistor in series with a diode. Due to the logarithmic shape of diode V-I curves, the voltage across the diode changes only slightly due to changes in current drawn. When precise voltage control is not important, this design may work fine. Feedback voltage regulators operate by comparing the actual output voltage to some fixed reference voltage. Any difference is amplified and used to control the regulation element in such a way as to reduce the voltage error. This forms a negative feedback control loop; increasing the open-loop gain tends to increase regulation accuracy but reduce stability. There will also be a trade-off between stability and the speed of the response to changes. If the output voltage is too low, the regulation element is commanded, up to a point, to produce a higher output voltage–by dropping less of the input voltage, or to draw input current for longer periods; if the output voltage is too high, the regulation element will normally be commanded to produce a lower voltage.

23 | P a g e

Page 24: Project Report(2)

USART

MICRO-CONTROLLER

A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications.

Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, and toys. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems.

Some microcontrollers may use Four-bit words and operate at clock rate frequencies as low as 4 kHz, for low power consumption (milliwatts or microwatts). They will generally have the ability to retain functionality while waiting for an event such as a button press or other interrupt; power consumption while sleeping (CPU clock and most peripherals off) may be just nanowatts, making many of them well suited for long lasting battery applications. Other microcontrollers may serve performance-critical roles, where they may need to act more like a digital signal processor (DSP), with higher clock speeds and power consumption.

Microcontrollers usually contain from several to dozens of general purpose input/output pins (GPIO). GPIO pins are software configurable to either an input or an output state. When GPIO pins are configured to an input state, they are often used to read sensors or external signals. Configured to the output state, GPIO pins can drive external devices such as LEDs or motors.

24 | P a g e

Page 25: Project Report(2)

USART

Many embedded systems need to read sensors that produce analog signals. This is the purpose of the analog-to-digital converter (ADC). Since processors are built to interpret and process digital data, i.e. 1s and 0s, they are not able to do anything with the analog signals that may be sent to it by a device. So the analog to digital converter is used to convert the incoming data into a form that the processor can recognize. A less common feature on some microcontrollers is a digital-to-analog converter (DAC) that allows the processor to output analog signals or voltage levels.

In addition to the converters, many embedded microprocessors include a variety of timers as well. One of the most common types of timers is the Programmable Interval Timer (PIT). A PIT may either count down from some value to zero, or up to the capacity of the count register, overflowing to zero. Once it reaches zero, it sends an interrupt to the processor indicating that it has finished counting. This is useful for devices such as thermostats, which periodically test the temperature around them to see if they need to turn the air conditioner on, the heater on, etc.

Time Processing Unit (TPU) is a sophisticated timer. In addition to counting down, the TPU can detect input events, generate output events, and perform other useful operations.

A dedicated Pulse Width Modulation (PWM) block makes it possible for the CPU to control power converters, resistive loads, motors, etc., without using lots of CPU resources in tight timer loops.

Universal Asynchronous Receiver/Transmitter (UART) block makes it possible to receive and transmit data over a serial line with very little load on the CPU. Dedicated on-chip hardware also often includes capabilities to communicate with other devices (chips) in digital formats such as I2C and Serial Peripheral Interface (SPI).

25 | P a g e

Page 26: Project Report(2)

USART

Atmega 16 pin diagram:

Figure 12 (AT-MEGA 16 pin configuration)

The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega16 achieves throughputs approaching 1 MIPS per MHz allowing the system designed to optimize power consumption versus processing speed.The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The ATmega16 provides the following features: 16K bytes of In-System Programmable Flash Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1K byte SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG interface for Boundary-scan, On-chip Debugging support and programming, threeflexible Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable USART, a byte oriented Two-wire

26 | P a g e

Page 27: Project Report(2)

USART

Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable gain (TQFP package only), a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable power saving modes. The Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset. In Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping.This allows very fast start-up combined with low-power consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue to run. The device is manufactured using Atmel’s high density nonvolatile memory technology. The On-chip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-chip Boot program running on the AVR core. The boot program can use any interface to download the application program in the Application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega16 is a powerful microcontroller that provides a highly-flexible and cost-effective solution to many embedded control applications.

27 | P a g e

Page 28: Project Report(2)

USART

Figure 13(Block Diagram of AT mega 16)

28 | P a g e

Page 29: Project Report(2)

USART

PIN DESCRIPTION:

VCC: Digital supply voltage.GND: Ground.Port A (PA7..PA0): Port A serves as the analog inputs to the A/D Converter. Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.Port B (PB7..PB0): Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B also serves the functions of various special features of the ATmega16 Port C (PC7..PC0): Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running. If the JTAG interface is enabled, the pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset occurs.Port C also serves the functions of the JTAG interface. Port D (PD7..PD0): Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low

29 | P a g e

Page 30: Project Report(2)

USART

will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port D also serves the functions of various special features of the ATmega16.RESET: Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset.XTAL1: Input to the inverting Oscillator amplifier and input to the internal clock operating circuit.XTAL2: Output from the inverting Oscillator amplifier.AVCC: AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter.AREF: AREF is the analog reference pin for the A/D Converter.

Figure 14(ATMEGA 16)

30 | P a g e

Page 31: Project Report(2)

USART

MOTOR DRIVER (L 293D)

A motor controller is a device or group of devices that serves to govern in some predetermined manner the performance of an electric motor. A motor controller might include a manual or automatic means for starting and stopping the motor, selecting forward or reverse rotation, selecting and regulating the speed, regulating or limiting the torque, and protecting against overloads and faults.

Figure 15(L 293D motor driver)

31 | P a g e

Page 32: Project Report(2)

USART

Block Diagram

The L293 and L293D are quad push-pull drivers capable of delivering output currents to 1A or 600mA per channel respectively. Each channel is controlled by a TTL-compatible logic input and each pair of drivers (afull bridge) is equipped with an inhibit input which turns off all four transistors. A separate supply input is provided for the logic so that it may be run off a lower voltage to reduce dissipation. Additionally the L293D includes the output clamping diodes within the IC for complete interfacing with inductive loads.

32 | P a g e

Page 33: Project Report(2)

USART

SPEED CONTROL:

• To control motor speed we can use pulse width modulation (PWM), applied to the enable pins of L293 driver.

• PWM is the scheme in which the duty cycle of a square wave output from the microcontroller is varied to provide a varying average DC output.

• What actually happens by applying a PWM pulse is that the motor is switched ON and OFF at a given frequency. In this way, the motor reacts to the time average of the power supply.

33 | P a g e

Page 34: Project Report(2)

USART

METAL DETECTOR The mine detector bot has to explore the arena and detect the mines. Since the mines are rectangular iron slabs the bot needs to have a metal detector. Metal detectors use electromagnetic induction to detect metal. The simplest form of a metal detector consists of an oscillator producing an alternating current that passes through a coil producing an alternating magnetic field. If a piece of electrically conductive metal is close to the coil, eddy currents will be induced in the metal, and this produces an alternating magnetic field of its own. If another coil is used to measure the magnetic field (acting as a magnetometer), the change in the magnetic field due to the metallic object can be detected.The circuit diagram given below can be used to make a metal detector. It uses a sensing coil which should be kept near metallic pieces (mines) for detection so you need to orient the coil such that it is placed above the mines when your mine detector bot is traversing the arena.

34 | P a g e

Page 35: Project Report(2)

USART

Specifications:

Resistors -R1,R4 -56K R2 -3K3 R3 -22K R5 -2K7 R6 -2K2 R7,R9 -680E R8 -15K VR1 -5K3386

Trim.-(potentiometer)

Capacitors- C1,C6 -1PF(104)100KPF C2 -1KPF(102).001PF C3 -220PF C4 -270PF C5 -12KPF/100V(.012/100V) C7 -100/25V

Transistors- T1,2,3,4 –BC547PH

Diode D1,2,3,4 – IN4148

LED -5MM Red Led

Coil -Metal detector coil

When the metal detector detects a metal piece (mine) the led glows. The voltage across the led in the absence of the mine is approximately zero and in the presence of mines approximately 2.5 volts, which can be used as an input to the ADC of the microcontroller to be converted to a digital signal. You will learn more about the microcontroller in the next section. Here we would mainly concentrate on how to use ADC. An ADC converts an input voltage (analog value) into a number (i.e.,a digital value). Most modern MCU including AVRs has an ADC on chip. The following example illustrates how an ADC works: If it is an 8-bit ADC and the reference voltage for the ADC is 5V. So if the analog input to the ADC is 5V then the digital converted value is 1111 1111 (Decimal 255) If the input is 2.5V the digital output will be 0111 1111 (Decimal 127) Similarly, a 10 Bit ADC has a range of 0-1023. (2^10=1024) The ADC also has a Reference voltage (ARef). When input voltage is GND the output is 0 and when input voltage is equal to ARef the output is 1023. So the input range is 0-ARef and digital output is 0-1023.

35 | P a g e

Page 36: Project Report(2)

USART

For sensing the presence of mines we would need to give the voltage across the LED as an input to the ADC. The ADC is multiplexed with PORTA that means the ADC channels are shared with PORTA. You would need to use the ADC in free running mode i.e., it is continuously converting. It does a conversion and then start next conversion immediately after that. The registers related to any particular peripheral module (like ADC, Timer, USART etc.) provides the communication link between the CPU and that peripheral. You configure the ADC according to need using these registers and you also get the conversion result also using appropriate registers. The ADC has only four registers. 1. ADC Multiplexer Selection Register – ADMUX : For selecting the reference voltage and the input channel. 2. ADC Control and Status Register A – ADCSRA : As the name says it has the status of ADC and is also use for controlling it. 3. The ADC Data Register – ADCL and ADCH : The final result of conversion is here.

36 | P a g e

Page 37: Project Report(2)

USART

MOTOR

Differential Drive, as the name suggests, is the drive caused due to a "difference”. This is chosen by beginners generally for its simplicity and ease in use. Actually, the rotational motion of the bot occurs in a differential drive due to the difference in the direction of rotation of two different wheels. When it is to be moved forward/backward, the two wheels rotate in the same direction. It basically contains two wheels controlled by two DC motors (preferably geared) on one axis, and one extra caster wheel for support.

Figure 16(Motor different motion)

37 | P a g e

Page 38: Project Report(2)

USART

Motor Interface and control circuit:

38 | P a g e

Page 39: Project Report(2)

USART

ELECTRONICS COMPONENT USED

ResistorsElectric current is simply the motion of electrons from one place to another through a wire. The more electrons that are flowing, the higher the current. Resistors have an apt name: They “resist” the electrical current going through them. You can think of resistors as “brakes” for electrons. By controlling the electrons going through a resistor, you can make a circuit do different things. Resistors may be the primary building block of circuits, so you see them quite a bit in electronics projects. Here are some of the things you can use them for:Limiting current to another component: Some parts, such as light emitting diodes (LEDs), eat up current. Like a kid eats candy bars they try to gobble up as much as you give them. But LEDs run into a problem they burn themselves out if they eat too much current.You can use a resistor to limit the amount of current that reaches an LED.Reducing voltage to part of the circuit: In many circuits, you need to provide different voltages to different parts of the circuit. You can do this easily with resistors.. Assuming that you have two identical resistors, that is, they apply their brakes in the same amount, the voltage in between the two is exactly half that of the rest of the circuit.Controlling the voltage/current going into another component: Combine a resistor and a capacitor, for example, and you create a kind of hourglass timer. Or put a resistor at the input of a transistor to control how much the transistor amplifies a signal.Protecting the inputs of sensitive components: Too much current destroys electronic components. By putting a resistor at the input of a sensitive transistor or integrated circuit, you limit the current that reaches that transistor or circuit. Although not foolproof, this simple technique can save you a lot of time and money that you would lose fixing accidental blow-ups of your circuits.

39 | P a g e

Page 40: Project Report(2)

USART

CapacitorsCapacitors store electrons by attracting them to a positive voltage. When the voltage is reduced or removed, the electrons move off. When a capacitor removes or adds electrons to the circuit in this fashion, it can work to smooth out voltage fluctuations. In some cases you can use capacitors combined with resistors as timers. Capacitors make possible all kinds of circuits, such as amplifiers and thousands of others.Capacitors are used for all sorts of neat applications, includingCreating timers: A kind of electronic metronome, a timer most often pairs up with a resistor to control the speed of the tick-tick-tick.smoothing out voltage: Power supplies that convert AC current to DC often use capacitors to help smooth out the voltage so that the voltage stays at a nice, constant level.Blocking DC current: When connected inline (in series) with a signal source, such as a microphone, capacitors block DC current but pass AC current. Most kinds of amplifiers use this function, for example.Adjusting frequency: You use capacitors to make simple filters that reject AC signals above or below some desired frequency. By adjusting the value of the capacitor, it’s possible for you to change the cut-off frequencies of the filter.

40 | P a g e

Page 41: Project Report(2)

USART

TRANSFERING DATA BETWEEN TWO BOTS

Digital transmission is the transfer of data over a point-to-point or point-to-multipoint transmission medium. There are two basic kinds of digital communication serial and parallel. Serial transmission is the sequential transmission of signal elements of a group representing a character or other entity of data. Digital serial transmissions are bits sent over a single wire, frequency or optical path sequentially.

Serial communication:

Two wire Serial Communication If two wires connect the devices, then one wire can be used to send the data value (0 or 1) and the other wire can be used to indicate when the data wire should be examined.

The transition from 0 to 1 on the clock line indicates when the bit is transmitted. The clock signal controls the timing of the data communication. This type of communication is called synchronous.

One wire Serial Communication The asynchronous technique uses one wire to send the timing and data values. Consider the following transmission of the letter 'R':

Asynchronous communication is limited by the accuracy of the sending and receiving clocks.

41 | P a g e

Page 42: Project Report(2)

USART

Parallel transmission is the simultaneous transmission of the signal elements of a character or other entity of data. In digital communications, parallel transmission is the simultaneous transmission of related signal elements over two or more separate paths. Multiple electrical wires are used which can transmit multiple bits simultaneously.

Asynchronous Communication

Many of the AVR devices provide a device that communicates using the asynchronous technique. The following properties must be defined when using asynchronous communication. Baud rate: The time period of the timer interval. A common period is 1/9600 seconds. Number of data bits: The number of data bits transmitted after the start bit. Number of stop bits: There is usually one or two periods used to transmit the stop bit. Parity: An extra bit containing the parity can be sent to ensure error free communication. The parity bit can be even or odd. This is not always transmitted.

42 | P a g e

Page 43: Project Report(2)

USART

USART

The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the two serial I/O modules (other is the SSP module). The USART is also known as a Serial Communications Interface or SCI. The USART can be configured as a full duplex asynchronous system that can communicate with peripheral devices such as CRT terminals and personal computers, or it can be configured as a half duplex synchronous system that can communicate with peripheral devices such as A/D or D/A integrated circuits, Serial EEPROMs etc.The USART can be configured in the following modes:• Asynchronous (full duplex)• Synchronous - Master (half duplex)• Synchronous - Slave (half duplex)

Synchronous operation uses a clock and data line while there is no separate clock accompanying the data for Asynchronous transmission.Since there is no clock signal in asynchronous operation, one pin can be used for transmission and another pin can be used for reception. Both transmission and reception can occur at the same time — this is known as full duplex operation. Transmission and reception can be independently enabled. However, when the serial port is enabled, the USART will control both pins and one cannot be used for general purpose I/O when the other is being used for transmission or reception.The USART is most commonly used in the asynchronous mode. In this presentation we will deal exclusively with asynchronous operation.The most common use of the USART in asynchronous mode is to communicate to a PC serial port using the RS-232 protocol. Please note that a driver is required to interface to RS-232 voltage levels and the PICmicro® MCU should not be directly connected to RS-232 signals.

43 | P a g e

Page 44: Project Report(2)

USART

CONTROL REGISTERS (Transmitter )

bit 7 CSRC: Clock Source Select bitAsynchronous modeDon’t careSynchronous mode1 = Master mode (Clock generated internally from BRG)0 = Slave mode (Clock from external source)

bit 6 TX9: 9-bit Transmit Enable bit1 = Selects 9-bit transmission0 = Selects 8-bit transmission

bit 5 TXEN: Transmit Enable bit1 = Transmit enabled0 = Transmit disabledNote: SREN/CREN overrides TXEN in SYNC mode.

bit 4 SYNC: USART Mode Select bit1 = Synchronous mode0 = Asynchronous mode

bit 3 Unimplemented: Read as '0'bit 2 BRGH: High Baud Rate Select bitAsynchronous mode1 = High speed0 = Low speedSynchronous modeUnused in this modebit 1 TRMT: Transmit Shift Register Status bit1 = TSR empty0 = TSR full bit 0 TX9D: 9th bit of transmit data. Can be parity bit.

44 | P a g e

Page 45: Project Report(2)

USART

RECEIVER STATUS

bit 7 SPEN: Serial Port Enable bit1 = Serial port enabled (Configures RX/DT and TX/CK pins as serial port pins)0 = Serial port disabledbit 6 RX9: 9-bit Receive Enable bit1 = Selects 9-bit reception0 = Selects 8-bit receptionbit 5 SREN: Single Receive Enable bitAsynchronous modeDon’t careSynchronous mode - master1 = Enables single receive0 = Disables single receiveThis bit is cleared after reception is complete.Synchronous mode - slaveUnused in this modebit 4 CREN: Continuous Receive Enable bitAsynchronous mode1 = Enables continuous receive0 = Disables continuous receiveSynchronous mode1 = Enables continuous receive until enable bit CREN is cleared (CREN overrides SREN)0 = Disables continuous receivebit 3 Unimplemented: Read as '0'bit 2 FERR: Framing Error bit1 = Framing error (Can be updated by reading RCREG register and receive next valid byte)0 = No framing errorbit 1 OERR: Overrun Error bit1 = Overrun error (Can be cleared by clearing bit CREN)

45 | P a g e

Page 46: Project Report(2)

USART

0 = No overrun errorbit 0 RX9D: 9th bit of received data, can be parity bit.

USART BLOCK DIAGRAM:

46 | P a g e

Page 47: Project Report(2)

USART

REQUIRED CODING

Transmitter section:

// 8MHZ fre. of MCU and 9600 baud rate value of UBRR is 51

#include<avr/io.h>

#include<avr/delay.h>

#define th 128

unsigned char a,b,c,d,e;

unsigned char path[3][2]={0,4,1,0,2,4,10,10};

unsigned char arr[7][7]= {0,0,0,0,0,0,0,

0,0,0,0,0,0,0,

0,0,0,0,0,0,0,

0,0,0,0,0,0,0,

0,0,0,0,0,0,0,

0,0,0,0,0,0,0,

0,0,0,0,0,0,0};

char rows=0,cols=0;

47 | P a g e

Page 48: Project Report(2)

USART

void fpwm()

{

TCCR0=0x6A;

DDRB=0xFF;

OCR0=0xFF;

TCCR2=0x6A;

DDRD=0xFF;

OCR2=0xFF;

}

void f_pwm()

{

TCCR0=0x6A;

DDRB=0xFF;

OCR0=180;

TCCR2=0x6A;

DDRD=0xFF;

OCR2=180;

}

48 | P a g e

Page 49: Project Report(2)

USART

void USART_Init( unsigned char ubrr)

{

UBRRH = 0;

UBRRL = ubrr;

UCSRB|= (1<<RXEN)|(1<<TXEN);

UCSRC |= (1 << URSEL)|(3<<UCSZ0);

}

void USART_Transmit( unsigned char data )

{

while ( !( UCSRA & (1<<UDRE)) )

;

UDR = data;

}

unsigned char USART_Receive( void )

{

while ( !(UCSRA & (1<<RXC)) )

;

return UDR;

}

49 | P a g e

Page 50: Project Report(2)

USART

void adc_getvalue()

{

ADMUX=0x60;

_delay_ms(1);

a=ADCH;

ADMUX=0x61;

_delay_ms(1);

b=ADCH;

ADMUX=0x62;

_delay_ms(1);

c=ADCH;

ADMUX=0x63;

_delay_ms(1);

d=ADCH;

ADMUX=0x64;

_delay_ms(1);

e=ADCH;

}

unsigned char check()

50 | P a g e

Page 51: Project Report(2)

USART

{

unsigned char a[4],b[4]={'R','W','P','L'},k=0;

for(k=0;k<4;k++)

{

a[k]=USART_Receive();

USART_Transmit(a[k]);

}

for(k=0;k<4;k++)

if(a[k]!=b[k])

break;

if(k==4)

return 1;

else

{

USART_Transmit('-');

USART_Transmit('(');

return 0;

}

}

51 | P a g e

Page 52: Project Report(2)

USART

void finish()

{

USART_Transmit('S');

_delay_ms(1000);

for(unsigned char i=0;i<50;i++)

{

if(arr[i/7][i%7]==1)

USART_Transmit(i);

_delay_ms(100);

}

USART_Transmit('Z');

while(1){}

}

52 | P a g e

Page 53: Project Report(2)

USART

Receiver coding:

#define length 6

#include<avr/io.h>

#include<avr/delay.h>

unsigned char dir=0;

#define th 128

unsigned char a,b,c,d,e;

unsigned char arr[6][6]={0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,};

void forward()

{

fpwm();

PORTC=0b00001010;

53 | P a g e

Page 54: Project Report(2)

USART

_delay_ms(1000);

_delay_ms(1000);

PORTC=0;

}

void fpwm()

{

TCCR0=0x6A;

DDRB=0xFF;

OCR0=0xFF;

TCCR2=0x6A;

DDRD=0xFF;

OCR2=0xFF;

}

void f_pwm()

{

TCCR0=0x6A;

DDRB=0xFF;

OCR0=180;

TCCR2=0x6A;

DDRD=0xFF;

OCR2=180;

54 | P a g e

Page 55: Project Report(2)

USART

}

void adc_getvalue()

{

ADMUX=0x60;

_delay_ms(1);

a=ADCH;

ADMUX=0x61;

_delay_ms(1);

b=ADCH;

ADMUX=0x62;

_delay_ms(1);

c=ADCH;

ADMUX=0x63;

_delay_ms(1);

d=ADCH;

ADMUX=0x64;

_delay_ms(1);

e=ADCH;

}

55 | P a g e

Page 56: Project Report(2)

USART

void right90()

{

adc_getvalue();

while(a>th)

{

adc_getvalue();

fpwm();

PORTC=0b00001001;//frd

}

while(b>th)

{

adc_getvalue();

fpwm();

PORTC=0b00001001;//frd

}

PORTC=0;

}

void left90()

{

adc_getvalue();

56 | P a g e

Page 57: Project Report(2)

USART

while(e>th)

{

adc_getvalue();

fpwm();

PORTC=0b00000110;//frd

}

while(d>th)

{

adc_getvalue();

fpwm();

PORTC=0b00000110;//frd

}

PORTC=0;

}

unsigned char check(unsigned char row,unsigned char col)

{

unsigned char data=0;

57 | P a g e

Page 58: Project Report(2)

USART

if(arr[row+1][col]==1)

data=data|1;

if(arr[row][col+1]==1)

data=data|2;

if(row>0 && arr[row-1][col]==1)

data=data|4;

if(col>0 && arr[row][col-1]==1)

data=data|8;

return data;

}

void direction()

{

if(dir==2)

{left90();dir=1;}

else if(dir==3)

{left90();dir=1;

forward();left90();

}

else if(dir==4)

58 | P a g e

Page 59: Project Report(2)

USART

{right90();dir=1;}

}

void align()

{

adc_getvalue();

if(a<th && b<th && c<th && d<th && e<th)

forward();

while(a<th && b<th && c<th && d<th && e<th)

{

adc_getvalue();

if(a>th && b>th && c<th && d<th && e>th)

{

f_pwm();

PORTC=0b00001000;//right

}

else if(a>th && b>th && (c<th || d<th || e<th))

{

f_pwm();

PORTC=0b00001001;//right

59 | P a g e

Page 60: Project Report(2)

USART

}

else if(a>th && b<th && c<th && d>th && e>th)

{

f_pwm();

PORTC=0b00000010;//left

}

else if((a<th || b<th || c<th) && d>th && e>th)

{

f_pwm();

PORTC=0b00000110;//left

}

else

{

f_pwm();

PORTC=0b00001010;

}

}

forward();

direction();

}

60 | P a g e

Page 61: Project Report(2)

USART

void path()

{

unsigned char row=0,col=0;

unsigned char status;

while(row<7 && col<7)

{

status=check(row,col);

if(status&0b00000011==0b00000000)

{

if(row<length)

{align();row++;}

else if(col<length)

{

right90();

dir=2;

align();

col++;

}

61 | P a g e

Page 62: Project Report(2)

USART

else

align();

}

else if(status&0b00000011==0b00000001)

{

if(col<length)

{

right90();

dir=2;

align();

col++;

}

else

{

left90();

dir=4;

align();

col--;

}

}

62 | P a g e

Page 63: Project Report(2)

USART

else if(status&0b00000011==0b00000010)

{

if(row<length)

{

align();

row++;

}

else if(status&0b00000100==0)

{

left90();

forward();

left90();

dir=3;

align();

row--;

}

else

{

left90();

dir=4;

63 | P a g e

Page 64: Project Report(2)

USART

align();

col--;

}

}

else

align();

}

}

void USART_Init( unsigned char ubrr)

{

UBRRH = 0;

UBRRL = ubrr;

UCSRB|= (1<<RXEN)|(1<<TXEN);

UCSRC |= (1 << URSEL)|(3<<UCSZ0);

}

void USART_Transmit( unsigned char data )

{

64 | P a g e

Page 65: Project Report(2)

USART

while ( !( UCSRA & (1<<UDRE)) )

;

UDR = data;

}

unsigned char USART_Receive( void )

{

while ( !(UCSRA & (1<<RXC)) )

;

return UDR;

}

void update()

{

unsigned char data;

data=USART_Receive();

while(data!='Z')

{

if(data<36)

arr[data/6][data%6]=1;

65 | P a g e

Page 66: Project Report(2)

USART

data=USART_Receive();

}

}

void main()

{

DDRB=0xFF;

DDRA=0x00;

DDRC=0xFF;

DDRD=0xFF;

ADCSRA=0XE5;

USART_Init(51);//9600 buad rate

if(USART_Receive=='S')

update();

path();

}

CONCLUSION 66 | P a g e

Page 67: Project Report(2)

USART

Line following robots was designed with an objective to detect metal point present in the track, and another to avoid it. With the required technical acumen, hard work, patience and by the grace of god, the project is a resounding success. The first robot has successfully traversed the whole path of 4*4 matrixes storing the mine location. After getting those locations the second robot has successfully traversed the path avoiding those peril locations.

BIBLIOGRAPHY

67 | P a g e

Page 68: Project Report(2)

USART

1) Line Following Robot Priyank Patil

Department of Information Technology K. J. Somaiya College of Engineering Mumbai, India

2) Embedded Robotics Thomas Bräunl

3) www.google.com 4) www.wikipidia.com 5) Designing and Building a Line Following Robot

Richard T. Vannoy II, M.S.I.T., B.S.E.E.T. [email protected]

6) How to program a 8 bit micro-controller using CRichard Mann, Imagcraft

68 | P a g e