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.

TM4C1294NCPDT: Not able to generate 1ms delay using timers.

Part Number: TM4C1294NCPDT


Hi,

we are using the TM4C1294NCPDT launchpad. In that launchpad , we did the program to generate 1ms delay by using timer, but we are not able to generate the delay.

when we are loading the less value (eg: 120000) in to the timer register , in this case after time elapsed it's not going in to the isr. 

Kindly go through the code....

int main(void)
{

ui32SysClock=SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE , GPIO_PIN_0 | GPIO_PIN_1);

TimerConfigure(TIMER0_BASE , TIMER_CFG_PERIODIC);

 TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);

period = 120000;

TimerLoadSet(TIMER0_BASE , TIMER_A , period-1);

IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE , TIMER_TIMA_TIMEOUT);
IntMasterEnable();

TimerEnable(TIMER0_BASE , TIMER_A);

while(1);

return 0;
}

void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE , TIMER_TIMA_TIMEOUT);

if(GPIOPinRead(GPIO_PORTN_BASE , GPIO_PIN_1))
{
GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1 , 0);
}
else
{
GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1, 2);
}
}

Thanks and Best Regards,

Venkatadri

  • You have configured timer 0 as a split timer (your second call to TimerConfigure()), meaning that timer A is 16 bits wide. You tried to load a period of 11999 counts into a 16-bit register. The 16 bit register cannot contain a number greater than 65535. If you intended to use timer 0 as a 32-bit timer, you should not include the second call to TimerConfigure(). You other option is to use Timer 0 as a split timer but set the prescale with a call to TimerPrescaleSet().
  • Thanks you for your quick response sir,

    I configured same as you suggested sir but i'am still not able to generate the 1ms time delay. I loaded the period value 23000 to generate the 50ms delay but when period value is less than 40000 is loaded in to the timerloadset() it's not entering in to the timer isr. can you please tell me the sir, how to set the prescale value to generate the 1ms and 1ns time delay.

    int main(void)
    {

    ui32SysClock=SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE , GPIO_PIN_0 | GPIO_PIN_1);

     TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);

    TimerPrescaleSet(TIMER0_BASE,TIMER_A,255);

    //period=65535;          // for 140 ms

    period = 23000;

    TimerLoadSet(TIMER0_BASE , TIMER_A , period-1);

    IntEnable(INT_TIMER0A);
    TimerIntEnable(TIMER0_BASE , TIMER_TIMA_TIMEOUT);
    IntMasterEnable();

    TimerEnable(TIMER0_BASE , TIMER_A);

    while(1);

    return 0;
    }

    void Timer0IntHandler(void)
    {
    TimerIntClear(TIMER0_BASE , TIMER_TIMA_TIMEOUT);

    if(GPIOPinRead(GPIO_PORTN_BASE , GPIO_PIN_1))
    {
    GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1 , 0);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1, 2);
    }
    }

    Thanks ,

    Venkatadri

  • I don't know what the problem was. I took your code and changed the prescale to 120 and the timer preload value to 1000 and have a 1mS periodic interrupt.

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_ints.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"
    
    uint32_t ui32SysClock;
    
    int main(void)
    {
        unsigned int period;
    
        ui32SysClock=SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
        GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE , GPIO_PIN_0 | GPIO_PIN_1);
    
        TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);
    
        // 120MHz divided by 120 gives 1MHz timer clock
        TimerPrescaleSet(TIMER0_BASE, TIMER_A, 120 - 1);
    
        //period of 1000 gives 1 mS interrupt
        period = 1000;
    
        TimerLoadSet(TIMER0_BASE , TIMER_A , period-1);
    
        IntEnable(INT_TIMER0A);
        TimerIntEnable(TIMER0_BASE , TIMER_TIMA_TIMEOUT);
        IntMasterEnable();
    
        TimerEnable(TIMER0_BASE , TIMER_A);
    
        while(1);
    
        return 0;
    }
    
    void Timer0IntHandler(void)
    {
        TimerIntClear(TIMER0_BASE , TIMER_TIMA_TIMEOUT);
    
        if(GPIOPinRead(GPIO_PORTN_BASE , GPIO_PIN_1))
        {
            GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1 , 0);
        }
        else
        {
            GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1, 2);
        }
    }
    

  • Hi Bob Crosby sir,
    Now I got output as per you posted. Thank you sir for your quick response.
    Thanks,
    Venkatadri.