Professional Documents
Culture Documents
1.2 Components
The block diagram below in figure 1.1 shows those basic four components to build the line follower which are: 1- The sensors array. 2- The microcontroller (ATmega16). 3- Motor driver (L293D). 4- Two Dc motors.
1.2.1 Sensors
The sensors are one of the most important components of the functional line follower robot ;they are robots eyes, ears, sense of touch, balance and only source of input from external environment The line follower uses IR sensors to sense the line, an array of 2 IR LEDs (Tx) and sensors (Rx), facing the ground. The output of the sensors is an analog signal which depends on the amount of light reflected back, this analog signal is connected to the microcontrollers pins that contain an analog to digital converter (ADC).
1.2.2 Microcontroller
A microcontroller often serves as the brain of a mechatronic system. It can be programmed to interact with both the hardware of the system and the user. Even the most basic microcontroller can perform simple math operations, control digital outputs, and monitor digital inputs. As the computer industry has evolved, so has the technology associated with microcontrollers. Newer microcontrollers are much faster, have more memory, and have a host of input and output features that dwarf the ability of earlier models. Most modern controllers have analog-to-digital converters, high-speed timers and counters, interrupt capabilities, outputs that can be pulse-width modulated, serial communication ports, etc. There are many types of microcontrollers but ATmega-16 is the one used in this project to control the robot movements. The ATmega16 is a low-power CMOS (complementary metal oxide semiconductor) 8-bit microcontroller based on the AVR enhanced RISC (reduced instruction set computing) architecture. By executing powerful instructions in a single clock cycle, the ATmega16 achieves throughputs approaching 1 MIPS per MHz allowing the system 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.[4]
1.2.4 DC motors
The Direct Current (DC) motor is one of the first machines devised to convert electrical energy to mechanical power. Its origin can be traced to machines conceived and tested by Michael Faraday, the experimenter who formulated the fundamental concepts of electromagnetism. These concepts basically state that if a conductor, or wire, carrying current is placed in a magnetic field, a force will act upon it. The magnitude of this force is a function of strength of the magnetic field, the amount of current passing through the conductor and the orientation of the magnet and conductor. The direction in which this force will act is dependent on the direction of current and direction of the magnetic field. Electric motor design is based on the placement of conductors (wires) in a magnetic field. A winding has many conductors, or turns of wire, and the contribution of each individual turn adds to the intensity of the interaction. The
force developed from a winding is dependent on the current passing through the winding and the magnetic field strength. If more current is passed through the winding, then more force (torque) is obtained. In effect, two magnetic fields interacting cause movement: the magnetic field from the rotor and the magnetic field from the stators attract each other. This becomes the basis of both AC and DC motor design.
The figure1.2 below shows the state diagram for the line follower
The state diagram above in figure1.2 explains the strategy the line follower takes to deal with all possible conditions.
the visitors from the entrance to the main office. There are cases where
smarter versions of line followers are used to deliver mail within an office building and deliver medications in a hospital.
computer, a microprocessor requires memory for storing data and programs, and input/output (I/O) interfaces for connecting external devices like keyboards and displays. Microcontrollers are characterized by how many bits of data they process at once, with a higher number of bits generally indicating a faster or more powerful chip. Eight-bit chips are popular for simpler designs, but 4-bit, 16-bit, and 32-bit architectures are also available. All microcontrollers have a defined instruction set, which consists of the binary words that cause the CPU to carry out specific operations. For example, the instruction 0010 0110 tells an 8052 to add the values in two locations. The binary instructions are also known as operation codes (Opcodes) for short. The opcodes perform basic functions like adding, subtracting, logic operations, moving and copying data, and controlling program branching. Inside, microcontrollers are little more than a carefully designed array of logic gates and memory cells, but modern fabrication processes allow thousands of these to fit on a single chip. Since the basic functions of a microcontroller performing arithmetic, logic, data-moving, and program branching functions are common ones that are useful in many applications, its practical to design a chip that performs these functions. The user accesses the abilities of the microcontroller by writing a program that performs the desired functions. The microcontroller contains all of the elements of a computer on a single chip. Using a microcontroller can reduce the number of components and thus the amount of design work and wiring required for a project. [4]
the AVRs, most operation can be done in only one instruction, where it often takes more than one instruction to do the same thing on a PIC. 3. Peripherals: Many Atmel AVR controllers, like many Microchip PIC controllers, have a built-in 10 bit ADC. Some have LCD (Liquid Cristal Display) or USB drivers. 4. One big advantage of AVRs is that they are supported by the GNU Compiler Collection (GCC)."
11
Table 2.1 types of mega AVR Code ROM 8K 16K 32K 64K 128K Data RAM 1K 1K 2K 4K 8K Data EEPROM 0.5K 0.5K 1K 2K 4K I/O pins 23 32 32 54 86
ADC Timers 8 8 8 8 16 3 3 3 4 6
12
2.3.4.2 Tiny AVR As its name indicates, the microcontrollers in this group have less instructions and smaller packages in comparison to mega family. Some characteristics are as follows: Program memory: 1K to 8K bytes. Package: 8 to 28 pins. Limited peripheral set. Limited instruction set: the instruction sets are limited. For example, some of them do not have the multiply instruction.[3]
2.4 ATmega16
The Atmel AT mega 16 is equipped with 32 general purpose 8-bit registers that are tightly coupled to the processors arithmetic logic unit within the CPU. Also, the processor is designed following the Harvard Architecture format. That is, it is equipped with separate, dedicated memories and buses for program and data information. The register-based Harvard Architectures coupled with the RISC-based instruction set allows for fast and efficient program execution and allows the processor to complete an assembly language instruction every clock cycle. Atmel indicates the AT mega 16 can execute 16 million instructions per second when operating at a clock speed of 16 MHz.
13
This
14
Port A (PA7..PA0) Port A serves as the analog inputs to the digital (ADC). Port A also serves as an 8-bit bi-directional I/O port, if the (ADC) 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.
15
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 as listed on table below.
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 and other special features of the Atmega16 as listed on table below.
16
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 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 as listed on table below.
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.
AVCC AVCC is the supply voltage pin for Port A and the ADC. 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.
17
AREF AREF is the analog reference pin for the ADC. [10]
Idle Mode stops the CPU while allowing the USART, Two-wire interface, SRAM (Static Random Access Memory), Timer/Counters, SPI port, and interrupt system to continue functioning.
Power-Down Mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next external interrupt or Hardware Reset.
Power-Save Mode in which the Asynchronous Timer continues to run, allowing to maintain a timer base while the rest of the device is sleeping.
ADC Noise Reduction Mode stops the CPU and all I/O modules except Asynchronous Timer, to minimize switching noise during A/D conversions.
Standby Mode in which 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.
Extended Standby Mode in which both the main Oscillator and the Asynchronous Timer continue to run.[9]
18
yourself by looking up the machine codes for each abbreviation. Another option is to use an assembler, which is software that runs on a desktop computer and translates the mnemonics into machine code. Most assemblers provide other features, such as formatting the program code and creating a listing that shows both the machine-code and assembly-language versions of a program side by-side.
A programming language such as C, FORTRAN, or Pascal that enables a programmer to write programs that are more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine languages. In contrast, assembly languages are considered low-level because they are very close to machine languages. The main advantage of high-level languages over low-level languages is that they are easier to read, write, and maintain. Ultimately, programs written in a high-level language must be translated into machine language by a compiler or interpreter. The first high-level programming
languages were designed in the 1950s. Now there are dozens of different languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP, Pascal, and Prolog. Higher-level languages also simplify programming by allowing you to do in one or a few lines what would require many lines of assembly code to accomplish. Interpreters and compilers are two forms of higher-level languages. An interpreter translates a program into machine code each time the program runs, while a compiler translates only once, creating a new, executable file that the computer runs directly, without re-translating. As a rule, interpreters are very convenient for shorter programs where execution speed
20
isnt critical. With an interpreted language, you can run your program code immediately after writing it, without a separate compile or assembly step. A compiler is a good choice when a program is long or has to execute quickly. A single language like BASIC may be available in both interpreted and compiled versions. [4]
2.7.3.1 BASCOM-AVR BASCOM-AVR is a type of high level languages is four programs in one package, it is known as an IDE (Integrated Development Environment) it includes the program editor, the compiler, the programmer and the simulator all together. BASCOM-AVR is a compiler that uses a version of Basic very similar to QBASIC to produce programs for the AVR. BASCOM-AVR uses IDE which allows writing and editing programs, compiling them, testing them with a simulator and finally writing the program to the microcontroller for use in a circuit all from one program. Microcontrollers, such as the AVR, are controlled by software and they do nothing until they have a program inside them. The AVR programs are written on a PC (Personal Computer) using the BASCOM-AVR. This software is a type of computer program called compiler.[8]
File Name: ----------------------------------------------------------------- 2. Program Description: ----------------------------------------------------------------- 3. Compiler Directives (these tell Bascom things about our hardware) $regfile = attiny26.dat the micro we are using $crystal = 1000000 the speed of the micro ----------------------------------------------------------------- 4. Hardware Setups setup direction of all ports Config Porta = Output LEDs on portA Config Portb =Input switches on portB 5. Hardware Aliases Led0 alias portb.0 6. 22nitialize ports so hardware starts correctly Porta = &B11111111 turns off LEDs ----------------------------------------------------------------- 7. Declare Variables 8. Initialise Variables 9. Declare Constants ----------------------------------------------------------------- 10. Program starts here Do Loop End end program
22
per channel. Moreover for protection of circuit from back EMF output diods are included within the IC. The output supply has a wide range from 4.5V to 36V, which has made L293D a best choice for DC motor driver.
As seen in the figure 3.2 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 direction accordingly. Like, if we switch on High side left and Low side right then motor rotate in forward direction, as current flows from (+) power supply through the motor coil goes to ground via switch low side right. Similarly, when you switch on low side left and high side right, the current flows in opposite direction and motor rotates
25
in backward direction. This is the basic working of H-Bridge. So we have seen that using simple switching elements we can make our own HBridge, or other option we have is using an IC based Hbridge driver. [7]
26
Table 3.1 pin configuration of L293D Pin Number 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 Function Enable pin for Motor 1; active high Input 1 for Motor 1 Output 1 for Motor 1 Ground (0V) Ground (0V) Output 2 for Motor 1 Input 2 for Motor 1 Supply voltage for Motors; 9-12V (up to 36V) Enable pin for Motor 2; active high Input 1 for Motor 1 Output 1 for Motor 1 Ground (0V) Ground (0V) Output 2 for Motor 1 Input 2 for Motor 1 Supply voltage; 5V (up to 36V) Name Enable 1,2 Input 1 Output 1 Ground Ground Output 2 Input 2 Vcc 2 Enable 3,4 Input 3 Output 3 Ground Ground Output 4 Input 4 Vcc 1
27
3.2 Sensors
A sensor is often defined as a device that receives and responds to a signal or stimulus. This definition is broad. In fact, it is so broad that it covers almost everything from a human eye to a trigger in a pistol. Sensors that are used in artificial systems must speak the same language as the devices with which they are interfaced. This language is electrical in its nature. Thus, it should be possible to connect a sensor to an electronic system through electrical wires. Hence, we use a somewhat narrower definition of sensors, which may be phrased as: A sensor is a device that receives a stimulus and responds with an electrical signal. The stimulus is the quantity, property, or condition that is sensed and converted into electrical signal. The purpose of a sensor is to respond to some kind of an input physical property (stimulus) and to convert it into an electrical signal which is compatible with electronic circuits. The sensors considered as a translator of a generally nonelectrical value into an electrical value. The sensors output signal may be in the form of voltage, current, or charge. These may be further described in terms of amplitude, frequency, phase, or digital code. This set of characteristics is called the output signal format. Therefore, a sensor has input properties (of any kind) and electrical output properties.
3.2.1 IR LEDs
A light-emitting diode (LED) is a semiconductor diode that emits incoherent narrow-spectrum light when electrically biased in the forward direction of the p-n junction. The basic function of the emitter is to convert electricity into light. It works on the principle of recombination of the electron-hole pair. As in the conduction band of a diode, electrons are the majority carrier and in the valence band, holes are majority carrier. So when an electron from a conduction band recombines with a hole
28
of valance band, some amount of energy is released and this energy is in the form of light. The amount of energy released is depends upon the forbidden energy gap. The color of the emitted light depends on the composition and condition of the semiconducting material used, and can be infrared (IR LED), visible, or nearultraviolet. LEDs are often used as small indicator lights on electronic devices and increasingly in higher power applications such as flashlights and area lighting. The IR Led has two legs, the leg which is longer is positive and other leg is negative as seen in figure 3.4 below.
3.2.2 Photodiodes
The photodiode is a p-n junction diode which is connected in reverse bias direction. The basic function of the detector is to convert light into electricity. As its name implies that it works effectively only when the certain number of photon or certain amount of light falls on it. When there is no fall of light on the photodiode it has an infinite resistance and act as an open switch but as the light starts falling on the photodiode, the resistance becomes low and when the full intensity of light fall on the photodiode then its resistance becomes zero and it starts act like a closed switch. The IR receiver shows in figure 3.5 below: [6]
29
A line sensor in its simplest form is a sensor capable of detecting a contrast between adjacent surfaces, such as difference in color. The theory of operation is simple when light shines on a white surface; most of the incoming light is reflected away from the surface. In contrast, most of the incoming light is
30
absorbed if the surface is black. Therefore, by shining light on a surface and having a sensor to detect the amount of light that is reflected, a contrast between black and white surfaces can be detected. Figure 3.7 shows an illustration of the basics just covered.
By making use the reflecting light from the black and white surfaces, the objective of tracking a black line is simple and can be achieved by using the appropriate sensors. The sensors array consists of two IR transmitters (Tx) and receivers (Rx) pasted on the front of the car as shown in figure 3.8 below:
31
En1 & En2 are given logic 1 from microcontroller or give 5V from outside and are used to activate/deactivate one half of the H-bridge.
V is the voltage supply to the motor(s). Vcc is the logic 1 or 5V. GND There are two DC motors front motor for front wheels and rear motor for
rear wheels. The motors receive a signal from the microcontroller through the motor driver. The dc motors rotation depends on the polarity or the current
32
direction, thats why the motor driver is used. It has four available inputs and outputs, only two outputs are needed for each motor. The inputs of L239D are connected to the microcontroller ports (D1, D2, D3), D1 and D2 are connected to (PIN1, PIN2) respectively to drive the front motor bidirectional, D3 connected to(PIN4) to drive the rear motor. When the microcontroller sends a signal to the motor driver, this signal actually enables one of the outputs of the motor driver, so L293D allows the motor to rotate in the desired direction. The rear motor only goes forward tracing the line, so it doesnt need to run bidirectional and that is the reason of not connecting PIN5 with the microcontroller. The L293D-DCmotor-Interface can be represented in figure 3.9 below bellow:
33
Table 3.2 Truth table of L293D IN1 1 0 1 1 IN2 1 1 0 1 Description Motor stops or breaks Motor runs anti-clock wise Motor runs clockwise Motor stops or breaks
For the above truth table, the enable (EN) has to be set (1).
34
35
37
38
Start
FLASH THE TWO YELLOW LEDs TEN TIMES (STANDBY MODE)
NO
YES
RUN THE REAR MOTOR AND THE TWO YELLOW LEDs
NO
YES
ROTATE FRONT MOTOR TO THE RIGHT & RUN REAR MOTOR + RIGHT BLUE LED
2
39
1
BOHT R. IR & L. IR OUTSIDE THE PATH
NO
YES
STOP ALL MOTORS AND LIGHT RED LED
L. IR DETECTS LINE & R. IR OUT OF LINE?
NO
YES
ROTATE FRONT MOTOR TO THE LEFT & RUN REAR MOTOR + LEFT BLUE LED
2
Figure 4.2 Flowchart of the possible cases
40
41
Port
I/O
connected to L293(IN 1) L293(IN 2) L293(IN 3) Red LED Left led Right led Forward yellow right LED Forward yellow left LED Right IR detector
Runs when Power is on Power is on Power is on The car got out of path The wheel turn left The wheel turn right At standby mode
Portb.3 O/P
At standby mode Always to detect the path Always to detect the path
30 msec
Porta.1
I/P
Porta.0
I/P
Left IR detector
42
Portb.3 = 0 Waitms 30 Next Config Adc = Single , Prescaler = 8 , Reference = Internal Enable Interrupts Start Adc Part (a) of the code The next part started with holding a word in the memory for two variables; Right1 and Left1, the first variable refers port A1, and the second refers to port A0, which are the right and the left IR transmitter connected to the ports mentioned respectively. The while-loop shows that when both right and left IR detectors at the same time detect less than 300 (ADC value) or about (+ 2.5v), then the microcontroller will give a signal (+ 5v) to the red LED that is connected to port C0. In other words, when the car is completely out of path, only the red LED will light up. Dim Left1 As Word Dim Right1 As Word Dim A As Byte M: Do Left1 = Getadc(0) Right1 = Getadc(1) While Right1 < 300 And Left1 < 300 Left1 = Getadc(0) Right1 = Getadc(1) Portc.0 = 1 Portb.2 = 0 Portb.3 = 0 Portd.0 = 0 Portd.1 = 0 Portd.2 = 0 Portd.3 = 0 Waitms 300 Wend Portc.0 = 0
44
Part (b) Part ( c) is an If condition used to represent that when the left Rx read less than 400(digitally) then the program jump to loop defined as L, and if the right Rx read less than 400(digitally) then the program jump to loop defined as R. In case the conditions an above are not confirmed the port B2=1and port B3=1 which are connected to the forward yellow LEDs and a port D1=1, which connected to (input1) of the L293driver meaning that the rear motor is running, and all other ports are 0. To control the speed of the rear motor for the specific design, the micro sends signal (1) for 5ms and stop (0) for16ms. If Left1 < 400 Then Gosub L End If If Right1 < 400 Then Gosub R End If Portb.2 = 1 Portb.3 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 0 Portd.3 = 0 Waitms 5 Portd.0 = 0 Portd.1 = 0 Portd.2 = 0 Portd.3 = 0 Waitms 16 Loop End Part (c) In part (d) the loop L and R which mentioned in previous conditions are defined, in loop L port B0=1 which mean the left led flashes, port D1=1 and port
45
D3=1 to enable the L293D to rotate the forward motor to the right because the left receiver is out of path and need to rotate right to be in the path. For the loop R port B1=1 meaning that the right led flashes, port D (1 and 2) equal 1to enable the L293D to rotate the front motor to the left because the right receiver is out of the path and need to rotate left to stay on the track. In both loop L and R the rear motor runs for 5ms and stops for 16ms to drive the rear motor by specific speed. L: For A = 1 To 3 Portb.0 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 0 Portd.3 = 1 Waitms 5 Portb.0 = 0 Portd.0 = 0 Portd.1 = 0 Portd.2 = 0 Portd.3 = 1 Waitms 16 Next Gosub M R: For A = 1 To 3 Portb.1 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 0 Portd.3 = 1 Waitms 16 Next Gosub M R: For A = 1 To 3
46
Portb.1 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 1 Portd.3 = 0 Waitms 5 Portb.1 = 0 Portd.0 = 0 Portd.1 = 0 Portd.2 = 1 Portd.3 = 0 Waitms 16 Next Gosub M Part (d)
47
Else if the car got out of the path to the right, in case that the path is curved to the left of the car, then the right IR transmitter will send an ADC value more than 300 (more than + 2.5v) to the Porta.0, by the time the other left IR still in the path with an ADC value of more than 300, then the microcontroller will send a signal to the L293D to enable the output1 and output2 that control the front motor in order to rotate the wheels of the car to the left, taking the car back to the path that is in the left. Another two signals will be sent, one to the L293D for enabling the rear motor while the car is turning left back to the path, and other is sent to the left blue LED to flash while the car turning left. When the car got out of the path, but this time to the left in case that the black live is curved to the right, then the left IR transmitter will send an ADC value more than 300 to the Port1.1 of the microcontroller, by the time that the right IR still located in the right path, then the microcontroller will send three signals, one to the L293D to enable the output3 and output4 which control the rear motor in order to rotate the wheel of the car to the right,. The second signal will also be sent to the L293D to run the rear motor to go forward, and the other signal is for flashing the blue right LED. The last case, when the car is completely inside of the path (the black line), then, both of the IR transmitters will detect the line, and send this signal to the microcontroller, then, only the rear motor will be active by enabling the its two outputs of the L293D. And the two forward yellow LEDs will light as long as the car is in the right way.
48
CAPTER FIVE
5.1 Conclusion
A follower scheme has been done which mean that this van can run forward, turn right and turn left. (l293D) represents an interface unit with a microcontroller to control the movements of the two motors. BASCOM-AVR compiler is an easy language compared with the other high level language.
5.2 Recommendations
Smart versions of followers can be used in many life applications. Obstacle detectors can be add so that follower to stop when something crossover its way. The follower can be modifying to avoid things that might face it and return to right path.
Embedded magnets path can be used instead of drown line on
the surface, when its supplied with magnetic detectors, the follower follows the magnets path. The code can be modified and array of sensors can be increased to satisfy a specific cases(sensitivity) and when the follower totally gets out of the right path the control program command the to reverse its movement to return to the course.
49
References
[1]- Dhananjay V.Gadre, Programming and customizing the AVR microcontroller McGraw-Hill 2001. [2]- Steven F.Barrett, Daniel J.Pack, Atmel AVR microcontroller primer Programming and Interfacing, Morgan & Claypool 2008. [3]-Muhammad Ali Mazidi, Sarmad Naimi, Sepeher Naimi, The AVR microcontroller and embedded system using assembly and C, Prentice hall. [4]-Jan Axelson, The microcontroller idea book, Lakeview Research 1997. [5]- Priyank Patill, , K.J.Somaiya,Line following robot, Mumbai India. [6]- Jacob Fraden, Hand book of modern sensors (third edition), San Diego California [7]-Krishna Nand Gupta and others, Motor driver L293D. [8]- Programming in BASCOM-AVR, David Swinscoe www.davidswinscoe.com [9]-http://www.atmel.com/products/avr/ , may 2011 [10]- ATmega16 data sheet,Atmel Corporation 2003.
50
Appendices
The control program
$regfile = "M16DEF.DAT" $crystal = 10000000 Config Portd.0 = Output Config Portd.1 = Output Config Portd.2 = Output Config Portd.3 = Output Config Portc.0 = Output Config Portb.0 = Output Config Portb.1 = Output Config Portb.2 = Output Config Portb.3 = Output Dim Y As Byte For Y = 1 To 10 Portb.2 = 1 Portb.3 = 1 Waitms 30 Portb.2 = 0 Portb.3 = 0 Waitms 30 Next Config Adc = Single , Prescaler = 8 , Reference = Internal Enable Interrupts Start Adc Dim Left1 As Word Dim Right1 As Word Dim A As Byte M: Do Left1 = Getadc(0) Right1 = Getadc(1) While Right1 < 300 And Left1 < 300 Left1 = Getadc(0) Right1 = Getadc(1) Portc.0 = 1
51
Portb.2 = 0 Portb.3 = 0 Portd.0 = 0 Portd.1 = 0 Portd.2 = 0 Portd.3 = 0 Waitms 300 Wend Portc.0 = 0 If Left1 < 400 Then Gosub L End If If Right1 < 400 Then Gosub R End If Portb.2 = 1 Portb.3 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 0 Portd.3 = 0 Waitms 5 Portd.0 = 0 Portd.1 = 0 Portd.2 = 0 Portd.3 = 0 Waitms 16 Loop End L: For A = 1 To 3 Portb.0 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 0 Portd.3 = 1 Waitms 5 Portb.0 = 0 Portd.0 = 0
52
Portd.1 = 0 Portd.2 = 0 Portd.3 = 1 Waitms 16 Next Gosub M R: For A = 1 To 3 Portb.1 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 0 Portd.3 = 1 Waitms 16 Next Gosub M R: For A = 1 To 3 Portb.1 = 1 Portd.0 = 0 Portd.1 = 1 Portd.2 = 1 Portd.3 = 0 Waitms 5 Portb.1 = 0 Portd.0 = 0 Portd.1 = 0 Portd.2 = 1 Portd.3 = 0 Waitms 16 Next Gosub M
53
54