高中生
最后登录1970-1-1
在线时间 小时
注册时间2014-8-14
|
楼主 |
发表于 2016-9-18 14:05:48
|
显示全部楼层
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Period=10000;//设置100ms一次TIM2比较的周期
TIM_TimeBaseStructure.TIM_Prescaler=719;//系统主频72M,这里分频720,相当于100K的定时器2时钟
TIM_TimeBaseStructure.TIM_ClockDivision=0x0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;//下面详细说明
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_Pulse=5000;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;//如果是PWM1要为Low,PWM2则为High
TIM_OC2Init(TIM2,&TIM_OCInitStructure);
TIM_Cmd(TIM2,ENABLE);
TIM_InternalClockConfig(TIM2);
TIM_OC2PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_UpdateDisableConfig(TIM2,DISABLE);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode=DISABLE;//关闭通道扫描模式
ADC_InitStructure.ADC_ContinuousConvMode=DISABLE;//注意不要使用持续转换模式,否则只要触发一次,
//后续的转换就会永不停歇(除非CONT清0),这样第一次以后的ADC,就不是由TIM2_CC2来触发了
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T2_CC2;//配置TIM2_CC2为触发源
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel=1;
ADC_Init(ADC1,&ADC_InitStructure);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//配置时钟(12MHz),在RCC里面还应配置APB2=AHB时钟72MHz,
ADC_RegularChannelConfig(ADC1,ADC_Channel_8,1,ADC_SampleTime_1Cycles5);
ADC_Cmd(ADC1,ENABLE);ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);//Start Calibration register
while(ADC_GetCalibrationStatus(ADC1));//waiting for finishing the calibration
ADC_ExternalTrigConvCmd(ADC1,ENABLE);
//设置外部触发模式使能(这个“外部“其实仅仅是相//对于ADC模块的外部,实际上还是在STM32内部)
}
看到这两个设置,但是ADC值,是怎么读出来的 |
|