Changing Arduino Zero PWM Frequency

Hi Nico,

I'm trying to make a LED (pin 8 ) blink with PWM, changing the frequency to value visible to the eyes. Is it possible in some ways?

If your intention is to simply blink an LED, then it's possible to run the TC or TCC timers at a lower frequency.

Here's some code that blinks an LED at 0.5Hz, 1 second on, 1 second off on digital pin D8. It uses the TCC1 timer in Normal Frequency (NFRQ) mode, this mode simply toggles the D8 output each time the timer overflows (every second):

// Toggle LED output 1 second on, 1 second off (0.5Hz) on digital pin D8 using timer TCC1
void setup()
{ 
  // Feed GCLK0 to TCC0 and TCC1
  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN |         // Enable GCLK0 
                      GCLK_CLKCTRL_GEN_GCLK0 |     // Select GCLK0
                      GCLK_CLKCTRL_ID_TCC0_TCC1;   // Feed GCLK0 to TCC0 and TCC1
  while (GCLK->STATUS.bit.SYNCBUSY);               // Wait for synchronization

  // Enable the port multiplexer for the TCC1 PWM channel 0 (digital pin D8), SAMD21 pin PA06
  PORT->Group[g_APinDescription[8].ulPort].PINCFG[g_APinDescription[8].ulPin].bit.PMUXEN = 1;
  
  // Connect the TCC0 timer to the port outputs - port pins are paired odd PMUO and even PMUXE
  // F & E specify the timers: TCC0, TCC1 and TCC2
  PORT->Group[g_APinDescription[8].ulPort].PMUX[g_APinDescription[8].ulPin >> 1].reg |= PORT_PMUX_PMUXE_E;
  
  TCC1->PER.reg = 46874;                          // Set TCC1 timer to overflow every 1 second: 48MHz / (1024 * 46874 + 1) = 1Hz
  while(TCC0->SYNCBUSY.bit.PER);                  // Wait for synchronization
 
  TCC1->CTRLA.reg |= TCC_CTRLA_PRESCALER_DIV1024; // Set TCC1 prescaler to 1024
  TCC1->CTRLA.bit.ENABLE = 1;                     // Enable the TCC1 output
  while (TCC1->SYNCBUSY.bit.ENABLE);              // Wait for synchronization
}

void loop() {}