Go Down

Topic: External clock input on timer0 (Read 82 times) previous topic - next topic


Jun 21, 2015, 03:55 am Last Edit: Jun 21, 2015, 01:01 pm by youthreewire

I want to set up the timer interrupt 1 for external clock input on the Due.How do I do it? I have some code for the timer but it is set to internal clock4. I need to give it an external clock.
Code: [Select]
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
        TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
        uint32_t rc = VARIANT_MCK/128/frequency; //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);

I need the Due code to do the following in the atmega328 code below.

Code: [Select]
// setup timer1 for codec clock division
  TCCR1A = 0x00; // set to CTC mode
  TCCR1B = 0x0f; // set to CTC mode, external clock
  TCCR1C = 0x00; // not used
  TCNT1H = 0x00; // clear the counter
  TCNT1H = 0x00;
  #if SAMPLE_RATE == 88
    OCR1AH = 0x00; // set the counter top
    OCR1AL = 0x3f;
  #elif (SAMPLE_RATE == 44) || (SAMPLE_RATE == 22)
    OCR1AH = 0x00; // set the counter top
    OCR1AL = 0x7f;
  #elif SAMPLE_RATE == 8
    OCR1AH = 0x02; // set the counter top
    OCR1AL = 0xbf;
  #elif SAMPLE_RATE == 2
    OCR1AH = 0x04; // set the counter top
    OCR1AL = 0x7f;
  TIMSK1 = 0x02; // turn on compare match interrupt
  // turn off all enabled interrupts (delay and wire)
  TIMSK0 = 0x00;
  TWCR = 0x00;

  sei(); // turn on interrupts


I found some information about the Due timers here:

Here they mention about connecting an external clock but TCLK0 but also mentioned about I/O Lines TIOA0 ,TIOB0. i am confused here.


I found this in the data sheet
"Block Mode Register (TC_BMR)--defines the external clock inputs for each channel, allowing them to be

Go Up