What is the way to setup a PWM counter which triggers IRQ once counter wrapped? #16056
Answered
by
peterhinch
pchala
asked this question in
RP2040 / Pico
-
So I would like to after 100 pulses PWM counter trigger IRQ (callback) to handle next step. I have found https://github.com/phoreglad/pico-MP-modules/blob/main/PWMCounter/README.md but it misses callback functionality. I can do it with PIO but I would like to save them for other tasks. |
Beta Was this translation helpful? Give feedback.
Answered by
peterhinch
Oct 22, 2024
Replies: 1 comment 1 reply
-
You haven't mentioned the PWM frequency but unless it's very high why not use a counter? class Foo:
# Construct with a pin instance configured as an input and your callback
def __init__(self, pin, callback):
self.callback = callback
self.count = 0
irq = pin.irq(self.cb, Pin.IRQ_RISING, hard=True)
def cb(self, _): # Actual pin ISR
self.count += 1
self.count %= 100
if not self.count:
self.callback() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
pchala
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You haven't mentioned the PWM frequency but unless it's very high why not use a counter?