Arduino Due - Clock Chaining

Hello,

Is there anyone who is working or has worked with the Due timer/counter Clock chaining?
I am struggling to find any general information or any code examples to get it working.(any information not mentioned in datasheet would be really appreciated).

Thank you.

To chain timers, you need to set TC_BMR and TC_CMR accordingly (as stated in the datasheet).

Here is an example sketch with Timer Counter 0 channel 1 clocked by Timer Counter 0 channel 0 TIOA0:

/****************************************************************************************/
/*          TImer Counter 0 channel 1 is chained with Timer Counter 0 channel 0         */
/****************************************************************************************/ 

void setup() {
 
  pinMode(LED_BUILTIN, OUTPUT);

  /*************  Timer Counter 0 Channel 0 to generate PWM pulses thru TIOA0  ************/
  PMC->PMC_PCER0 |= PMC_PCER0_PID27;                      // TC0 power ON - Timer Counter 0 channel 0 IS TC0

  TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK4  // MCK/128, clk on rising edge
                              | TC_CMR_WAVE               // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC        // UP mode with automatic trigger on RC Compare
                              | TC_CMR_ACPA_CLEAR          // Clear TIOA0 on RA compare match
                              | TC_CMR_ACPC_SET;           // Set TIOA0 on RC compare match

  TC0->TC_CHANNEL[0].TC_RC = 250;  //<*********************  Frequency = (Mck/128)/TC_RC  Hz = 2625 Hz
  TC0->TC_CHANNEL[0].TC_RA = 100;  //<********************   Duty cycle = (TC_RA/TC_RC) * 100  %

  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable

  /*******************     TC1 is internally clocked by TIOA0        ********************/
  PMC->PMC_PCER0 |= PMC_PCER0_PID28;                      // TC1 power ON - Timer Counter 0 channel 1 IS TC1

  TC0->TC_BMR = TC_BMR_TC1XC1S_TIOA0;                     // Timer Counter 0 channel 1 is internally clocked by TIOA0

  TC0->TC_CHANNEL[1].TC_CMR = TC_CMR_TCCLKS_XC1            // External clock XC1 selected
                              | TC_CMR_WAVE                // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC        // UP mode with automatic trigger on RC Compare
                              | TC_CMR_ACPA_CLEAR          // Clear TIOA1 on RA compare match
                              | TC_CMR_ACPC_SET;           // Set TIOA1 on RC compare match

  TC0->TC_CHANNEL[1].TC_RC = 105;  //<*********************  Frequency = 2625/TC_RC  Hz = 25 Hz
  TC0->TC_CHANNEL[1].TC_RA = 10;  //<********************   Duty cycle = (TC_RA/TC_RC) * 100  %

  TC0->TC_CHANNEL[1].TC_IER = TC_IER_CPCS;                 // Interrupt on RC compare match
  NVIC_EnableIRQ(TC1_IRQn);                                // TC1 Interrupt enable

  TC0->TC_CHANNEL[1].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC1 counter and enable

}

void TC1_Handler() {
  static uint32_t Count;
  TC0->TC_CHANNEL[1].TC_SR;  // Read and clear status register
  Count++;
  if (Count > 25) {
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));  // Toggle LED every 1 Hz
    Count = 0;
  }
}

void loop() {
}

Thank you ard_newbie its works fine.

Hello,
this sketch works very good, but I am trying to output this TIOA1 but I cannot.

Can someone help me to output it ?

Thanks

I found the solution myself :

void setup_pio_TIOA1 ()  // Configure Ard pin 7 as output TIOA1
{
  
  PIOA->PIO_PDR = PIO_PA2A_TIOA1 ;  // disable PIO control
  PIOA->PIO_IDR = PIO_PA2A_TIOA1 ;   // disable PIO interrupts
}

Hello,
do you know if is it possible to chained three timers ?

Because I am trying but it is not working

Thank you

Is it a Uni assignment ?

TUCTUC77:
do you know if is it possible to chained three timers ?

Yes it is.

Ok thank you very much !