Better PWM availability, fixing A3,D9 conflict, adding D8

As has been reported before https://forum.arduino.cc/t/analogwrite-on-pin-9-turns-led-a3-on/697997 D4 should be marked as PWM (analogWrite) capable in the Arduino Nano IoT 33, and A3 and D9 conflict.

However additionally A2 and D10 conflict, which I haven't found a mention of.

The problem with A3 and D9 conflicting can be fixed! In the file Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot/variant.cpp
replace the line:
{ PORTA, 10, PIO_ANALOG, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), ADC_Channel18, PWM0_CH2, TCC0_CH2, EXTERNAL_INT_NONE },
with the line:
{ PORTA, 10, PIO_ANALOG, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), ADC_Channel18, PWM1_CH0, TCC1_CH0, EXTERNAL_INT_NONE },
This will have PWM on pin A3 use an otherwise unused Timer/Counter channel, eliminating the conflict.

You can also add PWM capability to pin D8, by replacing the line:
{ PORTA, 18, PIO_DIGITAL, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
with the line:
{ PORTA, 18, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH0, TC3_CH0, EXTERNAL_INT_NONE },
which also uses an otherwise unused Timer/Counter channel.

If you make these changes, be sure to save a backup copy of the original file so you can restore it if necessary.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.