alif: implement machine.PWM support#18799
Conversation
b4206eb to
87a1a94
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18799 +/- ##
=======================================
Coverage 98.42% 98.42%
=======================================
Files 174 174
Lines 22331 22331
=======================================
Hits 21980 21980
Misses 351 351 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
No hurry! |
|
@dpgeorge - Works great! Tested on all pins. Also, ever think about adding this to the standard lib? https://github.com/redoxcode/micropython-servo. It would make folks lives easier to be able to use this for servo control. |
Great, thanks for testing.
No, I didn't see that servo driver before. It looks simple but useful. We do have In the meantime, people could easily install that servo Python driver. |
|
@dpgeorge - Okay, feel free to merge. |
This commit adds `machine.PWM` support to the alif port. It uses the existing common machine bindings and implements the standard set of functionality: `freq()`, `duty_u16()`, `duty_ns()` and `invert`. It uses the UTIMER peripheral and makes PWM available on all pins that have an alt function connection to a UTIMER, which is 54 pins. It does not use UTIMER11 which is already in use by the HE core for its systick timer. So the following pins don't have PWM available because they need UTIMER11: P2_6, P2_7, P7_6, P7_7, P12_6, P12_7. Signed-off-by: Damien George <damien@micropython.org>
Tested on ALIF_ENSEMBLE and OPENMV_AE3 boards. Signed-off-by: Damien George <damien@micropython.org>
87a1a94 to
95b3e72
Compare
Summary
This PR adds
machine.PWMsupport to the alif port. It uses the existing common machine bindings and implements the standard set of functionality.It uses the UTIMER peripheral and makes PWM available on all pins that have an alt function connection to a UTIMER, which is 54 pins (see below about UTIMER11).
Testing
Tested on ALIF_ENSEMBLE and OPENMV_AE3, using an oscilloscope, fading LEDs and the existing
tests/extmod_hardware/machine_pwm.pytest.Sample test code that works on both alif boards:
Trade-offs and Alternatives
This uses the UTIMER peripheral, but not UTIMER11 which is already in use by the HE core for its systick timer. So the following pins don't have PWM available because they need UTIMER11: P2_6, P2_7, P7_6, P7_7, P12_6, P12_7. For OPENMV_AE3, none of those pins are exposed to the user so they don't need PWM.
For the implementation I tried to use the Alif SDK driver, but it's quite limited so most of the code here uses direct register reads/writes.