Other Parts Discussed in Thread: ENERGIA
Hey everyone, I am trying to learn timers. I saw an example code on the internet and checked it against datasheet and values choosen for configuration seems fine.
Expected result: 1 second red led on, 1 second led off
Actual result: 0.5 sec red led on, 0.5 sec led off
Here is the code I build and load to TM4C. Code is developed on Keil Uvision. From Manage Runtime Environment, choose CMSIS->Core and Device->Startup software components.
#include "TM4C123.h" // Device header void delay_Microsecond(uint32_t time); int main() { SYSCTL->RCGCGPIO |= 0x20; // Unlock clock for Port F GPIOF->DIR = 0x02; // Set PF1(RED) LED pin as output GPIOF->DEN = 0x02; // Digital Enable PF1(RED) LED while(1) { delay_Microsecond(1000000); // Wait 1 sec GPIOF->DATA ^= 0x02; // Toggle output value of PF1(RED LED) } } void delay_Microsecond(uint32_t time) { SYSCTL->RCGCTIMER |= 0x02; // Enable and provide a clock to TIMER1 TIMER1->CTL = 0x00; // Timer 1-A is disabled. TIMER1->CFG = 0x04; // Select 16 bit timer TIMER1->TAMR = 0x2; // Set periodic timer mode TIMER1->TAILR = 16 - 1; // 0 to 15 = 16 ticks for 1 microsecond TIMER1->ICR = 0x1; // Clear interrupts from TIMER1(Unnecessary here?) TIMER1->CTL = 0x01; // Timer 1-A enabled for(int i = 0;i < time; i++){ while((TIMER1->RIS & 0x1) == 0x00); TIMER1->ICR = 0x1; // Clear Timer 1-A interrupt every 16 ticks } }