I caught interest in the "Capture" part of the MCPWM module after reading the docs.
Particularly, because of the "elapsed time measurement / period measurement" (see docs below) and/or counting time between 2 pulses as the API doc of function "mcpwm_capture_enable()" suggests (see below).
Yet, I noticed that the sample code provided in the examples [EX1, EX2] does not at all do an ad hoc measurement of a time difference between two pulses.
It rather uses interrupts, a queue, saving the previous values in variables and finally calculating the timer values between the interrupts.
Trying out these examples was not difficult, thus, thank you for providing them.
But I have the feeling, that using this indirect method will cost a lot of processing power.
My goal is to measure the RPM of three different sprockets that can variably spin slowly and rather fast in an experiment of mine.
The time between the rising and falling edge varies between 320ms and 420µs in the signal. Triggering interrupts at this fast rate seems to me not very efficient, especially with three different signals.
I was thinking about using the PCNT counter module but, I would like to handle timings rather than counts for accuracy reasons.
I thought after reading the documentation to find code in "mcpwm.c" that measures the time differences between edges using less code and not a queue. I'm very new to such hardware and I very likely do not yet fully know how to read the properly (eg. "mcpwm_struct.h").
So what am I missing? Is there some way, to program it such that:
- The capture starts for example with rising edge
- The timer counts until the next rising edge (or falling edge) while saving the time difference value to a register
- Reading out the register is done when needed, not particular with an interrupt
I'd greatly appreciate any kind of help/explanation! Thank you very much in advance.
Let me recite what I've read:
Technical Documentation (Sept. 2019)
- Page 404: 16.2 Features - Capture Module
- Measurement of elapsed time between position sensor pulses
- Period and duty-cycle measurement of pulse train signals
- Pages 432/433: 188.8.131.52 Introduction - Capture Submodule
[...] At a sync event the counter is loaded with phase stored in register PWM_CAP_TIMER_PHASE_REG
https://docs.espressif.com/projects/esp ... ml#capture
- Capture:[…] The hardware is able to detect the input signal’s edge and measure time between signals. As result the control software is simpler and the CPU power may be used for other tasks.
- On each capture event the capture timer’s value is stored in time-stamp register that may be then checked by calling mcpwm_capture_signal_get_value().
- - num_of_pulse: count time between rising/falling edge between 2*(pulses mentioned), counter uses APB_CLK
Code: Select all
esp_err_t mcpwm_capture_enable(..., uint32_t num_of_pulse)