各位,小弟在使用STM32的TIM3 TROG触发ADC1的测试中,发现串口输出的ADC值会由大到小,由小到大这样重复变化,类似一个波动效果。 [img]file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\735340838\QQ\WinTemp\RichOle\K0O4EYN3]R9ZEI(XNPX$0@F.png[/img] 用的是战舰stm32开发板,采用TIM3 500ms触发一次ADC转换,没有用DMA,使用的是ADC中断中读取ADC转化值,具体代码为: static void ADC1_Mode_Config(void)//ADC1_Mode_Config(uint32_t ADC_ConvertedVal) { // DMA_InitTypeDef DMA_InitInstructure; ADC_InitTypeDef ADC_InitStruct; NVIC_InitTypeDef NVIC_InitStructure ; RCC_ADCCLKConfig(RCC_PCLK2_Div6); ADC_DeInit(ADC1); ADC_InitStruct.ADC_Mode = ADC_Mode_Independent; ADC_InitStruct.ADC_NbrOfChannel = 1; ADC_InitStruct.ADC_ContinuousConvMode = DISABLE; ADC_InitStruct.ADC_ScanConvMode = DISABLE; ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO; ADC_InitStruct.ADC_DataAlign =ADC_DataAlign_Right; ADC_Init(ADC1,&ADC_InitStruct); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0) ; NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0 ; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 9 ; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ; NVIC_Init(&NVIC_InitStructure); ADC_ExternalTrigConvCmd(ADC1,ENABLE); ADC_RegularChannelConfig(ADC1,ADC_Channel_11,1,ADC_SampleTime_55Cycles5); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); ADC_Cmd(ADC1,ENABLE); ADC_ResetCalibration(ADC1); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); } void TIM3_Configration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct; NVIC_InitTypeDef NVIC_InitStruct; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStruct.TIM_Period = 4999; TIM_TimeBaseInitStruct.TIM_Prescaler = 7199; TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct); TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update); //??TRGO??????????? TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable); TIM_Cmd(TIM3,ENABLE); } /** * @brief This function handles ADC1 and ADC2 global interrupts requests. * @param None * @retval None */ #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) void ADC1_IRQHandler(void) #else void ADC1_2_IRQHandler(void) #endif { if(ADC_GetITStatus(ADC1, ADC_IT_EOC)) { ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); ADC_ConvertedValue = ADC_GetConversionValue(ADC1); sSysFlagBit.CANRx_G = TRUE; } } 大伙帮分析分析看,是否哪里配置的还有问题,多谢!!! |
串å£æ¾ç¤ºADCå¼
WARSHIP_CORE_V2.0_SCH.pdf
下载1.04 MB, 下载次数: 15, 下载积分: ST金币 -1
æè°STM32F103ZET6åçå¾
TIM_CtrlPWMOutputs(TIM3,ENABLE);
还有:ADC设置里好像缺少一句(你需要让定时器的上升沿或下降沿来触发ADC):
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
现已解决,这个TROG不同于CCx触发,不需要开启TIM的PWM,是板子上面的ADC端口有其他信号干扰了