本帖最后由 gesper3187 于 2017-4-6 14:26 编辑
用msp430f5438A的P6.4管脚,模拟输入A4,初始化后,使用ADC转换,不管是A4接地(实际也测量为0左右)还是采集实际电压,采集回来的AD值在2000左右。
void Init_Timer_A1()
{
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 30000; //设置时钟中断周期为30ms
//TA1CCTL2 = OUTMOD_7 + CCIE; // CCR2 set/reset Interrupt enabled
TA1CTL = TASSEL_1 + MC_1 + TACLR; // ACLK, upmode, clear TAR
}
void InitADC12()
{
P6SEL |= 0x10; // Enable P6.4 as A/D channel input
ADC12CTL0 = ADC12ON + ADC12SHT0_2; // Turn on ADC12, set sampling time, 16ADC12CLK cycles
ADC12CTL1 = ADC12SHP + ADC12CONSEQ_0 + ADC12SSEL_2; //MEM0,IFG0
// Use sampling timer, single time single channel,MCLK=4M
ADC12MCTL0 = ADC12SREF_2 + ADC12INCH_4; // ref+ = VeREF+, ref- = AVSS, channel = A4
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER_A0(void)
{
//P6OUT ^= 0x01; // Toggle触发 P11.0
ADC12IE = ADC12IE0;
ADC12CTL0 |= ADC12SC + ADC12ENC; //开始ADC转换
while((ADC12IFG & 0x0001) == 0);
Point_now = ADC12MEM0;
__no_operation(); |