machine: Add wait_opposite param to time_pulse_us func.#16160
machine: Add wait_opposite param to time_pulse_us func.#16160IhorNehrutsa wants to merge 1 commit intomicropython:masterfrom
Conversation
|
Code size report: |
7a9b45d to
f59833b
Compare
|
Thanks for mentioning me. I considered creating that feature, but as optional argument to time_pulse_us() instead of a new method. That looks like a smaller change, even if the additional code size might be the same.. |
f59833b to
e29b760
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #16160 +/- ##
==========================================
- Coverage 98.54% 98.53% -0.01%
==========================================
Files 169 169
Lines 21877 21882 +5
==========================================
+ Hits 21558 21561 +3
- Misses 319 321 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f25ae18 to
b9d6cf0
Compare
b9d6cf0 to
aa1cba8
Compare
90f267b to
28906bc
Compare
dd7b953 to
b6bcf72
Compare
|
Remove additionnal synchronization time_pulse_us() from tests/extmod_hardware/machine_pwm.py |
b6bcf72 to
e2a1c3a
Compare
If the pin is initially equal to *pulse_level* then first waits until the pin input becomes different from *pulse_level*. Then the function waits until the pin input becomes equal to *pulse_level*, then the func counts the duration that the pin is equal to *pulse_level*. Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com> Co-Authored-By: Robert Hammelrath <12476868+robert-hh@users.noreply.github.com>
e2a1c3a to
27486f2
Compare
|
After discussing with @projectgus , we feel that this is a useful enhancement but maybe not worth the cost in code size. I think it would be possible to make this PR a lot simpler and less code size. I opened #17346 as a basis for that. If #17346 is merged, then the additional argument added here could be generalised to a counter, eg: machine.time_pulse_us(pin, pulse_level, timeout_us=1000000, num_levels=2)With |
It's not (yet) visible in PR 17346. |
|
Now that #17346 is merged, this PR can be updated on that. |
time_pulse_us(pin, pulse_level, timeout_us=1000000, wait_opposite=false, /)
If
wait_oppositeis true, if the pin is initially equal to pulse_level then firstwaits until the pin input becomes different from pulse_level.
Then if the current input value of the pin is different to pulse_level,
the function first waits until the pin input becomes equal to pulse_level,
then times the duration that the pin is equal to pulse_level.
The advantage is that there is no need for additional synchronization before measuring the pulse duration.
A little bit longer, but with higher accuracy.
The jitter of the pulse measurement process is about 5-15 μs on the ESP32 board.
Idia from @robert-hh #16147 (comment)
This function is used in DRAFT PR for tests
PWM from 10845 and time_hardware_pulse_us() and test from 16147. #16161
The tests results show the functionality of the function over the entire ESP32 PWM frequency range from 1Hz to 40MHz.