Multiple PWM Outputs with Unique Frequencies

manual says:
mclk/1024*1/255 is the slowest clock == 84000000/1024/255==321.69....HZ
theoreticaly the longest period should be 321.7/65535 =.00491.... hz or 203sec/ pulse...

i dislike the clock setting function / you may have better luck seting it explitistly from the associated values (Find your own dividers & send them to the function )

hook a led(& resistor) to pin 9 & try the code below

/* 
  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
#define PWM_CHANNEL_0 0
#define PWM_CHANNEL_4 4
#define PWM_CHANNEL_5 5
#define PWM_CHANNEL_6 6
int period =2;
 
 
 void
startTimer (Tc * tc, uint32_t channel, IRQn_Type irq, uint32_t frequency)
{
  pmc_set_writeprotect (false);
  pmc_enable_periph_clk ((uint32_t) irq);
  TC_Configure (tc, channel,
		TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC |
		TC_CMR_TCCLKS_TIMER_CLOCK4);
  uint32_t rc =
    (VARIANT_MCK / 128 / frequency) > 2 ? (VARIANT_MCK / 128 / frequency) : 2;
  //128 because we selected TIMER_CLOCK4 above
  TC_SetRA (tc, channel, rc / 2);	//50% high, 50% low
  TC_SetRC (tc, channel, rc);
  TC_Start (tc, channel);
  tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPCS;
  tc->TC_CHANNEL[channel].TC_IDR = ~TC_IER_CPCS;
  NVIC_EnableIRQ (irq);
}
//--------------------------------------------------------------------------
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);  
   Serial.begin(9600);
  startTimer(TC1, 0, TC3_IRQn, 1);
  //PWM config
  pmc_enable_periph_clk(ID_PWM);  
  
  PWMC_DisableChannel(PWM, PWM_CHANNEL_4);  
  
  PWMC_ConfigureClocks(VARIANT_MCK/1024 /255, 0, VARIANT_MCK);

int ulPin = 9;
              // Setup PWM for this pin
              PIO_Configure(g_APinDescription[ulPin].pPort,
              g_APinDescription[ulPin].ulPinType,
              g_APinDescription[ulPin].ulPin,
              g_APinDescription[ulPin].ulPinConfiguration);
   //***************Channel 4           
   PWMC_ConfigureChannel( 
     (Pwm*)     PWM,    // pPwm,
     (uint32_t)    PWM_CHANNEL_4  ,  // ul_channel, 
     (uint32_t)    PWM_CMR_CPRE_CLKA  ,  // prescaler, 
     (uint32_t)    0  ,  // alignment, 0=left alighned
     (uint32_t)    0  ); // polarity ) 
    PWMC_SetPeriod( 
      (Pwm*) PWM,  //pPwm, 
      (uint32_t) PWM_CHANNEL_4,//ul_channel,   
      (uint16_t) period
    );
    PWMC_SetDutyCycle( 
      (Pwm*) PWM ,//pPwm, 
      (uint32_t) PWM_CHANNEL_4,// ul_channel, 
      (uint16_t) period/2 //duty
      );
  PWMC_EnableChannel( 
        (Pwm*) PWM,  //pPwm, 
        (uint32_t)  PWM_CHANNEL_4// ul_channel 
      ) ;
 }


//*******************************************************8
volatile boolean l;

// This function is called every 1 sec.
void TC3_Handler()
{
  // You must do TC_GetStatus to "accept" interrupt
  // As parameters use the first two parameters used in startTimer (TC1, 0 in this case)
  TC_GetStatus(TC1, 0);

  digitalWrite(led, l = !l);
  period < 4 ?  period = 4:period =period  << 1;
  period >65536 ? period = 4 :period;
      PWMC_SetPeriod( 
      (Pwm*) PWM,  //pPwm, 
      (uint32_t) PWM_CHANNEL_4,//ul_channel, 
      (uint16_t) period-1
    );
      PWMC_SetDutyCycle( 
      (Pwm*) PWM ,//pPwm, 
      (uint32_t) PWM_CHANNEL_4,// ul_channel, 
      (uint16_t) PWM->PWM_CH_NUM[4].PWM_CPRD/2 //duty
      );
}

// the loop routine runs over and over again forever:
void loop() {
Serial.println( PWM->PWM_CH_NUM[4].PWM_CPRD);
  
}