下面是程序
TIM8定时器好像是工作了,但,PWM无输出
void IO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_PinSource0|GPIO_PinSource1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7|GPIO_PinSource8,GPIO_AF_TIM8);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource0|GPIO_PinSource1,GPIO_AF_TIM8);
}
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
TIM_DeInit(TIM8);
TIM_TimeBaseStruct.TIM_Period = 7000;
TIM_TimeBaseStruct.TIM_Prescaler = 0;
TIM_TimeBaseStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStruct);
}
void PWM_Configuration(void)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM8_BDTRInitStruct;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC2Init(TIM8, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC3Init(TIM8, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM8, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM8, TIM_OCPreload_Enable);
TIM8_BDTRInitStruct.TIM_OSSRState = TIM_OSSRState_Enable;
TIM8_BDTRInitStruct.TIM_OSSIState = TIM_OSSIState_Enable;
TIM8_BDTRInitStruct.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM8_BDTRInitStruct.TIM_DeadTime = 0x10;
TIM8_BDTRInitStruct.TIM_Break = TIM_Break_Disable;
TIM8_BDTRInitStruct.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM8_BDTRInitStruct.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM8, &TIM8_BDTRInitStruct);
TIM_ARRPreloadConfig(TIM8, ENABLE);
TIM_ClearITPendingBit(TIM8,TIM_IT_Update);
TIM_ITConfig(TIM8,TIM_IT_Update,ENABLE);
TIM_CtrlPWMOutputs(TIM8, ENABLE);
TIM_CCxCmd(TIM8,TIM_Channel_2,TIM_CCx_Enable);
TIM_CCxNCmd(TIM8,TIM_Channel_2,TIM_CCxN_Enable);
TIM_CCxCmd(TIM8,TIM_Channel_3,TIM_CCx_Enable);
TIM_CCxNCmd(TIM8,TIM_Channel_3,TIM_CCxN_Enable);
} |