现象:我现在用AD采集电压值,但是电压从3.3V增加到4.7V了,可是AD采集的值还是没有太大变化,基本在0x0800左右变化,换算成相应的模拟值,一直在1.0V左右。
我的AD用的是STM32内部的12位的,其具体设置:
希望大家给些思路,大概可能由哪些原因造成的,(我的这个程序之前没有问题,只是在原来的程序上新加了部分功能,可是AD这部分程序都没有变化)谢谢。
- void init_adcl(void)
- {
- ADC_InitTypeDef adc_obj;
- GPIO_InitTypeDef gpio_obj;
- DMA_InitTypeDef dma_obj;
- NVIC_InitTypeDef NVIC_InitStructure;
- //peirph clock
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
- //NVIC config
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- /*DMA1 channel1 configuration*/
- DMA_DeInit(DMA1_Channel1); //½«DMA µÄͨµÀ1 ¼Ä´æÆ÷ÖØÉèΪȱʡֵ
- dma_obj.DMA_PeripheralBaseAddr = (u32)&ADC1->DR; //DMAÍâÉèADC »ùµØ
- dma_obj.DMA_MemoryBaseAddr = (u32)&adc_value;//DMA ÄÚ´æ»ùµØÖ·
- dma_obj.DMA_DIR = DMA_DIR_PeripheralSRC;//ÄÚ´æ×÷ΪÊý¾Ý´«ÊäµÄÄ¿µÄµØ
- dma_obj.DMA_BufferSize = ADC1_DATA_SIZE;//DMA ͨµÀµÄDMA »º´æµÄ´óС
- dma_obj.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÍâÉèµØÖ·¼Ä´æÆ÷
- dma_obj.DMA_MemoryInc = DMA_MemoryInc_Enable; //ÄÚ´æµØÖ·¼Ä´æÆ÷µÝÔö
- dma_obj.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //Êý¾Ý¿í¶ÈΪ16 λ
- dma_obj.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//Êý¾Ý¿í¶ÈΪ16 λ
- dma_obj.DMA_Mode = DMA_Mode_Normal; //Õý³£¹¤×÷ģʽ
- // dma_obj.DMA_Mode = DMA_Mode_Circular;
- // dma_obj.DMA_Priority = DMA_Priority_High;
- dma_obj.DMA_Priority = DMA_Priority_VeryHigh;
- dma_obj.DMA_M2M = DMA_M2M_Disable;
-
- DMA_Init(DMA1_Channel1 , &dma_obj);
-
- /*Enable DMA1 channel1*/
- DMA_Cmd(DMA1_Channel1 , ENABLE);
- DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); //ÅäÖÃDMA·¢ËÍÍê³Éºó²úÉúÖжÏ
- //periph clcok
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
- //gpio config
- gpio_obj.GPIO_Pin = GPIO_Pin_8;
- gpio_obj.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOB , &gpio_obj);
- ADC_DeInit(ADC1);//½«ÍâÉè ADC1 µÄÈ«²¿¼Ä´æÆ÷ÖØÉèΪȱʡֵ
- /*ADC1 configuration*/
- adc_obj.ADC_Mode = ADC_Mode_Independent; //ADC ¹¤×÷ģʽ:ADC1 ºÍADC2¹¤×÷ÔÚ¶ÀÁ¢Ä£Ê½
- adc_obj.ADC_ScanConvMode = DISABLE; //½ûֹɨÃèģʽ
- adc_obj.ADC_ContinuousConvMode = ENABLE; //Ä£Êýת»»¹¤×÷ÔÚÁ¬Ðøת»»Ä£Ê½
- adc_obj.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //Íⲿ´¥·¢×ª»»¹Ø±Õ
- adc_obj.ADC_DataAlign = ADC_DataAlign_Right;//ADC Êý¾ÝÓÒ¶ÔÆë
- adc_obj.ADC_NbrOfChannel = 1;
- ADC_Init(ADC1 , &adc_obj);
- RCC_ADCCLKConfig(RCC_PCLK2_Div8); //9Mhz
- //ÉèÖÃÖ¸¶¨ADC µÄ¹æÔò×éͨµÀ£¬ÉèÖÃËüÃǵÄת»¯Ë³ÐòºÍ²ÉÑùʱ¼ä
- ADC_RegularChannelConfig(ADC1 , ADC_Channel_9 , 1 , ADC_SampleTime_1Cycles5);
- /*Enable ADC1 DMA*/
- ADC_DMACmd(ADC1 , ENABLE);
- /*Enable ADC3*/
- ADC_Cmd(ADC1 , ENABLE);
- /*¸´Î»Ð£×¼¼Ä´æÆ÷*/
- ADC_ResetCalibration(ADC1);
- while(ADC_GetResetCalibrationStatus(ADC1));
-
- ADC_StartCalibration(ADC1);
- while(ADC_GetCalibrationStatus(ADC1));
-
- ADC_SoftwareStartConvCmd(ADC1 , ENABLE);
- }
复制代码 |
ADC_SampleTime_1Cycles5
评分
查看全部评分
评分
查看全部评分
STM32F103RB PB8没有AD映射。
之前没问题的时候就是这个采样周期,我也试过将周期改大,但效果还是一样的
您说的对,谢谢!