i am using PIC18F4550 with SRF04 sensor. I connect the Trigger pulse (output from pin) and Echo pulse (input to pin) with PIC pin 28(RD5) and 29(RD6). I need to supply a short 10uS pulse to the trigger input to start the ranging. The SRF04 will send out an 8 cycle burst of ultrasound at 40khz and raise its echo line high. It then listens for an echo, and as soon as it detects one it lowers the echo line again. The echo line is therefore a pulse whose width is proportional to the distance to the object. Now i am using
TRISD=0b01000000;
/** Trigger pulse***/
PORTDbits.RD5 = 1;
Delay1KTCYx(30); //delay for 20us
PORTDbits.RD5 = 0;
/**Echo pulse***/
PORTDbits.RD6 = 1;
What should i do next? How can i do the coding to measure the Echo pulse and put it back to PIC? I am using 1MHz internal clock for hardware PWM. Do i need to define another clock for the sensor?If yes, how many do i need? 1 for Trigger and 1 for Echo? Can i do it like If Echo pulse has 200us, send it back to PIC, PIC do somethings. How to write the code to let PIC know what pulse did Echo measure?
Thank you very much...Hope someone can give me a hand coz i stuck in this part for a long time.