Metro M4 Express ATSAMD51 PWM Frequency and Resolution

Hi Casey10110,

The A2 pin on the Adafruit Feather M4 is only connected to timer TC4, (I/O Multiplexing and Considerations table in the SAMD51 datasheet). As you mention, the tone() function also happens to use timer TC4 as well.

By the way, if you need to change the duty-cycle or frequency during operation, then it's possible to use the SAMD51's buffered CCBUF and PERBUF registers. This updates the corresponding CC and PER registers at the beginning of the timer cycle, thereby preventing glitches from appearing on your PWM output. (Changes to the CC and PER registers occur immediately at the output, regardless of the current position in the timer cycle).

For example, to change the duty-cycle between 25% and 75% every second:

void loop() 
{
  TCC0->CCBUF[0].reg = 29999;    // Set-up the CCBUF (Counter Compare Buffered), channel 0 register for 25% duty-cycle          
  delay(1000);                   // Wait for 1 second
  TCC0->CCBUF[0].reg = 89999;    // Set-up the CCBUF (Counter Compare Buffered), channel 0 register for 75% duty-cycle
  delay(1000);                   // Wait for 1 second
}