[En-Nut-Discussion] Getting precisely a 1 second interrupt from timer1 on and Ethernut3

Douglas Pearless Douglas.Pearless at pearless.co.nz
Wed May 2 00:33:20 CEST 2007



   I have been trying to get precisely a 1 second interrupt from  
timer1.  I have been trying to daisy chain it from timer0 which  
provides a 1ms periodic interrupt (the system timer).

   I have read the datasheet, looked at atmel application samples, etc  
but I cannot get it to work.

   If I connect TC1 to TC_CLKS_MCK1024 my timer 1 interrupt routine  
gets called, but when I try to connect it to TC_CLKS_XC1 it does not.

   I would appreciate help if anyone elase has done this!!!

   Cheers Douglas

   part of my code for initialising timer1 whcih is cloned from the  
NUTOS timer0 initialization:

     int dummy;

#ifndef NUT_TICK_FREQ
#define NUT_TICK_FREQ   1000UL
#endif

#if defined(MCU_AT91SAM7X256) || defined(MCU_AT91SAM9260)
    /* Enable TC1 clock. */
   
    outr(PMC_PCER, _BV(TC1_ID));
#endif

    dummy = inr(PS_PCSR);
    outr(PS_PCER, inr(PS_PCSR) | 0x20); //turn on timer 1 clock
    dummy = inr(PS_PCSR);
    /* Disable the Clock Counter */
    outr(TC1_CCR, TC_CLKDIS);
    /* Disable all interrupts */
    outr(TC1_IDR, 0xFFFFFFFF);
    /* Clear the status register. */
    dummy = inr(TC1_SR);
    /* Select divider and compare trigger and take the clock from  
timer0 running at 1ms */
//    outr(TC1_CMR, TC_CLKS_XC1 | TC_CPCTRG | TC_WAVE); //THIS DOES NOT WORK
    outr(TC1_CMR, TC_CLKS_MCK1024 | TC_CPCTRG | TC_WAVE); //THIS DOES  
WORK DIRECTLY FROM MASTER CLOCK
    dummy = inr(TC_BMR);
    /* connect clock to timer 0 at 1ms */
    outr(TC_BMR, inr(TC_BMR) | TC_TIOA0XC1);
    dummy = inr(TC_BMR);
    dummy = inr(TC0_CMR);
    outr(TC0_CMR, inr(TC0_CMR) | TC_ACPC_TOGGLE_OUTPUT);
    dummy = inr(TC0_CMR);
    /* Enable the Clock counter */
    outr(TC1_CCR, TC_CLKEN);
    /* Validate the RC compare interrupt */
    outr(TC1_IER, TC_CPCS);

    /* Register timer interrupt handler. */
    NutRegisterIrqHandler(&sig_TC1, handler, 0);
    /* Set to lowest priority. */
    NutIrqSetPriority(&sig_TC1, 0);

    /* Enable timer 0 interrupts */
    NutIrqEnable(&sig_TC1);
    //outr(AIC_IECR, _BV(TC1_ID));

    /* Set compare value for 1000 ms. */
#if defined(AT91_PLL_MAINCK)
//    outr(TC1_RC, At91GetMasterClock() / (32 * NUT_TICK_FREQ / 1000));
#else
//    outr(TC1_RC, NutGetCpuClock() / (32 * NUT_TICK_FREQ / 1000));
    outr(TC1_RC, 0x3E8);
#endif

    /* Software trigger starts the clock. */
    outr(TC1_CCR, TC_SWTRG);




More information about the En-Nut-Discussion mailing list