1 year ago

#210396

test-img

Chris Field

Measure PWM Duty Cycle on RP2040 using micropython

I'm trying to use a Raspberry Pi Pico to measure an incoming PWM signal duty cycle and use the value to drive an I2C digital potentiometer. I'd like to use micropython as I know some of this already. The I2C output I have working with no problems. However I can't find where to start with the PWM measurement.

  • The RP2040 datasheet suggests it is possible to use the PWM slices to measure duty cycle, but the micropython PWM commands don't seem to utilise this (https://docs.micropython.org/en/latest/library/machine.PWM.html)
  • I can't see how to access the PWM slices directly in micropython
  • The "rp2" micropython — functionality specific to the RP2040 does not reference PWM as far as I can see. (https://docs.micropython.org/en/latest/library/rp2.html)
  • There are ways to measure PWM by using some coding but I would like to do it using the hardware as this frees up the processor for other tasks and it should also be more accurate I believe.

Perhaps I am just missing some documentation - any pointers much appreciated.

Chris

EDIT: I have found a useful module which covers a large part of this query: https://github.com/phoreglad/pico-MP-modules/tree/main/PWMCounter

slice

micropython

pwm

0 Answers

Your Answer

Accepted video resources