Skip to content

PWMOut reports "All timers in use" after creating a variable_frequency PWMOut object #7747

Open
@RetiredWizard

Description

@RetiredWizard

CircuitPython version

Adafruit CircuitPython 8.1.0-beta.0-33-g9c1d83476 on 2023-03-17; Adafruit Grand Central M4 Express with samd51p20

Code/REPL

import board
import pwmio
a = pwmio.PWMOut(board.D8)
a.deinit()
a = pwmio.PWMOut(board.D8)
a.deinit()
a = pwmio.PWMOut(board.D7,variable_frequency=True)
a.deinit()
a = pwmio.PWMOut(board.D8)

Behavior

>>> import board
>>> import pwmio
>>> a = pwmio.PWMOut(board.D8)
>>> a.deinit()
>>> a = pwmio.PWMOut(board.D8)
>>> a.deinit()
>>> a = pwmio.PWMOut(board.D7,variable_frequency=True)
>>> a.deinit()
>>> a = pwmio.PWMOut(board.D8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: All timers in use

Description

Once a PWMOut object is created using the variable_frequency=True option some pins which could previously have PWMOut objects successfully created on them return an "All timers in use" error. A Control-D does not clear the issue, a board reset is required to allow the erring pins to once again be used to create a PWMOut object. Only some pins seems to be impacted, others continue to function as expected.

Additional information

By using the script from the learning guide:

# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""CircuitPython Essentials PWM pin identifying script"""
import board
import pwmio

for pin_name in dir(board):
    pin = getattr(board, pin_name)
    try:
        p = pwmio.PWMOut(pin)
        p.deinit()
        print("PWM on:", pin_name)  # Prints the valid, PWM-capable pins!
    except ValueError:  # This is the error returned when the pin is invalid.
        print("No PWM on:", pin_name)  # Prints the invalid pins.
    except RuntimeError:  # Timer conflict error.
        print("Timers in use:", pin_name)  # Prints the timer conflict pins.
    except TypeError:  # Error returned when checking a non-pin object in dir(board).
        pass  # Passes over non-pin objects in dir(board).

before and after creating a variable_frequency PWMOut object all the pins affected can be identified.

Looking through some other issues and old forum posts, it looks like there may be limitations on which Pins can be used for PWMOut in conjunction with variable_frequency PWMOut objects, but I would think those limitations would be dropped once the variable_frequency object was deinit'd. I would also think a Control-D would reset the pins to the same state as a power-up.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions