This code need some serious rewriting. Couple of years I wrote similar program for the 16F84A in the assembly.
At the first glimpse your frequency is not 40kHz. I suppose that you use 40kHz ultrasound transmiter/receiver pair. Your code transmits at ~ 8,7kHz.
Here is the flow how you should do this:
Code:
Init the PIC
|
|
Send ping (8 pulses at 40kHz) <---------+
Set timer1 to 0 |
| |
| |
Delay (see comment *) |
| |
| |
Check if pong received <--------+ |
| | |
+----- NO --------------+ |
| |
Calculate distance from time |
| |
| |
Display distance |
| |
| |
+------------------------------+
* Delay is used because first reply is not the correct one. Determine that based on experience.
aasief
Joined: 12 Feb 2009 Posts: 12 Location: cape town
Posted: Thu Apr 30, 2009 5:06 am
Thanx for ur response.
The delays I'm using are correct because I get 38.7 kHz out. I don't know why I do because looking at it, the PIC isn't doing what it's supposed to be doing.
I'm having a problem with capturing the pulse. I am getting a received pulse and I measured it and I get the correct time delay for distance measured.
I suspect that whatever is making my delays not work, is the same thing that's making my capture not work. Is there something wrong with my void isr loop ?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum