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.

tm4C1294X timer config

Other Parts Discussed in Thread: TM4C1294NCPDT

Hello, 

I'm using a tm4c1294xl launchpad. I'm trying to configure Timer 0 to run in periodic mode as a split 16 bits timer. When debugging, I saw that after  IntEnable(INT_TIMER0A) the program jumps to the interrupt error handler although the timer is disable.This is the normal behavior? Please tell me what am I doing wrong.

#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c1294ncpdt.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

int main(void) {

uint32_t sysClock;

//configure sys clock
sysClock=SysCtlClockFreqSet((SYSCTL_OSC_MAIN|SYSCTL_XTAL_25MHZ|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_320),40000000);

//enable peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

//config gpio and timer0
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1);
TimerConfigure(TIMER0_BASE,TIMER_CFG_SPLIT_PAIR |TIMER_CFG_A_PERIODIC|TIMER_CFG_B_PERIODIC);
TimerLoadSet(TIMER0_BASE,TIMER_A,10000000);
TimerLoadSet(TIMER0_BASE,TIMER_B,20000000);

IntMasterEnable(); //activate processor interrupt
IntEnable(INT_TIMER0A);
IntEnable(INT_TIMER0B);

TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
TimerIntEnable(TIMER0_BASE,TIMER_TIMB_TIMEOUT);

//TimerEnable(TIMER0_BASE,TIMER_A);
TimerEnable(TIMER0_BASE,TIMER_BOTH);
/*IntEnable(INT_TIMER0A);
IntEnable(INT_TIMER0B);*/

while(1){
}


}

void Timer0AIntHandler(void)
{
TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
if (GPIOPinRead(GPIO_PORTN_BASE,GPIO_PIN_0))
{
GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0,0);
}else
{
GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0,1);
}
}


void Timer0BIntHandler(void){
TimerIntClear(TIMER0_BASE,TIMER_TIMB_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);
}

}

  • Hello Florin,

    In split mode the timer would be a 16-bit timer. So the load value you are giving is definitely out of range of 2^16.You may want to correct the same

    Secondly, there could be a spurious interrupt logged in from a previous run. So before SysCtlPeripheralEnable of the timer do a SysCtlPeripheralReset to ensure that the previous run does not cause a problem

    Similarly, you can call IntUnpend before IntEnable to clear any stray status.

    Regards

    Amit

  • Hello Amit,


    Thank you for your answer.I overlooked that the input value for split mode should be on 16 bits. I modified this and also implemented your other suggestion and now it's working fine.


    Best regards,
    Florin