This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LM4f232h5qd, Timer, Prescaler



I am working with  a LM4f232h5qd. I tried to setup an periodic interrupt from Timer0 with prescaler. 

// setup periodic interrupt
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
 TimerLoadSet(TIMER0_BASE, TIMER_A, (80000000 / (4 * 1000))); 
TIMER0_TAPR_R &= ~TIMER_TAPR_TAPSR_M;
 TIMER0_TAPR_R |= 0x03;
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntPrioritySet(INT_TIMER0A, (3 << 5));
IntEnable(INT_TIMER0A);
TimerEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); 

The interrupt gets triggered, but the frequency is not as expected. It seem that the prescaler has no influence.

Am I missing something in the setup or are there problems with the prescaler on this device as well.

I have not seen any hint in the errata.

  • Josef,

       The prescalers only work if you are using the timers in their split mode (i.e. when using a 32-bit timer as 2 16-bit timers or a 64-bit timer as 2 32-bit timers). If you need a 32 bit timer with prescale, therefore, you can use one of the 64 bit timers (for example, SYSCTL_PERIPH_WTIMER0) in its split mode.

  • Hi Dave

    You are right, it works in split mode (see code below)..
    I have not realized that non-splited mode is default. 

    Thank you
    Josef

     

    // disable timer
    TIMER0_CTL_R &= ~(TIMER_CTL_TAEN);

    // setup timer A, periodic 16-bit mode with prescaler
    TIMER0_TAMR_R &= ~ TIMER_TAMR_TAMR_M;
    TIMER0_TAMR_R |= TIMER_TAMR_TAMR_PERIOD;
     TIMER0_TAILR_R = (80000000 / (4 * 1000));
    TIMER0_CFG_R &= ~TIMER_CFG_M;
    TIMER0_CFG_R |= TIMER_CFG_16_BIT;
    TIMER0_TAPR_R &= ~TIMER_TAPR_TAPSR_M;
    TIMER0_TAPR_R |= 0x03;
    TIMER0_IMR_R |= TIMER_IMR_TATOIM;

    // setup interrupt
    IntPrioritySet(INT_TIMER0A, (3 << 5));
    IntEnable(INT_TIMER0A);

     // enable timer
    TIMER0_CTL_R |= (TIMER_CTL_TAEN);

  • I'm delighted that you got this working, Josef. In case you want to make the code clearer, please be aware that there are DriverLib APIs to do everything you need here so you don't need to mix API calls with direct register access if you would prefer that.