1 Attachment(s)
Questions on ultrasonic distance finder
Hi,
I am at the begining of my project, actually I spent 1 week trying to make the LCD work properly so that tels me that I have a long way to go.
I am using a 16F627A (just because that's what I have on hand) if a better chip is suggested I can change it.
I have found a number of designs on the Web and read quite a few treads on forums, not that I want to reinvent the wheel but I would rather make my own design although I am taking some parts of interesting code here and there.
I do have a few questions to get me going. Based on the attached file, this is pretty much the simplest flowchart I could come up with and next to it is my understaning of what needs to happen as far as signal however I am no sure about the following details:
I presume that between T1 and T2 there has to be a burst of 40k times per second but I don't know how long it should last.
Ditto for the listening time between T3 and T4 and I guess the length of time it is listening is partly related to the range I can detect as long as I have enough transmitting and receiving power.
Please correct me if I am wrong but I figure I only want to start listening at T3 because I don't want the receiver to pickup vibrations from the transmiter since they are both on the same PCB.
What I have seen so far can take care of a ranges from a few centimeters to a few meters but I would like my range to be 6 cm to 6 meters so I understand I have to add some amplification at the receiver using op-amps and probably I have to increase power to the transmitter but how do I increase the Tx power? by raising the voltage?
and one last question (for now) when I detect an echo, do I calculate the time from T1 or T2?
I don't really need more than +/-20 cm of precision at 6 meters but I do need a minimum of 2 or 3 cm at 6 cm.
Here is where I am at with the code which basically I can see 40Khz on the scope and I know the LCD works. Like I said, I have a long way to go...
Code:
@ __config _XT_OSC & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
DEFINE OSC 4
TRISB = 0 ' Make PORTB all outputs
TRISA = %10 ' A0 = send burst, A1 = listen to echo
CMCON = 7 ' Disable comparator
FLAGS = 0
T1CON = %00000001 ' enable Timer1 prescaler 1:1
disTance var byte
ECHO var PORTA.1
Cycles var byte
LCD_DB4 VAR PORTB.0 ' Set port for 4 bits bus
LCD_DB5 VAR PORTB.1
LCD_DB6 VAR PORTB.2
LCD_DB7 VAR PORTB.3
LCD_RS VAR PORTB.5 ' Set RS bit port
LCD_E VAR PORTB.4 ' Set Enable bit port
LCD_Lines CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
LCD_DATAUS CON 50 ' Data delay time in us
LCD_COMMANDUS CON 2000 ' Command delay time in us
INCLUDE "LCD_AnyPin.pbp" ' Must go after LCD initialization
Pause 500: LCDOUT $FE,1: pause 250 ' clear screen and relax
LCDOUT $FE,$80,"Distance Finder"
goto start
asm
_Pulse
bsf PORTA,0 ; change to whatever port pin you have available
goto $+1 ; 2uS per GOTO $+1
goto $+1
goto $+1
goto $+1
goto $+1
bcf PORTA,0
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
decfsz _Cycles,f
goto _Pulse ; 25uS total for 40kHz carrier
RETLW 0 ; return to CALLing routine
ENDASM
Start:
' start timer ...
' send burst ...
Cycles = 8 ' number of carrier cycles to generate
CALL Pulse
PAUSEUS 24
' Listen for echo ...
' timed out...
' count number of time outs ...
' update display
gosub display_upd
GOTO start
Display_UPD:
LCDOUT $FE,$C0,"Distance = ",dec disTance," "
return
end
Try the SRF02 and solve a lot of your problems
Quote:
Originally Posted by
lilimike
I don't really need more than +/-20 cm of precision at 6 meters but I do need a minimum of 2 or 3 cm at 6 cm.
You could save yourself a lot of time, heartache and coding efforts by using one of the commercially available ultrasonic rangers that outputs a pre-calulated measurement (in inches or cm) down to 1 cm accuracy for less than $25. The one I have had a lot of success with is the SRF02 (see this URL: http://www.robotshop.com/srf02-ultra...m_campaign=jos. I have been very impressed with the performance of this device, but it does have one idiosyncracy when using an I2C bus to communicate with it.
If you decide to use this product, let me know and I can share some PBP code with you that has been pre-tested to work with the SRF02.
Don't overlook the mechanical aspects of these things...
I've used these sonic devices for a bunch of different projects. One thing that you have to pay attention to is the mechanical aspect of the transducers. They have to be rigidly fixed to the PCB and enclosure. Hanging off the pins as shown in your picture can cause all kinds of problems.
These things continue to "ring" after they've been pulsed. Many dampening circuits are available for electrically clamping the transducer. At the very least, wrap a small piece of felt around the body of the transducer, with a piece of dense foam around that (the dense weather stripping with an adhesive back is an ok place to start; buy it in a hardware store, something like 20' for $5.00). You can (and probably should) place a small plastic can around the transducer to make it more directional.
Years ago when my kids were younger we built a small robot for the science fair. It tooled around on its own through the crowd not bumping into anyone (people thought it was remote control). Anyway, we put the transducers in small plastic film cans with the pins sticking out the bottom. Line the film can with some thin felt (adhesive back - buy it at the craft store). Then take a piece of dense foam the same width as the transducer cut to length so that it wraps once and push it down around the transducer. We spaced the transducers so that they looked like "eyes". We also stuck some high brightness leds in there... you can experiment with the distance between the two. We used the full length of the film can but you can try cutting them back a little at a time until you get the response you want.
You will be amazed at the difference in performance.