Hello,
I am trying to understand how to use Timer A0 with the Driver Library APIs by toggling an LED (P1.0) every 15 seconds. The code runs, but the interrupt is never triggered. I think I want to use Up Mode with compare to trigger an interrupt every 15 seconds. Here is the code that sets up the clock:
UCS_initClockSignal(UCS_FLLREF, UCS_REFOCLK_SELECT, UCS_CLOCK_DIVIDER_1); // 32.768kHz UCS_initClockSignal(UCS_ACLK, UCS_REFOCLK_SELECT, UCS_CLOCK_DIVIDER_16); // 32.768kHz / 16 = 2.048kHz UCS_initFLLSettle(UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ, UCS_MCLK_FLLREF_RATIO); // 8MHz
The way I calculated the time for the interrupt is: 65535 / 15 = 4369, where 15 is the number of seconds after an interrupt should occur. The result would be the compare value. Here is the code for configuring the timer:
// Configure timer Timer_A_initUpModeParam upModeParam = {0}; upModeParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK; upModeParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; upModeParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; upModeParam.timerClear = TIMER_A_DO_CLEAR; upModeParam.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE; upModeParam.startTimer = false; Timer_A_initUpMode(TIMER_A0_BASE, &upModeParam); Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0); // Initialize compare mode Timer_A_initCompareModeParam compModeParam = {0}; compModeParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0; compModeParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE; compModeParam.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE; compModeParam.compareValue = COMPARE_VALUE; Timer_A_initCompareMode(TIMER_A0_BASE, &compModeParam); // Start timer upModeParam.startTimer = true;
I added a counter so that the LED would toggle once the condition is satisfied. Here is the code I have for the interrupt handler:
#pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER_A0(void) { if (timerA_cntr == 1) { GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); timerA_cntr = 0; } else { timerA_cntr++; } }
Here is the code for the main loop:
// Stop the watchdog timer WDT_A_hold(WDT_A_BASE); // Initialize clocks init_clock(); // Initialize GPIO init_gpio(); // Initialize Timer A init_timer_a(); __enable_interrupt(); while (1) { // Enter Low-power Mode 3 __bis_SR_register(LPM3_bits); }
Can anyone offer suggestions of where I am going wrong?
Anson