贴出我的程序,单通的,测直流信号还可以,800mv 1KHz的正弦信号误差十分大,只显示0.1XX(XX是两个变化很快的数字),求解是什么原因?怎么解决?
#include "msp430g2553.h"
#include "12864_1.h"
unsigned int s1 = 0;
unsigned char i = 0;
unsigned char flag = 0;
float sum = 0;
float voltage = 00.000;
unsigned char s2[]={"error"};
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_1; // input A1
ADC10AE0 |= 0x02; // PA.1 ADC option select
P2DIR |=BIT3+BIT4;
init_lcd();
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
voltage = (3560/1023)*sum/1000;
if((flag == 1)&&(voltage < 3.3))
{
wr_float(0,0,voltage);
// delay_ms(200);
flag = 0;
}
if(voltage >= 3.3)
{
clr_lcd(0,0,6);
wr_string(0,0,s2);
}
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
i++;
s1 = ADC10MEM;
sum = sum + s1;
if(i == 10)
{
i = 0;
sum = sum/10;
flag = 1;
}
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
此帖出自
小平头技术问答
一周热门 更多>