C8051F350单片机ADC调试问题,希望高手能分析一下
时间:10-02
整理:3721RD
点击:
ADC采样引脚的输入电压为0V的时候,各个寄存器的值,
![](../imgqa/ele/mcu/mcu-3721rd.com-38148atkibc3uxd0.png)
ADC采样引脚的输入电压为1V的时候,各个寄存器的值,
![](../imgqa/ele/mcu/mcu-3721rd.com-381490jguxilqhvy.png)
ADC采样引脚的输入电压为3V的时候,各个寄存器的值,
![](../imgqa/ele/mcu/mcu-3721rd.com-38150ndu5awudpcm.png)
ADC工作不正常,希望高手分析一下是什么原因。
程序如下:
/*--------------------------ADC初始化程序-------------------------------*/
void ADC0_Init (void)
{
unsigned ADC0_decimation;
REF0CN &= ~0x01; // disable internal vref,启用内部晶振
// REF0CN |= 0x01; // (enable if using internal vref)
ADC0CN = 0x10; // 双极性工作方式,1倍增益输出
// ADC0CN = 0x01; // Bipolar output codes, GAIN=1
// ADC0CF = 0x00; // interrupts upon SINC3 filter output
// and uses internal VREF
// ADC0CF = 0x04; // 电压基准设置为外部
// and uses external VREF
ADC0CF = 0x00;
ADC0CLK = (SYSCLK/MDCLK)-1; // Ideally, MDCLK = 2.4576 MHz(时钟分频)
// Generate MDCLK for modulator.
// program decimation rate for desired OWR
ADC0_decimation = (unsigned long) SYSCLK/ (unsigned long) OWR /
(unsigned long) (ADC0CLK+1)/(unsigned long)128;
ADC0_decimation--;
ADC0DEC = ADC0_decimation;
ADC0BUF = 0x00; // 关闭输入缓冲
ADC0MUX = 0x01; //
// AIN+ => AIN0.0
// AIN- => AIN0.1
ADC0MD = 0x80; // 使能(IDLE Mode)
}
/*---------------------------ADC转换程序-----------------------------*/
void ADC24 (void)
{
unsigned int i,g;
float average;
unsigned char e11,e22,e33,e44;
unsigned int e1,e2,e3,e4;
unsigned long int average1;
// PCA0MD &= ~0x40; // disable watchdog timer
// SYSCLK_Init(); // Initialize system clock to 49 MHz
// PORT7_Init(); // Initialize crossbar and GPIO
// OSCILLATOR_Init (); //晶振初始化
// PORT_Init (); //端口初始化
ADC0_Init();
for(i=0;i<128;i++)
{
sample_array=0;
}
// ADC0_Init(); // 初始化ADC0
// UART0_Init(); // 初始化UART0
EA = 1; // 使能总中断
// printf("\nMeasurements using the 24-bit ADC in C8051F350\n");
// printf("\nCalibrating ...\n");
EIE1 &= ~0x08; // 不使能 ADC0 中断
ADC0MD |= 0x01; // 完全内部校准
while (!AD0CALC); // 等待转换完成
ADC0MD &= ~0x07; // ADC0 为理想模式
// printf("Calibration complete\n\n");
AD0INT = 0; // clear pending sample indication
ADC0MD |= 0x83; // 启动连续转换
while(1) //处理采样值
{
// 捕捉128次采样
// printf ("Collecting 128 samples...\n");
for (i = 0; i < 128; i++)
{
while(!AD0INT); //等待转换完成
AD0INT = 0; //清 AD0 中断标志
// concatenate ADC0 data bytes to form the 24-bit value
ADC_OutputVal = ADC0H;
ADC_OutputVal =ADC_OutputVal<< 16;
ADC_OutputVal += (long)ADC0L + ((long)ADC0M << 8);
sample_array = ADC_OutputVal;
}
}
![](../imgqa/ele/mcu/mcu-3721rd.com-38148atkibc3uxd0.png)
ADC采样引脚的输入电压为1V的时候,各个寄存器的值,
![](../imgqa/ele/mcu/mcu-3721rd.com-381490jguxilqhvy.png)
ADC采样引脚的输入电压为3V的时候,各个寄存器的值,
![](../imgqa/ele/mcu/mcu-3721rd.com-38150ndu5awudpcm.png)
ADC工作不正常,希望高手分析一下是什么原因。
程序如下:
/*--------------------------ADC初始化程序-------------------------------*/
void ADC0_Init (void)
{
unsigned ADC0_decimation;
REF0CN &= ~0x01; // disable internal vref,启用内部晶振
// REF0CN |= 0x01; // (enable if using internal vref)
ADC0CN = 0x10; // 双极性工作方式,1倍增益输出
// ADC0CN = 0x01; // Bipolar output codes, GAIN=1
// ADC0CF = 0x00; // interrupts upon SINC3 filter output
// and uses internal VREF
// ADC0CF = 0x04; // 电压基准设置为外部
// and uses external VREF
ADC0CF = 0x00;
ADC0CLK = (SYSCLK/MDCLK)-1; // Ideally, MDCLK = 2.4576 MHz(时钟分频)
// Generate MDCLK for modulator.
// program decimation rate for desired OWR
ADC0_decimation = (unsigned long) SYSCLK/ (unsigned long) OWR /
(unsigned long) (ADC0CLK+1)/(unsigned long)128;
ADC0_decimation--;
ADC0DEC = ADC0_decimation;
ADC0BUF = 0x00; // 关闭输入缓冲
ADC0MUX = 0x01; //
// AIN+ => AIN0.0
// AIN- => AIN0.1
ADC0MD = 0x80; // 使能(IDLE Mode)
}
/*---------------------------ADC转换程序-----------------------------*/
void ADC24 (void)
{
unsigned int i,g;
float average;
unsigned char e11,e22,e33,e44;
unsigned int e1,e2,e3,e4;
unsigned long int average1;
// PCA0MD &= ~0x40; // disable watchdog timer
// SYSCLK_Init(); // Initialize system clock to 49 MHz
// PORT7_Init(); // Initialize crossbar and GPIO
// OSCILLATOR_Init (); //晶振初始化
// PORT_Init (); //端口初始化
ADC0_Init();
for(i=0;i<128;i++)
{
sample_array=0;
}
// ADC0_Init(); // 初始化ADC0
// UART0_Init(); // 初始化UART0
EA = 1; // 使能总中断
// printf("\nMeasurements using the 24-bit ADC in C8051F350\n");
// printf("\nCalibrating ...\n");
EIE1 &= ~0x08; // 不使能 ADC0 中断
ADC0MD |= 0x01; // 完全内部校准
while (!AD0CALC); // 等待转换完成
ADC0MD &= ~0x07; // ADC0 为理想模式
// printf("Calibration complete\n\n");
AD0INT = 0; // clear pending sample indication
ADC0MD |= 0x83; // 启动连续转换
while(1) //处理采样值
{
// 捕捉128次采样
// printf ("Collecting 128 samples...\n");
for (i = 0; i < 128; i++)
{
while(!AD0INT); //等待转换完成
AD0INT = 0; //清 AD0 中断标志
// concatenate ADC0 data bytes to form the 24-bit value
ADC_OutputVal = ADC0H;
ADC_OutputVal =ADC_OutputVal<< 16;
ADC_OutputVal += (long)ADC0L + ((long)ADC0M << 8);
sample_array = ADC_OutputVal;
}
}