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.

problem with timer interrupt

Hi,I m using wtimer1 in split mode. The timer is working  properly,,but the problem is coming when i am using interrupt along with it.The isr is not getting executed....


#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "utils/uartstdio.h"
#include "inc/hw_timer.h"
#include "driverlib/timer.h"
#include "inc/hw_ints.h"
#include "driverlib/pin_map.h"


void WTimer1AIntHandler(void)
{
    // Clear the timer interrupt
    TimerIntClear(WTIMER1_BASE, TIMER_TIMA_TIMEOUT);

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
    SysCtlDelay(SysCtlClockGet()/3);


}


int main(void)
{
    unsigned long int ulbase=0;

    /*Set the clocking to run at 80Mhz from the crystal of 16MHz using PLL*/
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    /* Set the clock for the GPIO Port F */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    /* Set the type of the GPIO Pin */
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
    TimerDisable(WTIMER1_BASE, TIMER_A);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1);

    TimerConfigure(WTIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PERIODIC);

    ulbase=80000000;

    TimerLoadSet(WTIMER1_BASE, TIMER_A,ulbase);


    TimerPrescaleSet(WTIMER1_BASE,TIMER_A,0x0003);

    IntMasterEnable();
    TimerIntRegister(WTIMER1_BASE, TIMER_A, WTimer1AIntHandler);
    TimerIntEnable(WTIMER1_BASE, TIMER_TIMA_TIMEOUT);

    IntEnable(INT_WTIMER1A);
    TimerEnable(WTIMER1_BASE,TIMER_A);

    while(1)
    {

    }

}

  • Hello Mahavir,

    I have doubts on the code working.

    REASON: The TimerDisable is called before the Clock is enabled using SysCtlPeripheralEnable. It wuld result in a bus fault.

    Regards

    Amit

  • sir ,,i have removed the TimerDisable from their..and my code is working properly..But isn't it a good habit to first disable the timer before enabling it?...

  • Hello Mahavir,

    The SysCtlPeripheralEnable is the function to enable the clock to the peripheral. Without the clock the TimerDisable ought not to work. Unless you have done CCS CPU Restart and before using the code that is present right now, the clock was already enabled.

    Anyways, we will look into it.

    Regards

    Amit

  • Hello Mahavir,

    The code is working fine and interrupt is getting called as I can see the LED Blink once every 4 seconds.

    0882.TM4C123_WideTimer_Periodic.c
    #include "stdint.h"
    #include "stdbool.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_timer.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_timer.h"
    #include "inc/hw_ints.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/adc.h"
    #include "driverlib/uart.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/timer.h"
    #include "driverlib/pin_map.h"
    #include "utils/uartstdio.h"
    
    
    void WTimer1AIntHandler(void)
    {
        // Clear the timer interrupt
        TimerIntClear(WTIMER1_BASE, TIMER_TIMA_TIMEOUT);
    
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
    
        SysCtlDelay(10000);
    
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);
    }
    
    
    int main(void)
    {
        unsigned long int ulbase=0;
    
        /*Set the clocking to run at 80Mhz from the crystal of 16MHz using PLL*/
        SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        /* Set the clock for the GPIO Port F and WTIMER-1*/
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1);
    
        /* Set the type of the GPIO Pin */
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
    
    
        TimerDisable(WTIMER1_BASE, TIMER_A);
    
        TimerConfigure(WTIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PERIODIC);
    
        ulbase=80000000;
    
        TimerLoadSet(WTIMER1_BASE, TIMER_A,ulbase);
    
    
        TimerPrescaleSet(WTIMER1_BASE,TIMER_A,0x0003);
    
        IntMasterEnable();
        TimerIntRegister(WTIMER1_BASE, TIMER_A, WTimer1AIntHandler);
        TimerIntEnable(WTIMER1_BASE, TIMER_TIMA_TIMEOUT);
    
        IntEnable(INT_WTIMER1A);
        TimerEnable(WTIMER1_BASE,TIMER_A);
    
        while(1)
        {
    
        }
    
    }
    

    Regards

    Amit