mini proj_UNIKLBMI
-
Upload
hisham-mat-hussin -
Category
Documents
-
view
12 -
download
1
Transcript of mini proj_UNIKLBMI
Universiti Kuala Lumpur British Malaysian Institute Micro-Controller Practical Assignment 2 Prepared to: Mr. Hisham Mat Hussin BERSERKER BUG
Prepared by:
EIZUDDIN BIN MOHAMAD 14211030279
MD. SHARIZAL BIN MD. SANI 14211030298
DE41
Summary
For this assignment, the main objective is to produce a mini project that applies the
application of software and hardware interfacing of Atmel 8052 microcontroller. The
software was developed using the freeware Buscom. All command and program
instruction language were based on the 8052 specification. The hardware includes the
mechanical application and triggering function in order to interact with the
microcontroller. To combine the software and hardware application a robot ‘Berserker
Bug’ was created with interfacing element that response to a lighting, touching and
sound sensor. The mechanical part of ‘Berserker Bug’ mainly support by Lego
Mindstorm. A pair of 9V motors assembled with 4 wheels and touch sensor complete the
hardware construction. The sensor circuit like light and sound function as a triggering
element to activate the microcontroller to decide the robot behavior by software
application. The construction of software was developed and tested with simple
triggering and basic output, but for the hardware the construction was quite complex due
to small current by microcontroller output to drive the motors and the circuit. Several
options of electronic circuit design were produce and analyzed to fulfill the
microcontroller output drive characteristic. All software and hardware development shall
be discussed separately and the attachment will include the Lego Mindstrom
construction. The mini project does expose our knowledge to the real microcontroller
interfacing application and widens our view on producing a practical robot.
SOFTWRE DEVELOPMENT
Software Development
Introduction (Overall Program) Connection Method
1. The concept use to trigger the motor and buzzer is by applying inverse
connection where we have to inverse the polarity of the device from LOW to
HIGH and HIGH to LOW (terminal of source – VCC & GND). The reason to use
the concept reverse is :
The output current from the microcontroller is too low (150 mA)
The hardware (motor and buzzer) require high current to operate
(minimum 250 mA)
Interrupts
2. The program uses two types of Interrupts which is INT0 and INT1. In the program
INT0 is assigned by ISR named ‘Den’ and INT1 is assigned named ‘Sha’. Since
both of the interrupts is active LOW (by hardware) we have to set +5v to the
interrupt, to enable the ISR the port 3 pin 2 (INT0) and pin 3 (INT1) require GND
source. The interrupt program (Using BASCOM) is enable by:
Enable Interrupts 'Initialize Interrupts
Enable Int0 'Set Interrupt 0
On Int0 Den Nosave
Enable Int1 'set Interrupt 1
On Int1 Sha Nosave
Den: ‘ISR for INT0’
Return
Sha: ‘ISR for INT1’
Return
Buzzer Sound
3. Sound- By using BASCOM programming technique, we can assigned the sound
directly to the port with duration and frequency. The duration limit is from 1 to
32000, for example: if we want to set port 2 pin 4 is the output pin and the
duration is 10 and the frequency is 5 the instruction will be:
Sound P2.4 , 10 , 5
4. Moving Data
Since we use the reverse concept, all output must be set to LOW. The instruction
to move the data to the port is:
Mov p2, #h' 3f
Where the value of port 2 now is 3F (in Hex) 0011 1111 (in binary) where pin 6
and 7 will be LOW, but the output translate the code to be high for pin 6 and 7
due to low current condition.
5. Delay / Timer
In order to set the motor to run in a few seconds, we have to set the timer / delay
by declare it in the program. For example if we want to set the delay in 2 second
we just defined as:
Wait 5 ‘ Delay to 5 seconds
And if we want to set the time in millisecond we just defined:
Waitms 150 ‘Delay to 150 millisecond
Main Program Flowchart Operation
Flow chart 1
By referring to Flow chart 1, the main program start declare ‘There’ as the main program
routine. The program begin with a clapping hand and first line that the programs do is
sound, which is by using buzzer at port 2 pin 4. After the sound is executed both of the
motor will move forward ( 3FH ) for 2 seconds. The motor then will turn to left for 5
seconds. After that, it will turn right and left for 4 times around 250 milliseconds.
The motor then move forward again for 2 seconds and turn right for 5 seconds. Then
starts to move right to left again for around 250 milliseconds, after that the sound or the
buzzer on again and the program will start looping continuously. The main program can
be stop either by:
Clapping hands (cutoff the VCC supply)
Activate INT0 ISR
Activate INT1 ISR
Interrupt 0 Service Routine (INT0 - ISR)
Flow chart 2
The interrupt 0 (INT0) is assigned by ISR named Den, where to activate it we have to
give active low to pin 12. The ISR routine can be referred to the flow chart 2 the ISR
starts by on the buzzer (port 2 pin 4) and then the motor start to move left and right for 4
times around 150 milliseconds. After that the buzzer is on again and the ISR end.
Interrupt 1 Service Routine (INT1 - ISR)
Flow Chart 3
Interrupt 1 basically similar to Interrupt 0 which is to activate it we have to give active
LOW to pin 13. For INT1 the ISR named Sha. The ISR Sha starts with sound or buzzer
on and executes the motor to turn left for 5 seconds and turn right for 5 seconds. After
that the buzzer is ON again before the program ends.
The BASCOM Program Instruction Code
Enable Interrupts 'Initialize Interrupts
Enable Int0 'Set Interrupt 0 On Int0 Den Nosave Enable Int1 'set Interrupt 1 On Int1 Sha Nosave There: 'start main program Sound P2.4 , 10 , 5 'Buzzer on Waitms 150 'Delay for 150 millisecond Sound P2.4 , 1000 , 75 Waitms 250 Sound P2.4 , 10000 , 600 Waitms 150 Sound P2.4 , 32000 , 300 Waitms 250 Mov p2,#h'3f 'Motor Forward Wait 2 'Delay for 2 second mov p2,#h'ff 'stop motor mov p2,#h'bf 'Motor Turn left Wait 5 'Delay for 5 second mov p2,#h'ff 'stop motor mov p2,#h'bf 'Motor Turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond Mov p2,#h'bf 'Motor turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond mov p2,#h'bf 'Motor turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond Mov p2,#h'bf 'Motor turn left Waitms 250 'Delay for 250 millisecondmov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 milliseco Mov p2,#h'3f 'Motor Forward Wait 2 'Delay for 2 second mov p2,#h'00 'stop motor mov p2,#h'7f 'Motor turn right Wait 5 'Delay for 5 second mov p2,#h'ff 'stop motor
mov p2,#h'bf 'Motor Turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond Mov p2,#h'bf 'Motor Turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond mov p2,#h'bf 'Motor Turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond Mov p2,#h'bf 'Motor Turn left Waitms 250 'Delay for 250 millisecond mov p2,#h'7f 'Motor turn right Waitms 250 'Delay for 250 millisecond mov p2,#h'ff 'stop motor Sound P2.4 , 770 , 900 'Buzzer On Waitms 150 'delay for 150 millisecond mov p2,#h'ff 'Buzzer Off / clear port 2 Goto There 'Return back to There Den: 'ISR (Den) Interrupt 0 (INT0) Sound P2.4 , 1000 , 15 'Buzzer On Waitms 150 Sound P2.4 , 500 , 900 Waitms 150 Sound P2.4 , 100 , 600 Waitms 150 Sound P2.4 , 770 , 15 Waitms 150 mov p2,#h'bf 'Motor Turn left Waitms 150 'Delay for 150 millisecond mov p2,#h'7f 'Motor turn right Waitms 150 'Delay for 150 millisecond Mov p2,#h'bf 'Motor Turn left Waitms 150 'Delay for 150 millisecond mov p2,#h'7f 'Motor turn right Waitms 150 'Delay for 150 millisecond mov p2,#h'bf 'Motor Turn left Waitms 150 'Delay for 150 millisecond mov p2,#h'7f 'Motor turn right Waitms 150 'Delay for 150 millisecond Mov p2,#h'bf 'Motor Turn left
Waitms 150 'Delay for 150 millisecond mov p2,#h'7f 'Motor turn right Waitms 150 'Delay for 150 millisecond Sound P2.4 , 770 , 300 'Buzzer On Waitms 250 'Delay for 250 millisecond mov p2,#h'ff 'Clear Port 2 (Buzzer Off Return Sha: 'ISR (Sha0 Interrupt 1 Sound P2.4 , 1000 , 5 'Buzzer On Waitms 150 Sound P2.4 , 1000 , 50 Waitms 150 Sound P2.4 , 1000 , 500 Waitms 150 Sound P2.4 , 1000 , 5000 Waitms 150 mov p2,#h'7f 'Motor turn right Wait 5 'Delay for 5 second mov p2,h'bf 'Motor Turn left Wait 5 'Delay for 5 second Sound P2.4 , 1000 , 10 'Buzzer On mov p2,h'ff 'Clear Port 2 Return End
HARDWARE
CONSTRUCTION
a) Atmel 8052
The first part of Berserker Bug is Atmel 8052 which is the brain of the robot.
Circuit Description:
The AT89S8252 is a low-power, high-
performance CMOS 8-bit microcomputer with 8K bytes of downloadable Flash
programmable and erasable read only memory and 2K bytes of EEPROM. The device is
manufactured using Atmel’s high-density nonvolatile memory technology and is
compatible with the industry- standard 80C51 instruction set and pinout. The on-chip
downloadable Flash allows the program memory to be reprogrammed in-system through
an SPI serial interface or by a conventional nonvolatile memory programmer. By
combining a versatile 8-bit CPU with downloadable Flash on a monolithic chip, the Atmel
AT89S8252 is a powerful microcomputer which provides a highly-flexible and cost-
effective solution to many embedded control applications.
The AT89S8252 provides the following standard features: 8K bytes of downloadable
Flash, 2K bytes of EEPROM, 256 bytes of RAM, 32 I/O lines, programmable watchdog
timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt
architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition,
the AT89S8252 is designed with static logic for operation down to zero frequency and
supports two software selectable power saving modes.
The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and
interrupt system to continue functioning. The Power-down mode saves the RAM
contents but freezes the oscillator, disabling all other chip functions until the next
interrupt or hardware reset.
The downloadable Flash can be changed a single byte at a time and is accessible
through the SPI serial interface. Holding RESET active forces the SPI bus into a serial
programming interface and allows the program memory to be written to or read from
unless Lock Bit 2 has been activated.
Atmel 8052 Application
For ‘Berserker Bug’, there are other 3 circuits that interface directly with the
microcontroller to determine the robot behaviour. Diagram below shows the
microcontroller parts that connected with external circuit:
PORT 2 I/O (pin 7; pin 6; pin 4) PORT 3 INT0 & INT1( pin 2; pin 3 )
Vcc
PORT2 was programmed to be output port. For pin 7 the left motor of the robot was
connected and pin 6 is for the right motor. Pin 6 and 7 will define when the motor
operate to move straight (both motor ON-activate pin 6&7), to turn left (only right motor
ON-activate pin 6) and to turn right (only left motor ON-activate pin 7). For pin-4 a
buzzer was connected to produce the output programmed sound following the
sequence.
PORT 3 was programmed for the interrupt application which is INT0 and INT1 where
both of the pin is active low. INT0 was connected with a limit switch that will activate
when the robot hit any obstacle on its path, when this happened the limit switch will be
push and activate the INT0 by sending a low signal to activate the Interrupt Service
Routine (ISR). For INT1, the light sensor circuit was connected. The LDR was used as
the sensor to measure the surround light intensity of the robot. When the robot move to
an area that have low light intensity the circuit will trigger the INT1 by sending a low
signal, at this point the ISR will activate to run.
The VCC input pin of the microcontroller was connected to the sound sensor circuit. The
microcontroller will connected to its source only when the sound sensor circuit activates
by a clapping sound and the source can be disconnected by clapping one more time
again.
b) Sound Sensor Circuit
The second part of the Berserker Bug is the sounds activate circuit.
Circuit Description:
This sound actuated switch enable the ON/ OFF control of any electrical appliances with
maximum load of 300W. It can be trigger by a clapping sound of our hands. The circuit
incorporates two active filters which is high pass and band pass filters with
sensitivity of 5KHz, so it may responds only to hand-clapping sound while ignoring other
such as spoken voices. A condenser microphone was connected to the circuit as the
input device to detect the sound. The relay (9V / 6V) is used as the output device to
trigger the external circuit (8052 Vcc). The whole circuit is generated by a 9V battery to
operate.
Sound Circuit Application
The Berserker Bug depends to the sound sensor circuit. The robot only activate when
the sound circuit is triggered by a clapping sound. The relay was used as a main switch
to ON and OFF the Atmel 8052 microcontroller. The circuit below shows the connection.
8052 Vcc ; battery 9V ; Relay (Normally Open; Common; Normally Close)
The relay output (common & normally open) was connected with a battery source on the
positive terminal. The negative terminal was directly connected to the microcontroller
source. When the sound circuit activated by hand clapping, the relay will toggle from
normally close (NC) to normally open (NO), thus the positive supply get through to the
microcontroller and start the robot operation. When the sound circuits detect another
clapping sound the relay will return to normally close (NC) and there will be no supply to
microcontroller. At this point the robot will stop and no longer functioning.
Each time the microcontroller activate it will begin the operation from the starting origin
program counter and it will continuously running until the ISR occur or the sound circuit
trigger by a clapping sound.
c) The Buzzer & Touch Sensor Circuit
The third part of Berserker Bug is the Buzzer and the touch sensor circuit.
Circuit Description:
The Buzzer is a basic sound activator that produces a sound when a voltage supply is
given. It has 2 basic terminal of positive and negative where it will be connected to the
microcontroller and active to function as programmed.
The touch sensor operates based on a limit switch operation that connected to a relay
for a switching selection of interrupt triggering. The touch sensor was connected to the
front nose of the robot where it will be trigger when the robot move toward an obstacle
such as wall or furniture.
d)The Light Sensor (LDR) Circuit.
The fourth part of Berserker Bug is the light sensor circuits that user the LDR.
Circuit Description:
The main part of this circuit is the light sensor (LDR). The LDR function as a device to
produce a resistance based on the light intensity. If the light intensity is high, the
resistance is low thus allowing the current to flow to trigger the relay. When the surround
light is dim, the resistance from the LDR will increase and blocking the current to trigger
the relay. The circuit also provides a variable resistance to control the LDR sensitivity.
The sensor control the relay operation, once the supply is provided (9V battery), the
relay switching will function based on the light sensor. The output connection of relay
(common, normally close, normally open) shall be used for the triggering application of
external circuit.
Light Sensor Circuit Application
For Berserker Bug, the light sensor circuits play a role as an interrupt trigger which
applies for INT1 (port 3, pin 3). The construction was based on the relay output
connection. As we know, the INT1 is an active low pin, and it requires a GND connection
to activate the ISR and 5V, VCC connection for not interrupt. At this point the relay was
used for both GND and VCC connection to the INT1. The common (C) pin from relay
was connected to INT1, while the normally close (NC) is connected to VCC and normally
open (NO) connected to GND. The common will send signal to INT1 based on the
position of NC or NO. When the light sensor is in high light intensity surrounding the
relay may not be trigger and stay at NC position thus supply common a VCC and when
dim light detected by LDR the relay provide GND to common to activate the ISR at INT1.
Figure below show the construction:
LDR sensitivity adjustment ; LDR ; Relay ( common-INT1 ; NC-GND ; NO-VCC)
Recommendation
1. Bi-direction movement (forward & reverse)
Currently ‘Berserker Bug’ movement is limited to forward left and right. The reverse
movement can simply be added by programming another 2 pin from the output (instead
of port 2 pin 6 & 7). Each motor shall be control by 2 pin and each pin connected to one
relay. The relay function is to determine the motor polarity (VCC or GND) that move the
motor forward or reverse. The relay my change it position (normally close or normally
open) to send the common a VCC or GND signal to trigger the motor. Surely only one of
it will be VCC and the other pin is GND which determine the motor direction.
2. Multi-direction movement.
With bi-directional movement ability, we may expand the list of robot movement or we
can say to make it as a dancing robot with special movement for the interrupt program
(ISR). The creativity may define the right movement as a bug robot to respond with its
surrounding with the aid of sensors and interrupts application.
3. Line Tracking Robot
The INT1 currently connected with a light sensor LDR circuit. By adding a super bright
LED which have the right angle reflection to the LDR, it can become a line tracking
device. Simply point the light sensor and the LED to a dark line surface with a bright
(white) background, then program the robot to move forward. The interrupt may occur
when the LDR triggered by the LED. This will happen when the robot moves out of the
dark line range. The dark line absorbs the brightness of the LED to reach LDR, but when
it out of track, the white surface reflexes the light to trigger the LDR. At this point we may
create the ISR program to move left or right until it return back to the dark line.
Conclusion
The microcontroller mini project does expose the student to the software and hardware
architecture that blends together for the interfacing purpose. The software development
may express the right pin to produce the output in the manner of proper instruction that
can be understood by the microcontroller. To identify the process it require the
application of BASCOM to identify whether the written language is acceptable to be
execute before sending it through the dongle. The sound by buzzer, data movement,
delay and interrupt service routine describe a complicated programming but BASCOM
translate it in a short programming language that easy to implement. But when come to
hardware, the reality reflexes the actual application of the software where mainly the
output from the microcontroller port unable to support the load. Analysis and
troubleshooting does help on the circuit construction to overcome the problem thus
require adjustment on the software. Overall, the project did introduce us to the interface
knowledge with a microcontroller and deep analysis on troubleshooting and
construction. Due to the lack of time, simple applications were implemented and further
recommendations were listed to produce a practical robot in future.