View Full Version : SRF04 Ultrasonic Rangefinder Unresponsive
the401tauntaun
19-01-2008, 11:56
we are using the Devantech SRF04 Ultrasonic Rangefinder. (http://www.acroname.com/robotics/parts/R93-SRF04.html) We have sent a 5v pulse to the input pin, and verified this with a voltmeter. The power supply is working. We are not getting any feedback. The voltage from the "echo output" pin stays at zero. The code we are using to send this signal folows:
if(p1_sw_trig == 0)
{
rc_dig_out02 = 0;
}
else
{
rc_dig_out02 = 1;
}
We are reading the output from the rangefinder using both a voltmeter and printfs, and neither one shows any output. We expected a pulse at the falling edge of our signal, to signify that it was "listening" for echoes. Is there something obvious we are missing here? These rangefinders are a few years old, so it's possible (though unlikely) that they are just broken.
Steve_Alaniz
19-01-2008, 18:59
Hi I have one here... I don't think you'll see anything on the Voltmeter... the echo is VERY short and most Meters are not fast enough. If you have access to an Oscilloscope, you might see the missing pulse.
How are you using the Printf? Once again... since the output is a pulse, your best chance of detecting it, without actually timing it, is to change a variable to "1" on the positive edge and use and
if variable == 1 then ... printf some message like "Found"
geeknerd99
19-01-2008, 19:52
that is a very good idea. We had a printf running in the user_routines_fast of the default code, and basically I was hoping that it would catch it. I figured that it would show up, but maybe not, and I will definitely try doing a single printf. thanks! (btw, geeknerd = same team as tauntaun)
geeknerd99
19-01-2008, 20:38
tried it. It is now official that we are not gettting any feedback...
basicxman
19-01-2008, 20:43
i have an SRF04 but also an SRF08, way better!!! and not to mention its controlled by i2c also it has a built in light sensor (CdS cell)
tried it. It is now official that we are not gettting any feedback...
I'm still not totally convinced. As Steve pointed out, the return pulse is very short, and it's possible that the pulse is coming and going faster than even the fast loop can keep up with. To be totally sure, could you set it up as an interrupt, and then see if you ever trigger it?
geeknerd99
19-01-2008, 21:31
It says that if there is no "echo," it won't timeout until 18 ms have passed. I'm sure the fast routine loops faster than 18 ms.
how about something like this. It should fire a ~20us drive pulse and then listen on the echo line. The echo line should be asserted shortly after the sonar is fired and remain high until the first echo is detected -or- no echo and the line will drop in 36ms.
void ping()
{
unsigned int count;
char usec;
#define drive_pin rc_dig_in01
#define echo_pin rc_dig_in02
//~20uS pulse out
drive_pin = 1;
for (usec=20; --usec != 0; )
{
Nop();
Nop();
Nop();
Nop();
Nop();
}
drive_pin = 0;
//echo pulse should start shortly... timeout in ~20ms
count = 35500;
while(echo_pin == 0)
{
count++;
if (count == 0)
{
printf( "whoa, where'd the pulse go?\n");
return;
}
}
// ok, count the pulse width, count*2 is approx. uSec.
count = 0;
while (echo_pin != 1)
{
Nop(); Nop(); Nop(); Nop();
count++;
if (count == 0) break;
}
printf( "count = %d\n", count );
return;
}
You could always fire up Easy C and check the operation with a Known working code.
the401tauntaun
20-01-2008, 11:52
thanks a lot for your help! I will try this tuesday, when I can go back to the shop.:D
Or you could try my single-pin ultrasonic driver (http://www.chiefdelphi.com/forums/showthread.php?p=650374&#post650374).
-q
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.