Setting SAM3X8E to external clock interrupt

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

youthreewire
Posts: 8
Joined: Wed Jun 10, 2015 5:21 pm

Setting SAM3X8E to external clock interrupt

Sun Jun 21, 2015 4:07 am

Hello,I want to setup the SAM3X8E to receive external clock on interrupt 1.I have some code but I dont under stand what each line does.

Code: Select all

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; //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);
}

I want it do the same as in this atmega328 code

Code: Select all

// 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;
  #endif
  TIMSK1 = 0x02; // turn on compare match interrupt
  
  // turn off all enabled interrupts (delay and wire)
  TIMSK0 = 0x00;
  TWCR = 0x00;

  sei(); // turn on interrupts
youthreewire
Posts: 8
Joined: Wed Jun 10, 2015 5:21 pm

Re: Setting SAM3X8E to external clock interrupt

Sun Jun 21, 2015 5:38 pm

Could some one tell me the coding style and syntax to set the necessary registers on SAM3X8E?
Magician
Posts: 8
Joined: Tue Aug 12, 2014 4:38 pm

Re: Setting SAM3X8E to external clock interrupt

Sun Jun 21, 2015 10:34 pm

If you are on arduino IDE, look into post "frequency measurements" - below this topic

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 4 guests