完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4; GPIO_Init(GPIOC, GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_4; GPIO_Init(GPIOF, GPIO_InitStructure); //ADC Init RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE); ADC_Structinit( ADC_InitStructure); /* Calibration procedure */ ADC_VoltageRegulatorCmd(ADC1, ENABLE); ADC_VoltageRegulatorCmd(ADC2, ENABLE); vTaskDelay(10); ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Differential); ADC_StartCalibration(ADC1); ADC_SelectCalibrationMode(ADC2, ADC_CalibrationMode_Differential); ADC_StartCalibration(ADC2); while(ADC_GetCalibrationStatus(ADC1) != RESET ); calibration_value1 = ADC_GetCalibrationValue(ADC1); while(ADC_GetCalibrationStatus(ADC2) != RESET ); calibration_value2 = ADC_GetCalibrationValue(ADC2); /* ADC Dual mode configuration */ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_RegSimul; ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular; ADC_CommonInitStructure.ADC_TwoSamplingDelay = 10; ADC_CommonInit(ADC1, ADC_CommonInitStructure); /* */ ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;//ADC_ContinuousConvMode_Enable; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_5;//Event5 = TIM4_CC4 event Event12 = TIM4_TROG event ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_RisingEdge; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable; ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable; ADC_InitStructure.ADC_NbrOfRegChannel = 4; ADC_Init(ADC1, ADC_InitStructure); ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; ADC_Init(ADC2, ADC_InitStructure); /* ADC1 regular channel7 and channel8 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 6, ADC_SampleTime_61Cycles5);//与ADC2共用CH6,错时使用 ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 7, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 8, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 2, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_3, 3, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_4, 4, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_9, 5, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 6, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_5, 7, ADC_SampleTime_61Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_6, 8, ADC_SampleTime_61Cycles5);//与ADC1共用CH6,错时使用 ADC_SelectDifferentialMode(ADC1, ADC_Channel_1, ENABLE); //差分通道 ADC_SelectDifferentialMode(ADC1, ADC_Channel_3, ENABLE); ADC_SelectDifferentialMode(ADC1, ADC_Channel_5, ENABLE); ADC_SelectDifferentialMode(ADC1, ADC_Channel_7, ENABLE); ADC_SelectDifferentialMode(ADC2, ADC_Channel_1, ENABLE); //差分通道 ADC_SelectDifferentialMode(ADC2, ADC_Channel_3, ENABLE); ADC_SelectDifferentialMode(ADC2, ADC_Channel_9, ENABLE); ADC_SelectDifferentialMode(ADC2, ADC_Channel_5, ENABLE); /* Configures the ADC DMA */ ADC_DMAConfig(ADC1, ADC_DMAMode_Circular); /* Enable the ADC DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 and ADC2 */ ADC_Cmd(ADC1, ENABLE); ADC_Cmd(ADC2, ENABLE); /* wait for ADC1 ADRDY */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY)); /* wait for ADC2 ADRDY */ while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_RDY)); vTaskDelay(10); //DMA Init RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC_CDR_ADDRESS; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) ADCDualConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 300*4; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, DMA_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( NVIC_InitStructure); DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); DMA_Cmd(DMA1_Channel1, ENABLE); //TIM4 Init RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* TIM4 configuration ------------------------------------------------------*/ /* Time Base configuration */ TIM_TimeBaseStructInit( TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 24000-1; //72M/3K = 24K TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, TIM_TimeBaseStructure); /* TIM4 channel1 configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; TIM_OCInitStructure.TIM_Pulse = 0x0FFF; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC4Init(TIM4, TIM_OCInitStructure); TIM_SelectOutputTrigger(TIM4, TIM_TRGOSource_OC4Ref); /* TIM4 counter enable */ TIM_Cmd(TIM4, ENABLE); /* TIM4 main Output Enable */ TIM_CtrlPWMOutputs(TIM4, ENABLE); ADC_StartConversion(ADC1); 采集直流数据,采集变化非常大。采集值有100左右的变化。 另外,如果不添加 ADC_StartConversion(ADC1);,采集是不会开始的,不知道哪里没有配置好。 |
|
相关推荐
1个回答
|
|
据你描述的情况,STM32F302差分ADC采集跳动的原因可能是由于采样时引脚电压波动较大导致的。有几种可能的解决方法如下:
1. 提高采样时的引脚稳定性:可以通过使用电源滤波电容、增加电源稳压器以及减少电源线的干扰等方式来提高采样时引脚的稳定性。 2. 添加外部参考电压:如果ADC的参考电压不稳定,可以考虑使用外部参考电压源,并将其连接到ADC的VREF+引脚上,以提供更稳定的参考电压。 3. 调整采样频率:可以尝试降低采样频率,以减少引脚之间的干扰。 4. 调整ADC转换模式:可以尝试使用不同的转换模式,例如单次转换模式或连续转换模式,以找出最适合你的应用的方式。 5. 检查硬件连接问题:确保差分ADC的信号线正确连接,并且没有松动或接触不良的问题。 通过以上几种方法,你可以尝试解决STM32F302差分ADC采集跳动的问题。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1621 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1546 浏览 1 评论
980 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
686 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1599 浏览 2 评论
1865浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
648浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
517浏览 3评论
534浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
506浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 11:00 , Processed in 0.738748 second(s), Total 82, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号