1556 views|0 replies

3836

Posts

19

Resources
The OP
 

MSP430 capture device is simple and practical [Copy link]

/***************************************************************** //Function: Use the capture of timer A to measure the pulse width of the pulse signal // // // MSP430F449 // ----------------- // /|\| XIN|- // | | | 32kHz // --|RST XOUT|- // | | // | P1.5/ACLK|---+ // | | | // | P2.0/TA2|<--+ // | | // | | //Description: ACLK needs to be divided by 8 (4K) and used as the external pulse to be captured; //MCLK=SMCLK=8M; *****************************************************************/ #include     int pwm_start,pwm_end,pwm_wide=0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR = 0x20; // P1.5 output P1SEL = 0x20; // P1.5 output ACLK P2SEL|=BIT0; //P2 .0 CCI2A SCFI0 |= FN_4; SCFQCTL = 121; // (121+1) ×32768 *2= 7.99Mhz FLL_CTL0=DCOPLUS+OSCCAP1; //MCLK=SMCLK=8M FLL_CTL1 |= FLL_DIV_8; //ACLK needs to be divided by 8, ACLK=4K TACCTL2 =CAP+CM_3+CCIS_0+SCS +CCIE; //Capture mode, capture both rising and falling, select CCI2A, synchronize, disconnect during capture //Capture input select: 0 - CCI2A TACTL = TASSEL_2 + MC_2; //SMCLK=8M,L continuous counting mode _EINT(); //Enable total interrupt LPM0; _NOP(); pwm_wide=pwm_end-pwm_start; [size =4] while(1); } // Timer_A3 Interrupt Vector (TAIV) handler #pragma vector=TIMERA1_VECTOR __interrupt void Timer_A(void) { switch(TAIV) {case 2:break; case 4: if(TACCTL2 & CCI) pwm_start=CCR2; else pwm_end=CCR2; // pwm_wide=pwm_end-pwm_start; break; case 10: break; } LPM0_EXIT; } Test method: [size=4 ]In the debug environment, observe pwm_end and pwm_start in the watch window, and then subtract them! I calculated it. In the example given, the theoretical value pwm_end-pwm_start=976 The observed result is 978, which is still a little bit wrong. It may be due to the value of the crystal oscillator, and the rounding in the calculation is a little bit wrong. /size]

This post is from Microcontroller MCU
 

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list