Possible PWM Issue

Hi guys,

I’m work on Arduino Nano Every (ATMEGA 4809), but I can not able to generate a PWM on digitalpin 2.

If I use digitalWrite function the pin goes HIGH or LOW, so I exclude a pin, solder or wiring problems.

Here is my sample code and below I attached scope picture and Arduino pinout:

#define PIN_2 2
#define PIN_3 3
#define PIN_9 9
#define PIN_10 10

void setup() {

  pinMode(PIN_2, OUTPUT);
  pinMode(PIN_3, OUTPUT);
  pinMode(PIN_9, OUTPUT);
  pinMode(PIN_10, OUTPUT);

}

void loop() {

  analogWrite(PIN_2, 125);
  analogWrite(PIN_3, 125);
  analogWrite(PIN_9, 125);
  analogWrite(PIN_10, 125);

}

so what is wrong ? Is an arduino problem or probably is my wrong understanding ? :smiley:

Thank you.

Well, if you look at this pinout pic you can see that there are no timer (purple) attached to PA0/digital pin 2. You can also see this in the datasheet for the ATmega4809. AFAIK the Arduino Nano Every only has 5 PWM pins.

EDIT: that was not very accurate. It is true that there is no PWM output on PA0/digital pin 2, but this on purpose. The ATmega4809 supports pin swapping, so peripherals such as timer outputs can me moved to different pins. By default the ATmega4809 has timer TCA0 connected to PORTA, PA[5:0]. This timer can be routed to any port available, but you can only move all five timer outputs at once. Arduino decided to move all these outputs to PORTB, PB[5:0]. Sadly, PB3, PB4, and PB5 are not broken out on the Nano Every, so you will not be able to access these.

hansibull:
Arduino decided to move all these outputs to PORTB, PB[5:0]. Sadly, PB3, PB4, and PB5 are not broken out on the Nano Every, so you will not be able to access these.

Ok I understand, Nano Every have timer TCA0 on PORTB and TCBn on PORTF. So by default the only pins that can generate a PWM are: D3 (PF5), D5 (PB2), D6 (PF4), D9 (PB0), D10 (PB1).

Therefore there is an error on box (pinout 6 PWM) and on pinout picture on arduino store.