改了硬件后,放大器输出为160mV, 我用的MSP430F5438A,想问下各位大大这个ADC模块有什么问题吗,我读取的电压值总是不对,输入电压160mV,换算后应该是270左右,而实际ADC采样到的是700到800,我尝试把ADC12SHT0_2变大,加长采样周期,结果得到的值是1400。。。(难道意思是ADC12SHT0_2采样时间还不够,那这误差也太大了。。1400和270)当我把ADC12CTL2 |= ADC12REFOUT打开时,ADC采到的数又变成了88。
我用的外置基准2.5V,实际测量硬件也是2.5V, 采样通道是P6.4,存储通道式ADC12MEM0,
#include "msp430x54x.h"
void InitADC12()
{
P5SEL = BIT0;
ADC12CTL0 &= ~ADC12ENC;
P6SEL |= 0x10; // Enable P6.4 as A/D channel input
ADC12CTL0 = ADC12ON + ADC12SHT0_2 + ADC12CSTARTADD_0; // Turn on ADC12, set sampling time, 16ADC12CLK cycles
ADC12CTL1 = ADC12SHP + ADC12CONSEQ_0 + ADC12SSEL_2; // Use sampling timer, single time single channel,MCLK=4M
ADC12MCTL0 = ADC12SREF_2 + ADC12INCH_4; // ref+ = VeREF+, ref- = AVSS, channel = A4
//ADC12CTL2 = ADC12REFOUT;
//ADC12IE = ADC12IE0; // Enable ADC12IFG.0
//ADC12CTL0 |= ADC12ENC; // Enable conversions
}
unsigned int read_ad() //开启一次AD转换,并读值
{
unsigned int ad_value;
ADC12CTL0|=ADC12SC + ADC12ENC; //给转换开始脉冲
ADC12CTL0&=~ADC12SC;
while((ADC12CTL1&0X01)==1); //ADC转换忙信号时等待
ad_value=ADC12MEM0; //读取转换结果值
ADC12CTL0 &= ~ADC12ENC;
return ad_value;
}
long read_avg() //数字滤波
{
long ad_avg=0; //滤波次数,滤波累加变量
unsigned int flt_t;
for(flt_t=0;flt_t<500;flt_t++)
{
ad_avg+=read_ad();
}
ad_avg/=500;
return ad_avg;
}
|