问题描述:如果定时器4输出PWM最后稳定在3kHz,当我开启定时器5的时候,定时器4的输出就变了,但我看了TMR4寄存器的值是没有变化的。
/***************************************************************************/
//*******函数名:void TIM4Config(u16 PeriodValue1)
//*******说 明: 定时器4配置
//*******参 数:
//*******返回值:
/***************************************************************************/
void TIM4Config(u16 PeriodValue1)
{
TMR_TimerBaseInitType TMR_TMReBaseStructure;
TMR_OCInitType TMR_OCInitStructure;
/* Compute the prescaler value */
TMR_TMReBaseStructure.TMR_Period = PeriodValue1;
TMR_TMReBaseStructure.TMR_DIV = 999; //36khz
TMR_TMReBaseStructure.TMR_ClockDivision = 0;
TMR_TMReBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR4, &TMR_TMReBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TMR_OCInitStructure.TMR_OCMode = TMR_OCMode_PWM1;
TMR_OCInitStructure.TMR_OutputState = TMR_OutputState_Enable;
TMR_OCInitStructure.TMR_Pulse = PeriodValue1/2;
TMR_OCInitStructure.TMR_OCPolarity = TMR_OCPolarity_High;
TMR_OC1Init(TMR4, &TMR_OCInitStructure);
TMR_OC1PreloadConfig(TMR4, TMR_OCPreload_Enable);
TMR_ARPreloadConfig(TMR4, ENABLE);
/* TMR3 enable counter */
TMR_Cmd(TMR4, ENABLE);
}
/***************************************************************************/
//*******函数名:void TIM5Config(u16 PeriodValue2)
//*******说 明: 定时器5配置
//*******参 数:
//*******返回值:
/***************************************************************************/
void TIM5Config(u16 PeriodValue2)
{
TMR_TimerBaseInitType TMR_TMReBaseStructure;
TMR_OCInitType TMR_OCInitStructure;
/* Compute the prescaler value */
TMR_TMReBaseStructure.TMR_Period = PeriodValue2;
TMR_TMReBaseStructure.TMR_DIV = 999; //36khz
TMR_TMReBaseStructure.TMR_ClockDivision = 0;
TMR_TMReBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR5, &TMR_TMReBaseStructure);
/* PWM1 Mode configuration: Channel2 */
TMR_OCInitStructure.TMR_OCMode = TMR_OCMode_PWM2;
TMR_OCInitStructure.TMR_OutputState = TMR_OutputState_Enable;
TMR_OCInitStructure.TMR_Pulse = PeriodValue2/2;
TMR_OCInitStructure.TMR_OCPolarity = TMR_OCPolarity_High;
TMR_OC2Init(TMR5, &TMR_OCInitStructure);
TMR_OC2PreloadConfig(TMR5, TMR_OCPreload_Enable);
TMR_ARPreloadConfig(TMR5, ENABLE);
/* TMR3 enable counter */
TMR_Cmd(TMR5, ENABLE);
}
打了断点,出问题是再定时器初始化之后 |