Ultrasonic Sensor and Interrupt

Hello,
I need to use ultrasonic sensors on a project, but I need a better precision, like in centimeters. I use EasyC Pro with hand-written C code. Is there any function in WPILib to get this?
I haven’t found one, so I am trying to remake the ultrasonic functions using interrupt handlers. I successfully used interrupt handlers with a limit switch, but it seems like the ultrasonic sensor never changes its output: I get a rising edge at the begginning, but shouldn’t I get a rising edge every time I set the digital output to 1, and a falling edge when the sound comes back?
Could anyone please send me some source code using interrupt to handle a ultrasonic sensor, or give advice on where is my error on handling the sensors?

Thank you in advance,
Renato.

No, the ultrasonic returns goes high when it hears the return pulse.

Make it yourself:
Send a Pulse Return and Record the Current Time.
Listen for the Pulse when the return Goes high get the time.
Compare and do the maths.

If you want to write your own interrupt handler you can do that in easyC, using some of the MCC18 libraries.

We have been asked to offer a higher resolution output for the ultrasonic, and it’s on the feature list for future upgrades.

Thank you for the quick answer.
Do I need to wait for the falling edge to start recording time or can I watch just for the rising edge, and start recording when I set the digital output? (e.g., does the sensor send the pulse as soon as I ask it to?)

I would start counting as soon as you send the pin high, but I don’t know how long you should leave it high to get a good ping. You’d have to ask Vex about that.

Again, thank you for your great help :slight_smile:
I will test it again as soon as I can, then I post the results here.