-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp32/PWM: Reduce inconsitencies between ports. #10854
base: master
Are you sure you want to change the base?
esp32/PWM: Reduce inconsitencies between ports. #10854
Conversation
Code size report:
|
Wouldn't it be better to put DEBUG printing into a separate PR? |
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #10854 +/- ##
=======================================
Coverage 98.36% 98.36%
=======================================
Files 159 159
Lines 21090 21090
=======================================
Hits 20745 20745
Misses 345 345 ☔ View full report in Codecov by Sentry. |
V30303-161405.mp4 |
I fetched the PR, compiled & loaded it. What I found somewhat unexpected was the error message after the sequence:
Which said: What has to be discussed beside that is the method duty(). The range is different for the ports which support it. 1024 for ESP32, 256 for ESP8266, 100 for nrf and 10000 for CC3200. The duty() method was intentionally not implemented any more at the newer ports. And i may be dropped in a release later than 1.20 (nickname Godot). |
output is
Earlier in a discussion, someone said that 1023 is too small for his application case, so duty=100 in nrf port is small too. 0..10000 is attractive for noobs
output is
I vote for the duty [0..1023] range. |
pwm.duty() is kept for legacy only in the ports that had it before duty_us() was introduced. It will be dropped some day. For instance with the announced version 2.x, which will have breaking changes. So no reason to change it at the moment. |
V30309-134257.mp4 |
V30309-141247.mp4 |
983b093
to
eb33120
Compare
7d821bb
to
265b82e
Compare
@IhorNehrutsa I have a question regarding the PWM module. Reading the various ESP32 reference manuals I learned, the the ESP32 has 3 to 8 timers, which can be assigned to 6 to 16 PWM channels, which then can be assigned to GPIO pins. Pretty flexible. Since the timer and channel to be used cannot be selected in the constructor, the selection of timer an channel is kind of automatic. What is the policy you have implemented? Is there some way to control this assignment? |
Try to find a timer with the same frequency in the current mode, otherwise in the next mode.
Output is::
See https://github.com/IhorNehrutsa/micropython/blob/pwm_reduce_inconsist/docs/esp32/tutorial/pwm.rst |
Thank you for the explanation and the example code. It is very convenient. The strategy looks fine for an automatic assignment. It may as well be helpful to specify timer and channel in the constructor replacing the automatic search, such that one can have synchronous channels at a timer. |
@IhorNehrutsa In order to make
You could consider whether you skip the test for changes and just configure the channel always when you call init(). |
265b82e
to
490b8ea
Compare
The esp32 board build fails with esp-idf v4.0.2 because of this include in machine_pwm.c: |
Please restrict the changes in this PR to the machine.PWM module and do not add unrelated code like for debug printing. These affect all other ports as well. I you consider that useful for everyone, please open a separate PR for it. |
MP_PRN() will removed in release |
At the moment I can only use ESP IDF 5.0.2. Switching back to 4.4.2 is not possible. Since you PR fails to build with IDF 5.0.2, I cannot buils & test it. |
93a7733
to
537aac8
Compare
537aac8
to
bccd73f
Compare
I noticed the change from 65535 to 65536 to support the 100% duty by using the overflow value.
Since you capped the resolution to 16bits, it's not going to be an issue with the 20 bits counter of the ESP32. |
It works as expected. At 65536 the output is constant high, at 0 it's constant low. |
@florentbr
|
I was referring to the internal resolution which is related to duty_u16 by the scaling:
Thanks, so the 100% overflow is not used but converted a 0% inverted. |
@IhorNehrutsa It may be better to hold back the last commit until the esp-idf version is changed and the build succeeds. Otherwise it cannot be merged. |
The last update works down to 3Hz on as ESP32S3 with esp-idf 5.0.4. Still formatting errors at the code and commit message, |
@robert-hh Thank you for testing. When used with esp-idf 5.1.2 will the ESP32-S3 reach >= 1.04Hz? |
ESP32-S3 with esp-idf 5.1.2 allows 2Hz |
1cdc34a
to
e3fdc79
Compare
The frequency must be an integer. It is easily possible to change the code accepting floating point numbers for Frequency which would allow a finer granularity at low frequencies. I had implemented that, but never made a PR. There are too many PRs outstanding, and there were not many requests for that higher frequency granularity (1). |
@robert-hh I think that a finer granularity at low frequencies is a very good feature. I wrote 1.04Hz because, as @florentbr wrote, is the minimum frequency allowed closer to 1Hz on the ESP32-S3. I believe that 2Hz will works fine in my application, but if 2Hz will not enough I would like to request a PR to accept floating point numbers to have 1.04Hz (closer to 1Hz) :) Thank you very much! |
In this case there's no need for floating point. The IDF ledc driver also takes an integer for the frequency but it has the |
@IhorNehrutsa Do you like to add that check to just emit the lowest supported frequency if the requested frequency is below it. AFAIK, other ports raise an error. |
de194c4
to
114b067
Compare
ESP32-S3 with esp-idf 5.1.2 allows ~1Hz |
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
114b067
to
75452c4
Compare
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
75452c4
to
6022240
Compare
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
This PR is developed according to the: PWM: Reduce inconsistencies between ports. #10817
Note: MicroPython-lib PR Add Stepper Motor PWM-Counter driver. requires this PR.