| SensComp to OOPic Example Last Modified: 2006-10-30 | | |
| Acroname Robotics | PDF webpage version | ||
| ![]() Introduction In this example, an OOPic microcontroller uses a 6500 Polaroid Ranging Module combined with a 7000 Series transducer to measures distances to obstacles. The OOPic tells the sonar module to emit a "ping" and measures the time it takes to receive an echo. It converts this time to a distance in inches. It turns on an LED when an object is within 6 feet. Circuit Schematic In the following schematic, the OOPic is powered by an external 9V battery. The sonar module has its own supply of four AA batteries (Ni-Cad, NiMH, or Alkaline). (Be sure the sonar module power supply and OOPic power supply share a common ground connection.) According to the Polaroid specs, The sonar module uses up to 2A during the transmit period and up to 100ma after the transmit period. Do not use the OOPic's onboard regulator to power the sonar module. The only additional components required for this circuit are a 4.7K pull-up resistor for the ECHO output from the sonar module and an LED with a 1K resistor as an object detection indicator. ![]() The test circuit also included a jumper wire between pin 3 and pin 15 of the socketed chip on the sonar board. The jumper eliminated some noise problems as described in the Polaroid Sonar Ranging Primer . Source Code This code uses BASIC syntax. It runs with version 3.0.1 of the OOPic compiler and version A.1.7 of the OOPic chip. ' polaroid-2.osc
' This program takes sonar readings every quarter second
' and turns on an LED when an object gets within 6 FT
dim w1 as new oWord
dim b6FT as new oDio1
sub main()
b6FT.IOLine=25
b6FT.Direction=cvOutput
b6FT.value=0
call initSonar
do
call readSonar
oopic.delay=25
if w1<72 then
b6FT.value=1
else
b6FT.value=0
end if
loop
end sub
'-----------------------------------
' operate timer if (INIT & ~ECHO)
' which is equivalent to ~(~INIT | ECHO)
'
dim echoTimer as new oTimer
dim tmrControl as new oGate(2)
dim INIT as new oDio1
dim ECHO as new oDio1
sub initSonar()
' sound travles 1 inch every 73.746us
' timer uses 625KHz clock frequency (5MHz/8)
' 625KHz is 1.6us per clock tick
' maximum range of sonar is 35ft (420 inches, 1067cm)
' distance of echo round trip is 420*2=840 inches
' 840 * 73.746us / 1.6us = 38716 ticks at max range
' 38716 / (420) = 92 --> conversion factor for inches
' 38716 / (1067) = 36 --> conversion factor for cm
echoTimer.ExtClock=cvOff
echoTimer.PreScale=3
INIT.IOLine=15
INIT.Direction=cvOutput
INIT.value=0
ECHO.IOLine=14
ECHO.Direction=cvInput
tmrControl.Input1.Link(INIT.value)
tmrControl.Input2.Link(ECHO.value)
tmrControl.InvertIn1=cvTrue
tmrControl.InvertOut=cvTrue
tmrControl.Output.Link(echoTimer.Operate)
tmrControl.Operate=cvTrue
end sub
sub readSonar()
echoTimer.value=0 ' clear old result
INIT.value=1 ' kick-off new reading
' wait until echo goes high again to return reading
' (also check for time-out condition)
while ((ECHO.value=0) and (echoTimer.value < 40000))
wend
INIT.value=0 ' reset sonar
w1=echoTimer.value/92 ' read time and convert units
end sub
This program also demonstrates an OOPic Virtual Circuit. The 6500 Polaroid Ranging Module has an INIT input and an ECHO output. Setting the INIT line to 1 (+5V) starts a sonar reading and causes the module to emit a "ping". The ECHO line goes high as soon as the module receives an echo. The interval between the INIT line going high and the ECHO line going high is the time for the ping to make a round trip from the module to an object and back again. To time this interval, a timer must run while INIT is high and ECHO is low. This logic can be implemented with an OOPic Virtual Circuit. However, this "and" logic must be converted to "or" logic. The following Boolean identity (using ~ to denote negation) does the trick: A and B = ~ (~A or ~B) Revision History:
| ||||
Related Links: | |||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2010 Acroname, Inc., Boulder, Colorado. All rights reserved. |