How to measure pulse width on an HC-SR04

DTC1957
Posts: 1
Joined: Sun May 13, 2018 7:19 pm

How to measure pulse width on an HC-SR04

Postby DTC1957 » Sun May 13, 2018 7:31 pm

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

ESP_Sprite
Posts: 8926
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Mon May 14, 2018 6:30 am

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.

papaluna
Posts: 50
Joined: Tue Jan 30, 2018 11:27 am

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

Postby papaluna » Mon May 14, 2018 12:44 pm

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).
--
Paul.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

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

Postby Ritesh » Tue Oct 16, 2018 4:08 am

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
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: Bing [Bot] and 122 guests