MDK3.5,JLINK7,RAM,调试STM32F103C8T6,定时器1PWM互补输出缺一路输出,缺这路的管教PA9/USART1_TX/TIM1_CH2 ,其它几路用示波器测得都正确定时器我是这样设置的:
/*************************************************
函数: void TIM1_Configuration(void)
功能: TIM配置 pwm输出
参数: Period, Prescaler , Pulse
返回: 无
**************************************************/
void TIM1_Configuration(uint16_t Period,uint16_t Prescaler, uint16_t Pulse)
{
TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
TIM_BaseInitStructure.TIM_Period =Period; //自动重装载的值
TIM_BaseInitStructure.TIM_Prescaler =Prescaler;//计数器的时钟频率
TIM_BaseInitStructure.TIM_ClockDivision =0;//时钟分频因子 288MHZ
TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;//计
TIM_BaseInitStructure.TIM_RepetitionCounter =0; //重复记数
TIM_TimeBaseInit(TIM1, &TIM_BaseInitStructure);
//TIM1_OC1模块设置(设置1通道占空比)
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //管脚输出模式 PWM2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //输出使能
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = Pulse; //占空长度
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出为负逻辑
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Pulse;
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Period/2;
TIM_OC4Init(TIM1,&TIM_OCInitStructure);
//死区设置
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 0x90; //这里调整死区大小0-0xff
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
} |