| Sonar and IR Ranging with the Atmel AT90S8515 Last Modified: 2006-11-16 | | |
| Acroname Robotics | PDF webpage version | ||
| Introduction The Atmel Corporation makes the popular AVR family of microcontollers. These devices have an 8-bit RISC core and Flash memory for in-system programming. Two example programs for the AT90S8515 microcontroller are listed below. They show how to use some common ranging devices. Both programs were developed with the BascomAVR Basic compiler . Source Code - AT90S8515 with SRF04 The following program shows how to use a Devantech SRF04 Ultrasonic Rangefinder with the AT90S8515. Pin connection info may be found in the comments and code. The user must design any additional circuitry that may be needed. $sim
'REMOVE the above command for the real program !!
'$sim is used for faster simulation
'**************************************************
' filename: atSRF04.bas
' Devantech SRF04 Ultrasonic Range Detector
' Test example program for Atmel 90S8515 MCU.
' By Earl Bollinger Jan 21, 2002
' earlwbollinger@attbi.com
'*************************************************
'LCD to AVR 8515 pinouts
'1 GND
'2 VCC +5
'3 Contrast 10k from Vcc to Gnd wiper in between
'4 RS PortD.2
'5 RW Gnd
'6 E PortD.3
'7 D0 Gnd
'8 D1 Gnd
'9 D2 Gnd
'10 D3 Gnd
'11 D4 PortD.4
'12 D5 PortD.5
'13 D6 PortD.6
'14 D7 PortD.7
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 =
Portd.7 , E = Portd.3 , Rs = Portd.2
Config Lcd = 24 * 2 'configure lcd screen
Dim Dist As Word
Dim D As Word
D = 9 'cheap conversion factor for inches, cm's, whatever
'Devantech UltraSonic SRF04 Rangefinder pinout
' +5v supply
'Echo Output to Port A pin3
'Pulse trigger input to Port A pin2
'Do not use
'Ground
'Port A pin 2 for Pulse trigger output to device
'Port A pin 3 for echo input from device
Ddra = &B11011111
Porta.2 = 0
Dist = 0
Mainloop:
Cls
Waitms 400
Lcd "Sonar Range = "
Pulseout Porta , 2 , 20 'very sensitive to pulsewidth
Pulsein Dist , Pina , 3 , 1
Dist = Dist / D
Lcd Dist
Wait 1
Goto Mainloop
End
Source Code - AT90S8515 with GP2D02 The following program shows how to use a Sharp GP2D02 Infrared Ranger with the AT90S8515. Pin connection info may be found in the comments and code. The user must design any additional circuitry that may be needed. $sim
'REMOVE the above command for the real program !!
'$sim is used for faster simulation
'**************************************************
' filename: atGP2D02.bas
' Devantech Sharp Infrared GP2D02 Object Detector
' Test example program for Atmel 90S8515 MCU.
' By Earl Bollinger Jan 21, 2002
' earlwbollinger@attbi.com
'*************************************************
'LCD to AVR 8515 pinouts
'1 GND
'2 VCC +5
'3 Contrast 10k from Vcc to Gnd wiper in between
'4 RS PortD.2
'5 RW Gnd
'6 E PortD.3
'7 D0 Gnd
'8 D1 Gnd
'9 D2 Gnd
'10 D3 Gnd
'11 D4 PortD.4
'12 D5 PortD.5
'13 D6 PortD.6
'14 D7 PortD.7
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 =
Portd.7 , E = Portd.3 , Rs = Portd.2
Config Lcd = 24 * 2 'configure lcd screen
Dim X As Byte
Dim Dist As Byte
Dim D As Byte
X = 255
D = 10 'cheap conversion factor for inches, cm's or whatever
'Devantech Sharp GP2D02 Infrarwed Object Detector pinout
'pin 1 (black) Ground
'pin 2 (Green) Vin pulse input drive
'pin 3 (red) VCC +5v supply
'pin 4 (yellow) Vout serial data out
'Port A pin 0 yellow data input from IR device
'Port A pin 1 green output wire to IR device
Ddra = &B10111111
Porta.1 = 1
Dist = 25
X = 255
Mainloop:
Cls
Waitms 400
Lcd "Infrared Range = "
Porta.1 = 0
Waitms 70
Porta.1 = 1
Shiftin Pina.0 , Porta.1 , Dist
Dist = X - Dist
'Dist = Dist / D
Lcd Dist
Wait 1
Goto Mainloop
End
Comments Thanks go to Earl Bollinger for contributing these code examples. Revision History:
| |||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved. |