用AD1的通道15对温度传感器的上电压进行采样,通过WATCH窗口查看AD转换的结果发现采样的值总是一个大的范围的抖动,百思不得其解 温度传感的部分的电路如下 :AD部分的驱动如下:/****************ADC配置函数******************************/
/*********************************************************/
void ConfigADC()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); //打开ADC1的时钟
ADC_InitStruct.ADC_Mode=ADC_Mode_Independent; /*!< Configures the ADC to operate in independent or
dual mode.
This parameter can be a value of @ref ADC_mode */
ADC_InitStruct.ADC_ScanConvMode=DISABLE; /*!< Specifies whether the conversion is performed in
Scan (multichannels) or Single (one channel) mode.
This parameter can be set to ENABLE or DISABLE */
ADC_InitStruct.ADC_ContinuousConvMode=DISABLE; /*!< Specifies whether the conversion is performed in
Continuous or Single mode.
This parameter can be set to ENABLE or DISABLE. */
ADC_InitStruct.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None; /*!< Defines the external trigger used to start the analog
to digital conversion of regular channels. This parameter
can be a value of @ref ADC_external_trigger_sources_for_regular_channels_conversion */
ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right; /*!< Specifies whether the ADC data alignment is left or right.
This parameter can be a value of @ref ADC_data_align */
ADC_InitStruct.ADC_NbrOfChannel=1; /*!< Specifies the number of ADC channels that will be converted
using the sequencer for regular channel group.
This parameter must range from 1 to 16. */
ADC_Init(ADC1,&ADC_InitStruct);
ADC_RegularChannelConfig(ADC1,ADC_Channel_11,1,ADC_SampleTime_239Cycles5);
ADC_Cmd(ADC1,ENABLE);
//初始化时开启一次自动校准
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
// Start ADC1 calibaration
ADC_StartCalibration(ADC1);
// Check the end of ADC1 calibration
while(ADC_GetCalibrationStatus(ADC1));
}
AD的时钟为12M RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
通道11的对应端口为PC1:GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AIN; //模拟输入
GPIO_Init(GPIOC,&GPIO_InitStruct);
读取AD结果int16_t TemperSample() //要关闭外部中断,启动一次AD转换,计算出温度值
{
uint16_t T_Vaule,i;
// ADC_Cmd(ADC1,ENABLE);
ADC_SoftwareStartConvCmd(ADC1,ENABLE); //开启一次软件触发AD
while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
T_Vaule=ADC_GetConversionValue(ADC1); //取回转换值
return(T_Vaule);
} |