工具与软件:
您好!
我误解了 Timer0_A0/A1的含义、并适当地调整了我的问题。
我想帮忙弄清楚为什么 当使用 P1.2作为从外部硬件提供的 TA0CLK 输入时 Timer0_A1 ISR 会无限期触发。 尽管如此、Timer0_A0和 Timer0_A0 ISR 似乎运行正常。
主项目代码已经被简化、所有宏和定义被删除、这是因为它与以下问题无关:
#include "cs.h"
#include "msp430fr5739.h"
void delay_ms(uint16_t _value){ //basic delay function
for (int i = _value; i >= 0; i--){
__delay_cycles(((double)1000000.0 / (double)1000.0));
}
}
volatile uint8_t counter_A0 = 0;
volatile uint8_t counter_A1 = 0;
float test(uint16_t sample_time){
P4OUT |= (BIT0); //turn oscillations on (external circuit, connected to P1.2)
delay_ms(5); //let settle
__bis_SR_register(GIE);
TA0CTL = (TASSEL__TACLK | MC__CONTINUOUS | TACLR | TAIE | CNTL__16);
delay_ms(sample_time);
TA0CTL = (TASSEL__TACLK | MC__STOP); //this line is never reached
__bic_SR_register(GIE);
P4OUT &= ~ (BIT0);//turn oscillations off
uint32_t pulses = (65536 * counter_A1) + TA0R;
return(pulses * (1000.0 / (float)sample_time));
}
void main(void){
WDTCTL = WDTPW | WDTHOLD; //stop watchdog timer
__bic_SR_register(GIE);
P4DIR |= (BIT0); //initiate extrnal control pin
P1DIR &= ~(BIT2); //initiate P1.2 as TA0CLK
P1SEL0 &= ~(BIT2);
P1SEL1 |= (BIT2);
float count_out = test(100);
//do something with count_out
__bis_SR_register(LPM0_bits + GIE); //enable global interrupts and enter LPM0
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void timerA0_ISR(void){
counter_A0++; //incriment counter (working as intended)
}
#pragma vector = TIMER0_A1_VECTOR
__interrupt void timerA1_ISR(void){
counter_A1++; //shouldn't be called? (never clears)
}
有人能解释为什么触发了两个 Timer0 (TA0)向量吗?