TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430f149AD采集电压不准问题

我用的TI提供fet140_adc12_06的程序,稍微改了一下,加了一个MEM5然后再将MEMO,MEM1,MEM2,MEM3,MEM5的值转换为实际电压值的计算函数,我的P6.0  P6.3 都没有施加电压,通电后电压都是0.4,其他的施加了电压,分别是P6.1电压为3v,P6.2电压为1.1V,P6.5为0.09V(这些值为万用表测量的),AD转换的结果为P6.0 P6.1 p6.3都为1.7v左右(不准确),P6.2为1.5v(准确),P6.5为0.09v(准确),P6.1明明施加了电压,AD转换显示却与没有施加电压的P6.0和 P6.3 一样,求大神帮忙,捣鼓两天了。程序如下:

#include <msp430x14x.h>
#define uint unsigned int#define uchar unsigned char#define Num_of_Results 4
uint Curr_Volt2;
void Trans_val1(uint Hex_Val);
uint soildianya0;
uint soildianya2;
uchar soildianya1[15]={"太阳能电压="};
uchar soildianya;
void zhongduan(void);
uchar ta[4];
uchar shuzi1[]={"0123456789."};
unsigned long caltmp2;

static unsigned int A0results[Num_of_Results]; // These need to be global in
static unsigned int A1results[Num_of_Results]; // this example. Otherwise, the
static unsigned int A2results[Num_of_Results]; // compiler removes them because
static unsigned int A3results[Num_of_Results]; // they are not used
static unsigned int A5results[Num_of_Results];

void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6SEL = 0x1F; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time
// to avoid overflow of results
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1
ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2
ADC12MCTL3 = INCH_3;
ADC12MCTL5 = INCH_5+EOS; // ref+=AVcc, channel = A3, end seq.
ADC12IE = 0x08; // Enable ADC12IFG.3
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
_BIS_SR(LPM0_bits + GIE); // Enter LPM0, Enable interrupts
}

#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0;

A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared
A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared
A2results[index] = ADC12MEM2; // Move A2 results, IFG is cleared
A3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared
A5results[index] = ADC12MEM5;
index = (index+1)%Num_of_Results; // Increment results index, modulo; Set Breakpoint here
if(index == 3) {
uchar j;
unsigned long sum1 = 0;

for(j = 0; j <Num_of_Results; j++)
{
sum1 += A5results[j];
}
sum1 >>= 2; //除以32 Trans_val1(sum1);
}
}

void Trans_val1(uint Hex_Val)
{
// unsigned long caltmp2;
//uint Curr_Volt2;
uchar t3;
//uchar ta[4];
caltmp2 = Hex_Val;
caltmp2 = (caltmp2 << 5) + Hex_Val; //caltmp = Hex_Val * 33
caltmp2 = (caltmp2 << 3) + (caltmp2 << 1); //caltmp = caltmp /10
Curr_Volt2 = caltmp2 >> 12; //Curr_Volt = caltmp / 2^n
ta[0] = Curr_Volt2 / 100; //Hex->Dec变换
//t3 = Curr_Volt2 – (ta[0] * 100);
ta[2] = Curr_Volt2 %100/10;
ta[3] = Curr_Volt2 %10;
ta[1] = shuzi1[10];
soildianya0=ta[0]* 10+ta[2];
soildianya=(soildianya0<<2)+(soildianya0<<1);
soildianya1[11]=shuzi1[soildianya/100];
soildianya1[12]=shuzi1[soildianya%100/10];
soildianya1[13]=shuzi1[10];
soildianya1[14]=shuzi1[soildianya%100%10];
soildianya2=(soildianya/100*10)+(soildianya%100/10);
}

user5767411:

补充:sum1 >>= 2;是除以4不是32,忘改了

灰小子:

回复 user5767411:

你施加电压是通过什么电路提供的电压?电压源,还是电阻分压?

电阻分压要注意阻抗匹配

没施加电压的io是接到了GND还是悬空?悬空会受周围电磁环境影响

user5767411:

回复 灰小子:

感谢您为我解答,我是通过电阻分压提供的电压,没施加电压的IO是悬空的,什么都没接,测单片机引脚电压时用万用表直接在引脚上测的,分压电阻上的电压也测了,跟引脚上的一样,为了排除程序错误导致AD测量不准的原因,用AD测不同引脚电压时都是用的同一个程序,例如测P6.1引脚电压时,直接将上述的A5results[j]改为A1results[j] 即可,一共三个引脚施加电压(P6.1 ,P6.2, P6.5),同一个程序P6.1,P6.5都能准确测出,P6.2就是不行,我刚刚把没有修改过的fet140_adc12_06的程序试了一下在watch中查看A1results的值,跟我这个修改过的程序里面的A1results值一样

灰小子:

回复 user5767411:

前面说了,外部电路用电阻分压时注意阻抗匹配。用万用表测电阻不会出现问题是因为万用表的抗比较大

赞(0)
未经允许不得转载:TI中文支持网 » msp430f149AD采集电压不准问题
分享到: 更多 (0)