5th analogWrite causes crash

I've just started tinkering with arduinos and my experience level is sufficiently low when it comes to the hardware side in general. I'm a software developer by trade, so I do understand the programming part of it (to a certain degree I guess).

Please don't hold back on the technical details :slight_smile:


I've started tinkering with LEDs using three of the PWM pins on a Nano 33 BLE board (specifically 9, 10, 11).
And everything was working so far. Did some rainbow transitions, etc just to get used to using the pins.

Now I wanted to compare two different rainbow transitions and tried to add a second LED. I checked which other pins would be PWM and found 3, 5 and 6.

To start with I just tried to turn on both LEDs, but after the 4th analogWrite, the 5th just won't work and the Arduino seems to be stuck (have to double press reset to upload a new program).

I'm stumped as to why this might be happening.

    analogWrite(D3, 255);  // LED1 - Red
    analogWrite(D5, 255);  // LED1 - Green
    analogWrite(D6, 255);  // LED1 - Blue 
    analogWrite(D9, 255);  // LED2 - Red
    analogWrite(D10, 255); // LED2 - Green
    analogWrite(D11, 255); // LED2 - Blue

I'm using 255s, to use the resulting color of the RGB LEDs to see when it's failing.

If I use digitalWrite([...], HIGH), both LEDs are white, but with digital write, LED1 is white, while LED2 stays red.

If I mix up the statements, it's always the 5th analog write that is causing the arduino to be stuck.

This may be of interest Arduino Nano 33 BLE high-frequency PWM for more than 4 pins

1 Like

Thanks, will check it out. Looks promising :slight_smile:

@byteflux, your topic has been moved to a more suitable location on the forum.

That is a major shortcoming. It should be mentioned at least in the reference: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/.
It would be better if it was fixed, to allow that all 21 pins can be used for PWM output.

There is a Pull Request for the documentation: https://github.com/arduino/reference-en/pull/824.
After reading about, it seems that things can get hairy when libraries are used which might or might not use timers.