Page 1 of 1

How to measure pulse width on an HC-SR04

Posted: Sun May 13, 2018 7:31 pm
by DTC1957
Hi

I would like to use an HC-SR04 to measure distances. The way that device works is to return a pulse whose length is proportional to the distance being measured (ultrasonic reflection). I saw that there is a way to do this on Arduino (pulseIn - see http://www.instructables.com/id/Distanc ... a-NodeMCU/), but I am not using Arduino software, rather the native ESP IDF. How can I code this in C?. Please bear with me as I am new to this chip and its environment.

Many thanks

David

Re: How to measure pulse width on an HC-SR04

Posted: Mon May 14, 2018 6:30 am
by ESP_Sprite
I'm pretty sure you can use the RMT peripheral for that. The MCPWM block may also have a capture mode that allows you to capture pulse lengths, but I'm not 100% sure on that.

Re: How to measure pulse width on an HC-SR04

Posted: Mon May 14, 2018 12:44 pm
by papaluna
Be careful. The ESP32 allows approx max 3.3V DC on its input pins. But the operating voltage of that unit is 5V DC; I asssume it also emits max 5V DC on the output pin(s).

Re: How to measure pulse width on an HC-SR04

Posted: Tue Oct 16, 2018 4:08 am
by Ritesh
Hi,

Did you try with PCNT Interface to get exact accuracy about pulse width which you want to achieve?

We have also same requirement for one of our product based on ESP32