Hello. I use LM3S9b90 microcontroller. I want to generate interrupt in periodic timer mode each time when the timer value equals the timer match register. Corresponding the datasheet this should work:
11.3.2.1 One-Shot/Periodic Timer Mode
In addition to reloading the count value, the GPTM generates interrupts and triggers when it reaches the time-out event... By setting the TnMIE bit in the GPTMTnMR register, an interrupt condition can also be generated when the Timer value equals the value loaded into the GPTM Timer n Match (GPTMTnMATCHR) and GPTM Timer n Prescale Match (GPTMTnPMR) registers.
But my code doesn't work well. It looks as follows:
void Timer0AIntHandler() { TimerIntClear(TIMER0_BASE, TIMER_CAPA_MATCH); uint32_t val = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_4); val = ~val; val = val & GPIO_PIN_4; GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, val); } int main() { SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_4); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); uint32_t const freq = SysCtlClockGet(); // freq = 80 000 000 = 80MHz uint32_t const period = freq; // Overflow period = 1 sec TimerLoadSet(TIMER0_BASE, TIMER_A, period); uint32_t const pulse_width = period / 2; // Match value = 0.5 sec TimerMatchSet(TIMER0_BASE, TIMER_A, pulse_width); IntMasterEnable(); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_MATCH); IntEnable(INT_TIMER0A); TimerEnable(TIMER0_BASE, TIMER_A); while (true) { } }
I expect the handler will be called each second, but it happens much more often. It looks like I forgot to clear interrupt bit, but I did.