Tool/software: TI C/C++ Compiler
I am using a timer to generate a pulse with different periods. The timer is working fine when counting from 80 to 16M counts (TIMER0->TAILR). But when I go below 80, it always give the same period (1.7 usec).
Here is my code:
#include <lm4f120h5qr.h> #include <string.h> #include <stdlib.h> #include <stdint.h> void TIMER_INIT(){ SYSCTL->RCGCTIMER |= (1<<0); //1: Disable the timer (clear the TnEN bit in the GPTMCTL register) TIMER0->CTL &= ~(1<<0); //2: Write the GPTMCFG with a value of 0x00000000 TIMER0->CFG = 0x00000000; //3: Configure the TnMR field in the GPTMTnMR. 0x2 for Periodic TIMER0->TAMR |= (0x2<<0); //4:Count up timer TIMER0->TAMR &= (1<<4); //5: Load the value that you will count down/up to TIMER0->TAILR = 16000000; //0x00F42400 16,000,000 this corresponds to the clk speed of this microcontroller //6: If interrupts are required, set the appropriate bits in the GPTMIMR //7: Set the TnEN bit in the GPTMCTL register to enable the timer and start counting TIMER0->CTL |= (1<<0); }
int main() { TIMER_INIT(); while (1){ while((TIMER0->RIS & 0x00000001) != 1){} // Wait if TIMER0 has not timed out. TIMER0->ICR |= (1<<0); GPIOC->DATA ^= (1<<5); //trigger C5 } }
Note: I am using a logic analyzer to measure the pulse period.