How to configure all available PWM outputs?

Hi there.

I’m hoping to use a ItsyBitsy M0 to drive a somewhat large number of PWM outputs that control current on a bunch of LED drivers. However, I can’t seem to successfully setup PWMs on all the pins that should allow it… the python fails to compile with a runtime error “all timers in use”.

Is it possible that despite the promised 13 PWM capable pins, only a smaller number can be used simultaneously? - If so, I am happy for 12 of them to share same duty cycle/frequency if that helps?

I need a total of 13 PWM outputs. Using CircuitPython, I have the following pins working (or at least the init is accepted):

D1,D2,D3,D5,D7,D9,D10,D11,D12,D13,A2,SCL - so I am one short!

According to the Adafruit page (Pinouts | Introducing ItsyBitsy M0 Express | Adafruit Learning System) I should also be able to use A1 - however, configuring this results in a “Invalid pin error”.

Other pins such as D4 should also be available for PWM - but the init results in the “all timers in use” error.

Basic sample code attached for reference - any suggestions much apreciated!

sample.txt (422 Bytes)

As a side note, I looked into a shift register to cut down on pins - however the resulting high-frequency flicker is not compatable with my photographic application for this project :frowning:

You can "configure" each available hardware PWM output by analogWrite(). The number of available hardware PWM outputs depends on the Arduino controller type - which one do you use?

Dunno how CircuitPython handles PWM outputs, but the message "all timers in use" suggests that it also uses hardware PWM. So you are restricted to the true PWM pins marked with a "~".

Hi - thanks for the reply.

I'm using an Adafruit ItsyBitsy M0 Express (Overview | Introducing ItsyBitsy M0 Express | Adafruit Learning System) which clearly advertises 13 available PWM pins.

Perhaps I will try a regular C sketch to see if the PWM limit is somehow part of the CircuitPy setup?

If you are using Circuit Python, not the Arduino IDE, this would be a good question for the Adafruit Circuit Python forum: