I want to interface a HC-SR04 ultrasonic sensor with ESP32, and to do that, I need to measure the pulse width of the ultrasonic sensor to microsecond precision, and in Arduino there is pulseIn() function which do exactly that. The problem is that this is for a university course and Arduino libraries are banned, so I need to find a way to implement pulseIn in ESP-IDF.
The function need to measure the width of a single pulse, and a timeout if there is no pulse detected. I'm currently thinking to use RMT because there is this thread: viewtopic.php?t=1772 but somewhere I also read that MCPWM capture unit also works, and I'm not sure whether using timers and interrupts also work. In the Arduino pulseIn implementation I think they use assembly code to do cycle counting, but from multiple threads and google it seems that ESP32 assembly is proprietary. Is there any way to do this, or any working code?
How do I measure a pulse width with microsecond precision?
-
- Posts: 2
- Joined: Thu Oct 31, 2019 7:56 am
Re: How do I measure a pulse width with microsecond precision?
This is where I would start.
https://github.com/espressif/esp-idf/tr ... sic_config
In mcpwm_basic_config_example.c, you will see "static void disp_captured_signal(void *arg)" function. I would pick that apart to lean how it works. Then you should be able to time your pulses and get your timing.
https://github.com/espressif/esp-idf/tr ... sic_config
In mcpwm_basic_config_example.c, you will see "static void disp_captured_signal(void *arg)" function. I would pick that apart to lean how it works. Then you should be able to time your pulses and get your timing.
Who is online
Users browsing this forum: Bing [Bot] and 130 guests