【LaunchPad学习】 MSP430G2452电容测量问题
[复制链接]
想通过P1.1测量电容量,可是代码跑起来后,在不同时刻meas_cnt的值却始终为0。
使用官方的msp430g2xx2_pinosc_01.c代码测量到的meas_cnt也始终为0.p1.0,p1.6的LED不断闪烁。
上面是修改后的代码,在meas_cnt处设置了断点。
-
//****************************************************************************** // MSP430G2xx2 Demo - Capacitive Touch, Pin Oscillator Method, 1 button // // Description: Basic 1-button input using the built-in pin oscillation feature // on GPIO input structure. PinOsc signal feed into TA0CLK. WDT interval is used // to gate the measurements. Difference in measurements indicate button touch. // LEDs flash if input is touched. // // ACLK = VLO = 12kHz, MCLK = SMCLK = 1MHz DCO // // MSP430G2xx2 // ----------------- // /|\| XIN|- // | | | // --|RST XOUT|- // | | // | P1.1|<--Capacitive Touch Input 1 // | | // // Brandon Elliott/D. Dang // Texas Instruments Inc. // November 2010 // Built with IAR Embedded Workbench Version: 5.10 //******************************************************************************
#include "msp430g2452.h" unsigned int meas_cnt; void measure_count(void) { TA0CTL = TASSEL_3+MC_2; // TACLK, cont mode TA0CCTL1 = CM_3+CCIS_2+CAP; // Pos&Neg,GND,Cap } void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO P2SEL = 0x00; // No XTAL measure_count(); P1DIR &= ~ BIT1; // P1.1 is the input used here P1SEL &= ~ BIT1; P1SEL2 |= BIT1; TA0CTL |= TACLR; // Clear Timer_A TAR while(1) { meas_cnt = TACCR0; // Save result } } // End Main
复制代码
[ 本帖最后由 littleshrimp 于 2012-6-16 13:43 编辑 ]
|