Input Capture Units
I am looking for an accurate implementation to capture the time after a rising edge occurred on an external pin by a WiPy 3.0 module. My needs for a time measurement between rising edges, is between 0.5s and 0.5ms with an accuracy of about 10us. Tests showed, that calling the time value inside the interrupt driven callback function is very inaccurate.
Now my question:
It seem that the ESP32 has a Capture Submodule implemented in the PWM module.
Is it possible to configure the PWM unit in a way, that it stores a time stamp value in a HW register after a rising edge on a HW pin occurred? A interrupt driven callback function could then simply read the specific register value and the value would not be interrupt latency dependent.
Any help is very appreciated
The worst-case interrupt latency that I measured on pycom's Wipy board was approximately 1 ms (measured with an oscilloscope).
I did not find the timerchannel.capture ([value]) method on the micropython implementation of pycom.
In the meantime I switched to the Pybord D series with an STM32F7.
The measured interrupt latency is approx. 30us and the timer.capture method is implemented and can be called within the callback routine.
Measurements in the us scale are no problem, so this solution works for me.
robert-hh last edited by
@d-alvrzx Oh yes. That is something I stumbled upon. So the only method I found until now is stopping the input, either be re-defining the pin, or by gating the signal with an external gate.
The behavior is caused by the esp-idf methods used. I did not look into that again about whether it could be changed.
@robert-hh I've personally attempted to use the RMT module to measure RPM signals (which are square waves at ~1 kHz in the case of my sensor), but unfortunately the module only works for signals that "stop" at some point (until it gets some timeout), while my RPM signal keeps on going as long as the engine is running... But yeah, when I tested it, it was super precise...
Any idea of how to make it work with "continuous" signals? I actually followed your code here: https://forum.pycom.io/topic/3430/how-to-measure-ac-line-frequency-using-lopy/4
robert-hh last edited by
@Markus-Roggli Did you have a look at the RMT module? It is very precise.
Have you made any progress on this? I'm considering applying a WiPy to a problem where I'll need to be measuring short events, maybe 30-100ms, with approximately 100 microsecond accuracy.
What sort of accuracy did you see in your tests? You say you were calling time() inside an interrupt. Did you try using the micropython timerchannel.capture([value]) ?