Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 217260

Forum Post: TM4C1230E6PM: TivaWare Timer for Interrupts

$
0
0
Part Number: TM4C1230E6PM Tool/software: Hi, Im trying to make a timer which periodically triggers an interrupt on a TM4C1230E6PM. Here is the minimal example I came up with: // --- Includes #include #include #include #include "inc/hw_memmap.h" #include "driverlib/timer.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" // --- Typedefs typedef void (*pFctHandler)(void); typedef const struct { uint8_t TIMER_NR; uint32_t SYSCTL_TIMER; uint32_t TIMER_BASE; uint32_t TIMER_CFG; uint32_t TIMER_A_OR_B; uint32_t TIMER_INTERVAL_US; uint32_t INT_FLAGS; pFctHandler callbackFct; } timerHW_t; // --- Local Function Prototypes void test_tick(void); // --- Variables timerHW_t tmr = { .TIMER_NR = 0, .SYSCTL_TIMER = SYSCTL_PERIPH_TIMER2, .TIMER_BASE = TIMER2_BASE, .TIMER_CFG = TIMER_CFG_PERIODIC, .TIMER_A_OR_B = TIMER_BOTH, .TIMER_INTERVAL_US = 1000, .callbackFct = test_tick, .INT_FLAGS = TIMER_TIMA_TIMEOUT, }; int main(void) { // Set Clock SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //80MHz SysClk // Enable Interrupts IntMasterEnable(); // Enable the peripheral SysCtlPeripheralEnable(tmr.SYSCTL_TIMER); // Wait for the module to be ready. while(!SysCtlPeripheralReady(tmr.SYSCTL_TIMER)) { } // configure Timer TimerConfigure(tmr.TIMER_BASE, tmr.TIMER_CFG); TimerLoadSet(tmr.TIMER_BASE, tmr.TIMER_A_OR_B, SysCtlClockGet()); // Register the interrupt handler TimerIntRegister(tmr.TIMER_BASE, tmr.TIMER_A_OR_B, tmr.callbackFct); // Start the timer TimerEnable(tmr.TIMER_BASE, tmr.TIMER_A_OR_B); TimerIntEnable(tmr.TIMER_BASE, tmr.INT_FLAGS); while(1) { // do nothing ; } } void test_tick(void) { TimerIntClear(tmr.TIMER_BASE, tmr.INT_FLAGS); // Why is this line needed? TimerLoadSet(tmr.TIMER_BASE, tmr.TIMER_A_OR_B, SysCtlClockGet()); } I have the following problems with this: Why is the line 81 needed? Should the Timer with TIMER_CFG_PERIODIC not reset itself when load 0 is reached? Without this line I'm basically stuck in test_tick() With Line 81 active, I noticed that the Clock Counts between line 78 is inconsistent. Its often around the expected 80 000 000 (80 000 192) but deviates in between it shows [0 (???), 70 000 000, 68 000 000, 79 000 000]. Shouldn't the timer be very exact in how many Clock cycles happen between calls? Thanks for any help in advance!

Viewing all articles
Browse latest Browse all 217260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>