我使用的是STM32F103VCT6
VDD,VDDA,VREF+都是直接连接到板上的3.3V供电,实测在3.27V
只有一个需要测量的外部信号,连接到PA2
使用ADC1+DMA方式采样
以下是我的ADC和DMA的初始化代码
PA2引脚已经配置为Analog IN,不是floating
ADC的时钟频率为7M
void ADC_DMA_Init (void)
{
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 10;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 4, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 5, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 6, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 7, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 8, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 9, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 10, ADC_SampleTime_239Cycles5);
ADC_DMACmd(ADC1, ENABLE);
//DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4001244C;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&AD_Value[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 10;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE);
DMA_Cmd(DMA1_Channel1,ENABLE);
ADC_Cmd (ADC1, ENABLE);
ADC_TempSensorVrefintCmd( ENABLE );
p=0;
while(p<10000)p++;
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1)==SET)__NOP();
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1)==SET)__NOP();
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
以下是采样以后的结果
外部信号加的是1.38V的直流信号
AD_Value[10]是对AD_Value[0]~[7]进行平均值运算以后的结果
根据这样的话,VREF+ = 1.38/(0x436)*(0xFFF) = 5.24V !!!
而内部的1.2V基准电压,仅仅只有 1.38/(0x436)*(0x336)=1.05V !!!
请问这样为什么会出现这样奇怪的结果? |
|