问题描述:简单的通过串口打印verF的数字,发现波动很大。请用过的兄弟帮忙
(怀疑是AD初始化有问题,还发现不同的转换周期对基准的数值影响很大,但PA0正常)
测试实际的输出:
PA1 AD:1984,Vref:0,TempSensor:1440,Vbat:1552
PA1 AD:2045,Vref:0,TempSensor:1429,Vbat:1527
PA1 AD:2008,Vref:86,TempSensor:1416,Vbat:1544
PA1 AD:2027,Vref:0,TempSensor:1387,Vbat:1512
PA1 AD:1994,Vref:55,TempSensor:1440,Vbat:1691
PA1 AD:2007,Vref:75,TempSensor:1375,Vbat:1663
PA1 AD:2047,Vref:0,TempSensor:1367,Vbat:1663
PA1 AD:1999,Vref:0,TempSensor:1359,Vbat:1663
PA1 AD:2015,Vref:0,TempSensor:1343,Vbat:1647
使用的AD初始化源代码:
uint16_t RegularConvData_Tab[4];
void ADC1_DMA_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // ????GPIOA ?±??
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
ADC_DeInit(ADC1);//ADC1 ??????
DMA_DeInit(DMA1_Channel1); /* DMA1 Channel1 Config */
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;//???è???·
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)RegularConvData_Tab;//???????·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //???è×÷????????????
DMA_InitStructure.DMA_BufferSize = 4;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //???è???·??±?
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //???????·????
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //???????í????16??
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //???????í????16??
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_Cmd(DMA1_Channel1, ENABLE);/* DMA1 Channel1 enable */
ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular); /* Enable ADC_DMA */
ADC_DMACmd(ADC1, ENABLE);
ADC_StructInit(&ADC_InitStructure);//??????ADC?á??
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //?????è??
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Backward; //ADC???¨?è·??ò
ADC_Init(ADC1, &ADC_InitStructure);
ADC_ChannelConfig(ADC1, ADC_Channel_0 , ADC_SampleTime_239_5Cycles); /* Convert the ADC1 Channel 11 with 239.5 Cycles as sampling time */
ADC_VrefintCmd(ENABLE);
ADC_ChannelConfig(ADC1, ADC_Channel_Vrefint ,ADC_SampleTime_239_5Cycles);
ADC_TempSensorCmd(ENABLE);
ADC_ChannelConfig(ADC1, ADC_Channel_TempSensor ,ADC_SampleTime_239_5Cycles);
ADC_VbatCmd(ENABLE);
ADC_ChannelConfig(ADC1, ADC_Channel_Vbat ,ADC_SampleTime_239_5Cycles);
ADC_GetCalibrationFactor(ADC1); /* ADC Calibration */
ADC_Cmd(ADC1, ENABLE); /* Enable ADCperipheral[PerIdx] */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); /* Wait the ADCEN falg */
ADC_StartOfConversion(ADC1); /* ADC1 regular Software Start Conv */
} 在转载自
|