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(){
}