Tool/software: Code Composer Studio
Dear team
The MSP-TS430PN80 target motherboard uses the MSP430F2619 chip with 4M external crystal oscillator.
The timer timerB cannot accurately capture frequencies exceeding 20K.
Please help
void SetupClock() { uint16_t tmpv; BCSCTL1 &= ~XT2OFF; BCSCTL3 |= XT2S_2; do { IFG1 &= ~OFIFG; for (tmpv = 0xff; tmpv > 0; tmpv--); } while((BCSCTL3 & XT2OF) == 1); BCSCTL2 |= SELM_2+SELS; } void Capture_Pos(void)//TIMER_B { TB0CTL |= TBSSEL_2 + ID_0 + MC_2 + TBCLR + TBIE; TBCCTL0 = CM_1+CCIS_1+SCS+CAP+CCIE; } #pragma vector = TIMERB0_VECTOR __interrupt void Timer_B0 (void) { static double Pre_T_Frequency = 0; if(TBCCTL0 & CM0) { T_CaptureNum++; if(T_CaptureNum == 1) { T_cap_count_first = TBCCR0; }else if(T_CaptureNum >= 2) { T_cap_count_second = TBCCR0; if(T_cap_count_second>T_cap_count_first) { T_count_num = T_cap_count_second-T_cap_count_first; }else{ T_count_num = 0xFFFF+T_cap_count_second-T_cap_count_first; } T_Frequency = ((float)4000000)/T_count_num; T_CaptureNum = 0; if(T_Frequency != Pre_T_Frequency) { Pre_T_Frequency = T_Frequency; }else{ close_T_capture(); } } } }