Skip to content

Instantiation of PWM sometimes fails. #2

@diputssi

Description

@diputssi

It appears that as long as you don't change the value of freq, it continues to work. But 'sometimes' a change in frequency will fail. This is most likely because the underlying MicroPython library is doing some kind of magic to check for valid values.

Here is an example:

mosfet_pwm = PWM(Pin(4), freq=15000) # 15kHz
mosfet_pwm = PWM(Pin(4), freq=15000) # 15kHz
mosfet_pwm = PWM(Pin(4), freq=30000) # 30kHz
Traceback (most recent call last):
File "", line 1, in
ValueError: unreachable frequency 30000
mosfet_pwm = PWM(Pin(4), freq=30000) # 30kHz

If you run the function again, it appears to work correctly. Might need to be wrapped in a small loop or try catch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions