*TIM2通道2作为ADC1转换的触发时钟200US转换一次--------------------------------- */ TIM_DeInit(TIM2); //重新将Timer设置为缺省值 TIM_TimeBaseStructure.TIM_Period = 200; //1US*200=200US设置计数溢出大小, TIM_TimeBaseStructure.TIM_Prescaler = 20; //预分频系数为20 /20=1M(1US) TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //设置计数器模式为向上计数模式 TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); //将配置应用到TIM2中 //PWM设置 TIM_OCStructInit(&TIM_OCInitStructure); //设置缺省值 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //PWM模式1输出(PWM2也行) TIM_OCInitStructure.TIM_Pulse = 15; //设置占空比 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //TIM输出比较极性高 (LOW也行) TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //使能输出状态 TIM_OC2Init(TIM2, &TIM_OCInitStructure); //初始化TIM2的2通道 TIM_ARRPreloadConfig(TIM2, ENABLE); //使能TIMx在ARR上的预装载寄存器 TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); //使能TIMx在CCR2上的预装载寄存器 ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 9; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 Regular Channel1 Configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 4, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 5, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 6, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 7, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 8, ADC_SampleTime_41Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 9, ADC_SampleTime_239Cycles5); /* Enable ADC1 */ ADC_TempSensorVrefintCmd(ENABLE);// 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)); ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1's DMA interface */ ADC_Cmd (ADC1, ENABLE); /* Enable ADC1 */ ADC_ExternalTrigConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC1,ENABLE);/* Start ADC1 Software Conversion */ TIM_Cmd(TIM2,ENABLE); TIM_CtrlPWMOutputs(TIM2,ENABLE); //设置TIM2的PWM输出为使能 程序下载后只能转换一次后就不再定时转换了,是不是上面配置有问题,(我是通过DMA传送ADC转换结果的,DMA配置经验证是对的) |
RE:关于定时器2通道2定时触发ADC1转换的程序,程序配置上好像有问题,请大家指教
RE:关于定时器2通道2定时触发ADC1转换的程序,程序配置上好像有问题,请大家指教
回复:关于定时器2通道2定时触发ADC1转换的程序,程序配置上好像有问题,请大家指教
不好意思,我发现问题了,上面程序配置是对的,只是我在主程序中调用出错了,我在主程序中是定时读取AD数据的,定时计数没循环递减造成只读了以便,更改后就正常了。
能把主程序源码发给我看一下吗 我最近做的这个和你的这个项目很像