another timer question


hey folks,

need w/ using timer interrupts on due i'm running issue not understand.

i'm trying use 2 different timers create interrupts @ different rates.  i've managed tc0, channel0 set , working no problems, if try different timer ( tc0, channel1 example ) working, code worked tc0,0 fails work tc0,1.

here's i'm talking about.   this works fine , pin13 led toggling on counter expiration/interrupts

code: [select]
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 peripheral id 27 tc0
  reg_tc0_wpmr=0x54494d00; // enable write registers
  //             33222222222211111111110000000000
  //             10987654321098765432109876543210
  reg_tc0_cmr0=0b00000000000000001100000000000001; // set channel mode register (see datasheet)
 
  // cmr bits set
  // 15 = wave: waveform mode selected
  // 14:13 = wavsel, mode w/ trigger on rc compare ( important 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 modify code use tc0,1, fail interrupts / led toggling:

code: [select]
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 peripheral id 27 tc0
  reg_tc0_wpmr=0x54494d00; // enable write registers
  //             33222222222211111111110000000000
  //             10987654321098765432109876543210
  reg_tc0_cmr1=0b00000000000000001100000000000001; // set channel mode register (see datasheet)
 
  // cmr bits set
  // 15 = wave: waveform mode selected
  // 14:13 = wavsel, mode w/ trigger on rc compare ( important 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);
}


same holds true if try use tc1 channel 0:
code: [select]
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 peripheral id 28 tc1
  reg_tc1_wpmr=0x54494d00; // enable write registers
  //             33222222222211111111110000000000
  //             10987654321098765432109876543210
  reg_tc1_cmr0=0b00000000000000001100000000000001; // set channel mode register (see datasheet)
 
  // cmr bits set
  // 15 = wave: waveform mode selected
  // 14:13 = wavsel, mode w/ trigger on rc compare ( important 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);
}


assume there other config regs need written other timers/channels working set default tc0,0 i'm struggling find them.   

great.

thanks

nevermind.

i figured out.   i thinking peripheral clock enables on per-tc basis 3 needed,  not per channel basis ( 9 used ).

as always.  rtfm



Arduino Forum > Products > Arduino Due (Moderator: fabioc84) > another timer question


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support