Skip to content

What is the way to setup a PWM counter which triggers IRQ once counter wrapped? #16056

Discussion options

You must be logged in to vote

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()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pchala
Comment options

Answer selected by pchala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants