我的IR接收器在P1.1上发送数字数据。我已经配置了定时器,如果有下降或上升沿,则会触发中断。我想知道如何获得边缘之间的实际时间。之后我想把它们保存在阵列中。
主:
// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
//1mhz = 0.000001
BCSCTL1 = CALBC1_1MHZ; // load calibrated data
DCOCTL = CALDCO_1MHZ;
//Define Outputs
P1DIR = green_led+red_led+IR_Send;
P2DIR = LED1+LED2+LED3;
//Define Inputs
P1DIR &= ~IR_Recv;
//Set IR_Recv as input for Timer (TA0.CCI0A)
P1SEL |= BIT1;
//Timer_A using SMCLK/8 = 0.000008s and Continuous mode
TACTL = TASSEL_2 | MC_2 | ID_3;
// falling edge and rising edge capture mode, CCI0A, enable IE
CCTL0 = CM_3 | CCIS_0 | CAP | CCIE;
//Enter LPM and enable Global Interrupts
__bis_SR_register(CPUOFF + GIE);
中断例程:
//gets called when falling or rising edge is detected on IR_Recv
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
if(edgeCount < 10){
rxData[edgeCount] = TACCR0;
TACCR0 = 0;
}
edgeCount++;
P2OUT ^= LED2;
//Clear interrupt Flag
TACCTL0 &= ~CCIFG;
//go back to LPM
__bic_SR_register_on_exit ( CPUOFF );
}
答案 0 :(得分:1)
要获得两个捕获事件之间的时间差(以刻度表示),只需让计时器继续运行而不重置它,然后减去捕获的时间戳:
NULL
即使定时器计数器发生溢出,该计算也是正确的。