void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Period = (250-1); //96K
TIM_TimeBaseStructure.TIM_Prescaler = (3-1);
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;//?????,??????pwm???
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Output Compare Active Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1; //???pwm1????
TIM_OCInitStructure.TIM_Pulse=125; //???????
//????????????????,?????????
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High; //?????????
TIM_OCInitStructure.TIM_OCNPolarity=TIM_OCNPolarity_Low; //?????????
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//???????
TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;//???????
TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Set; //???????
TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset;//??????????
TIM_OC3Init(TIM4, &TIM_OCInitStructure); //??TIM_OCInitStruct???????????TIMx
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); //??TIMx?CCR3????????
TIM_ARRPreloadConfig(TIM4, ENABLE); //??TIMx?ARR????????
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE); //??TIMx??
TIM_CtrlPWMOutputs(TIM4, ENABLE);
}
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//GPIO_Mode_Out_PP;//;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource8,GPIO_AF_TIM4);
|