我有两个计时器工作正常。 初始化 B1计时器的代码为:
/* Configure TimerB1 to generate 100 Hz Clock */
void jiffyClockInitTimerB1(void){
Timer_B_initUpModeParam param = {0};
param.clockSource = TIMER_B_CLOCKSOURCE_SMCLK;
param.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_48; // 16uS / 62.5 KHz
param.timerPeriod = 624; //625 ticks = 10 mS / 100 Hz
param.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_ENABLE;
param.captureCompareInterruptEnable_CCR0_CCIE = TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
param.startTimer = true;
Timer_B_initUpMode(TIMER_B1_BASE, ¶m);
HWREG16(TIMER_B1_BASE + OFS_TBxCTL) &= ~(TBIE); // Turn off overflow (goes to zero) IRQ
}
这种编译和工作正常。 现在我要使用 B2计时器、让此代码使其运行:
void sineWaveInitTimerB2(void){
Timer_B_initUpModeParam param = {0};
param.clockSource = TIMER_B_CLOCKSOURCE_SMCLK;
param.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_12; // SMCLK at 3 MHz 4uS / 250.5 KHz
param.timerPeriod = 71; // 284uS --> 3.52 KHz / 8 =440 Hz
param.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_ENABLE;
param.captureCompareInterruptEnable_CCR0_CCIE = TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
param.startTimer = true;
Timer_B_initUpMode(TIMER_B2_BASE, ¶m);
HWREG16(TIMER_B2_BASE + OFS_TBxCTL) &= ~(TBIE); // Turn off overflow (goes to zero) IRQ
}
当我尝试编译这个代码时、我收到一个未定义 TIMER_B2_BASE 的错误。
我在顶部添加了这个宏、源文件:
#define TIMER_B2_BASE (*(volatile uint16_t *)((uint16_t) 0x0400 +(0x0000)))
现在编译、但是看不到计时器运行(我看不到 IRQ)。
有什么想法为什么有有效的宏用于 timer_B0_BASE 和 timer_B1_base 而不是 timer_B2_base ?
FWiw、这个中断处理程序是一个用于定时器1的中断处理程序副本。 它看起来像:
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER2_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER2_B0_VECTOR)))
#endif
void TIMER0_B2_ISR(void){
// to DEBUG, pulse the P2.2 bit so we can see when we take timer interrupts and see how long it takes
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN3);
// Important safety tip: the CCIFG interrupt flag is automatically reset when the TBxCCR0 IRQ is serviced
// Timer_B_clearTimerInterrupt(TIMER_B0_BASE);
HWREG16(TIMER_B2_BASE + OFS_TBxCCTL0) &= ~(CCIFG | COV); // COV is a safety
HWREG16(TIMER_B2_BASE + OFS_TBxCTL) &= ~TBIFG; // "counter went to zero" interrupt flag, saf
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN3); // exit timer irq DEBUG
}
请注意、使用编译没有问题
#pragma vector=TIMER2_B0_vector
语句。