I did a bunch of sonar stuff on a little robot years ago so was intrigued by your post. I haven't used the SRF05 but found a little info about it at http://www.robot-electronics.co.uk/htm/srf05tech.htm.
I'd ask a couple of questions based on what you're seeing:
When using PULSIN what is STATE set to? It looks like the response from the SRF05 is a high pulse so STATE has to be set to a "1". The manual says "If the pulse edge never happens or the width of the pulse is too great to measure, Var is set to zero.
What is the period of the PULSOUT command. The SRF05 doc says it needs to be a minimum of 10uS. That's a "1" for a 4MHz osc.
Are you doing anything between the trigger pulse (PULSOUT) and the PULSIN? If so you may be blowing right by the leading edge and the PIC is seeing nothing so it returns a zero in VAR.
The manual also says "The resolution of PULSIN is dependent on the oscillator grequency. If a 4MHz oscillator is used, the pulse width is returned in 10uS increments. (Paraphrase) "if 20Mhz pulse width is 2uS". OSC value has no effect on PULSIN. What is the width of the pulse coming back?
Answering those to start should get you on the right track...
Mike Tripoli
Bookmarks