another timer question

Hey folks,

I need some help w/ using the timer interrupts on the Due as I’m running into an issue I do not understand.

I’m trying to use 2 different timers to create interrupts at different rates. I’ve managed to get TC0, channel0 set up and working with no problems, however if I try to then get a different timer ( TC0, channel1 for example ) working, the code that worked for TC0,0 fails to work for TC0,1.

Here’s what I’m talking about. This works just fine and I get the pin13 LED toggling on the counter expiration/interrupts

volatile boolean l;

void TC0_Handler()
{
    long dummy=REG_TC0_SR0;                      
    l= !l;
}

void setup(){
  pinMode(13,OUTPUT);
  
  PMC->PMC_PCER0 = 1<<27;  // PMC: Enable Timer TC0 ( clock enable for peripheral ID 27 which is TC0
  REG_TC0_WPMR=0x54494D00; // enable write to registers
  //             33222222222211111111110000000000
  //             10987654321098765432109876543210 
  REG_TC0_CMR0=0b00000000000000001100000000000001; // set channel mode register (see datasheet)
  
  // CMR bits set
  // 15 = WAVE: waveform mode selected
  // 14:13 = WAVSEL, up mode w/ trigger on RC compare ( important for counter matching ) 
  // 2:0 = TCCLKS, timer selection ( divide_by ) = 1  ( SYSCLK/8 )

  REG_TC0_RC0=0x84E1C0; // counter period 
  REG_TC0_CCR0=0b101;    // start counter
  REG_TC0_IER0=0b00010000; // enable interrupt on counter=rc
  REG_TC0_IDR0=0b11101111; // disable other interrupts

  NVIC_EnableIRQ(TC0_IRQn); // enable TC0 interrupts

}

void loop(){
      digitalWrite(13,l);
}

However if I modify the code to use TC0,1, I fail to get the interrupts / LED toggling:

volatile boolean l;

void TC1_Handler()
{
    long dummy=REG_TC0_SR1;                      
    l= !l;
}

void setup(){
  pinMode(13,OUTPUT);
  
  PMC->PMC_PCER0 = 1<<27;  // PMC: Enable Timer TC0 ( clock enable for peripheral ID 27 which is TC0
  REG_TC0_WPMR=0x54494D00; // enable write to registers
  //             33222222222211111111110000000000
  //             10987654321098765432109876543210 
  REG_TC0_CMR1=0b00000000000000001100000000000001; // set channel mode register (see datasheet)
  
  // CMR bits set
  // 15 = WAVE: waveform mode selected
  // 14:13 = WAVSEL, up mode w/ trigger on RC compare ( important for counter matching ) 
  // 2:0 = TCCLKS, timer selection ( divide_by ) = 1  ( SYSCLK/8 )

  REG_TC0_RC1=0x84E1C0; // counter period 
  REG_TC0_CCR1=0b101;    // start counter
  REG_TC0_IER1=0b00010000; // enable interrupt on counter=rc
  REG_TC0_IDR1=0b11101111; // disable other interrupts

  NVIC_EnableIRQ(TC1_IRQn); // enable TC0 interrupts

}

void loop(){
      digitalWrite(13,l);
}

The same holds true if I try to use TC1 channel 0:

volatile boolean l;

void TC3_Handler()
{
    long dummy=REG_TC1_SR0;                      
    l= !l;
}

void setup(){
  pinMode(13,OUTPUT);
  
  PMC->PMC_PCER0 = 1<<28;  // PMC: Enable Timer TC1 ( clock enable for peripheral ID 28 which is TC1
  REG_TC1_WPMR=0x54494D00; // enable write to registers
  //             33222222222211111111110000000000
  //             10987654321098765432109876543210 
  REG_TC1_CMR0=0b00000000000000001100000000000001; // set channel mode register (see datasheet)
  
  // CMR bits set
  // 15 = WAVE: waveform mode selected
  // 14:13 = WAVSEL, up mode w/ trigger on RC compare ( important for counter matching ) 
  // 2:0 = TCCLKS, timer selection ( divide_by ) = 1  ( SYSCLK/8 )

  REG_TC1_RC0=0x84E1C0; // counter period 
  REG_TC1_CCR0=0b101;    // start counter
  REG_TC1_IER0=0b00010000; // enable interrupt on counter=rc
  REG_TC1_IDR0=0b11101111; // disable other interrupts

  NVIC_EnableIRQ(TC3_IRQn); // enable TC1 interrupts

}

void loop(){
      digitalWrite(13,l);
}

I assume there are probably other config regs that need to be written to get the other timers/channels working that are set by default for TC0,0 but I’m struggling to find them.

Any help would be great.

thanks

nevermind.

I figured it out. I was thinking the peripheral clock enables were on a per-TC basis so only 3 needed, not a per channel basis ( 9 used ).

as always. RTFM