1、使用自带的AD口进行光电管数值的采样,数值最大本来应该是4095的,结果采集进来的时候最大为4880左右,测量了VREF+和VREF-两端的电压为3.28V,光电管最大输入电压3.14V,现在采集能正常变化数值也不会飘,
但AD值采集进来和实际值相差太多,请各位大神帮忙分析看看,光电管电路图如下,采集口为H_PHE_ADC_PC2;还有初始化代码!
void ADC_DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure; //¶¨ÒåDMA³õʼ»¯½á¹¹Ìå
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* DMA1 channel1 configuration */
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //ÍâÉèµØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADStruct.AdBuffer;//ÄÚ´æµØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //dma´«Êä·½Ïòµ¥Ïò
DMA_InitStructure.DMA_BufferSize = (ADC_Channe_SUM * ADC_NUMBER); //ÉèÖÃDMAÔÚ´«Êäʱ»º³åÇøµÄ³¤¶È word
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÉèÖÃDMAµÄÍâÉèµÝÔöģʽ£¬Ò»¸öÍâÉè
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //ÉèÖÃDMAµÄÄÚ´æµÝÔöģʽ£¬
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//ÍâÉèÊý¾Ý×Ö³¤
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //ÄÚ´æÊý¾Ý×Ö³¤
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //ÉèÖÃDMAµÄ´«Êäģʽ£ºÁ¬Ðø²»¶ÏµÄÑ»·Ä£Ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //ÉèÖÃDMAµÄÓÅÏȼ¶±ð
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //ÉèÖÃDMAµÄ2¸ömemoryÖеıäÁ¿»¥Ïà·ÃÎÊ
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); //´ò¿ª20¸ö×Ö½ÚµÄÊý¾ÝÍê³ÉÖжÏ
}
/*************************************************
º¯Êý: void ADC_Config(void)
¹¦ÄÜ: ADC½øÐÐÅäÖÃ
²ÎÊý: ÎÞ
·µ»Ø: ÎÞ
**************************************************/
void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //¶ÀÁ¢¹¤×÷ģʽ
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //ɨÃ跽ʽ
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //Á¬Ðøת»»
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //Íⲿ´¥·¢½ûÖ¹
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //Êý¾ÝÓÒ¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = ADC_Channe_SUM; //ÓÃÓÚת»»µÄͨµÀÊý
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration [¹æÔòģʽͨµÀÅäÖÃ]*/
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_239Cycles5); //µçѹ
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 2, ADC_SampleTime_239Cycles5); //²âÖ½
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 3, ADC_SampleTime_239Cycles5); //ζÈ
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 4, ADC_SampleTime_239Cycles5); //ÉϸÇ
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 5, ADC_SampleTime_239Cycles5); //Íâ½ÓµçÔ´
/* Enable ADC1 DMA [ʹÄÜADC1 DMA]*/
ADC_DMACmd(ADC1, ENABLE);
// RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* Enable ADC1 [ʹÄÜADC1]*/
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
哈哈哈,赚大了!!
一周热门 更多>