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.

EK-TM4C123GXL: Timer 1 shot up count

Part Number: EK-TM4C123GXL


I am trying to get a wide timer to count up and trigger an interrupt when the desired value is met. Is TimerMatchSet() the function to use to set the value?

My ISR is not being triggered.

Here is what I have tried:

void
Timer1IntHandler(void)
{
    static bool toggle = 1;
    MAP_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    if (toggle)
    {
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
    }
    else
    {
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
    }
    toggle = !toggle;
    TimerEnable(TIMER0_BASE, TIMER_A);

}


int
main(void)
{
    volatile uint64_t vg = 0;
    volatile uint64_t vg1 = 1000000LLU;

    MAP_FPULazyStackingEnable();
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    //LED setup
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);


    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1);

    MAP_TimerConfigure(WTIMER1_BASE, TIMER_CFG_ONE_SHOT_UP);
    //TimerLoadSet(TIMER1_BASE, TIMER_A, 0);
    TimerIntRegister(WTIMER1_BASE, TIMER_A, Timer1IntHandler);
    IntMasterEnable();
    TimerIntEnable(WTIMER1_BASE, TIMER_TIMA_TIMEOUT);
    IntEnable(INT_WTIMER1A);
    TimerMatchSet64(WTIMER1_BASE, 80000);
    TimerEnable(WTIMER1_BASE, TIMER_A);


    while(1)
    {
       vg = TimerValueGet(WTIMER1_BASE, TIMER_A);
       SysCtlDelay(100000);
    }
}

  • Hi John,

      If you are using the timer in either one-shot or periodic mode then all you need is to set up the preload value, not the match value. In your code you have set up the counter to count up. This means that the counter will start from 0 and count up to your preload value. Once the preload value is reached, it will generate an interrupt. You can use the TimerLoadSet64() API to set up the preload value. 

       MAP_TimerLoadSet64(WTIMER1_BASE,  MAP_SysCtlClockGet()); // example to load 1 second for the timer to time out

      

      

  • OK, thanks. What does TimerMatchSet64() add?

  • Hi John,

      The TimerMatchSet64 will be used for timer operating in other modes such as Input Edge-Time Mode or PWM mode. For example in PWM mode, the output PWM signal asserts when the counter is at the value of the preload registers (its start state), and is de-asserted when the counter value equals the value in the match registers. 

      For One-shot mode, you don't really need to use the match register. You have te preload value xyz that the counter will count up to starting from 0. When the counter reaches xyz it will generate an interrupt. With that said, the datasheet does mention that you could also use the match register to generate an interrupt in One-shot mode. However, I don't think it will be useful to you. See below excerpt from the datasheet for One-shot mode using match register. 

    By setting the TnMIE bit in the GPTMTnMR register, an interrupt condition can also be generated
    when the Timer value equals the value loaded into the GPTM Timer n Match (GPTMTnMATCHR)
    and GPTM Timer n Prescale Match (GPTMTnPMR) registers. This interrupt has the same status,
    masking, and clearing functions as the time-out interrupt, but uses the match interrupt bits instead
    (for example, the raw interrupt status is monitored via TnMRIS bit in the GPTM Raw Interrupt Status
    (GPTMRIS) register). Note that the interrupt status bits are not updated by the hardware unless the
    TnMIE bit in the GPTMTnMR register is set, which is different than the behavior for the time-out
    interrupt.

    For your intended purpose, I will suggest you just simply let the counter timeout.

  • Thanks. Was hoping for a BOGO.

    JH