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.

Compiler/EK-TM4C123GXL: TIVA TM4c123gxl reload of periodic Timer not working...

Part Number: EK-TM4C123GXL
Other Parts Discussed in Thread: TM4C123GH6PM

Tool/software: TI C/C++ Compiler

Hello Everyone, so I want generate a 10Hz, 50% duty cycle led light by using the periodic timer on this board TM4c123gxl.

However, I burned the following code to the board only to see that the led light which should be "blinking" is not function correctly.

Instead of "blinking" at 10Hz the led light just emits constantly with same lightness. 

The interrupt must have been handled by the processor because else the led will not have been lit in the first place.

Therefore, i suppose the code section for timer interrupt is only entered once, maybe because I have done something wrong with the reload value of timer.

Could anybody help me? I've been stucked with this problem for a while.

#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/interrupt.h"

static unsigned long ulPeriod;
void Timer0IntHandler(void);

void Timer0IntHandler(void)
{
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Read the current state of the GPIO pin and
// write back the opposite state
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
else
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
}

void setup(){
//system clock to run at 40MHz
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)){}

TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC );

ulPeriod = (SysCtlClockGet() / 10) / 2;
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000);//ulPeriod -1);
IntEnable(INT_TIMER0A);


TimerEnable(TIMER0_BASE, TIMER_A);
IntMasterEnable();
TimerIntDisable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerIntRegister(TIMER0_BASE, TIMER_A, &Timer0IntHandler);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

}

void loop(){

}

  • Hi,
    I quickly browsed through your code and didn't spot anything wrong that is obvious. Can you put a breakpoint in the Timer0IntHandler and will you be entering the ISR each time the timer is up. Can you also use the scope to capture PF2?
  • Hi! Thank you for your help. Good news is, I just solve this problem by changing the timer to a full-width timer, since the half-width timer can only count to 2^16 = 65536

    and therefore with my 16MHz clock I will be entering so fast the ISR that the led light is not perceptible to naked eyes.

    Now that the full-width counter can count up to a sufficient large number, I saw the led flashing at 10Hz.

    Thank you again!!!