STM8S定时器的预分频器问题

2019-07-19 20:25发布

PSCR contains the value which is loaded in the active prescaler register at each UEV (including when the counter is cleared through the UG bit of the TIM1_EGR register or through the trigger controller when configured in trigger reset mode).
A UEV must be generated so that a new prescaler value can be taken into account.

这是摘自手册中的一段话,就是说写入的预分频值要想生效,就必须产生一个更新事件,但是我看了固件库中的有些例子,在定时器初始化时,写入了预分频值,但是就没有置位UG产生更新事件使写入的预分频值生效,这怎么解释啊?下面是两个定时器初始化的例子,一个置位UG,另一个没有:

static void TIM2_Config(void)
{  /* Time base configuration */      
TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 65535);  
/* Prescaler configuration,这里就是置位UG,使得写入的预分频值生效*/
TIM2_PrescalerConfig(TIM2_PRESCALER_2048, TIM2_PSCRELOADMODE_IMMEDIATE);
  
/* Output Compare Active Mode configuration: Channel1 */
  /*    TIM2_OCMode = TIM2_OCMODE_ACTIVE    TIM2_OutputState = TIM2_OUTPUTSTATE_ENABLE    TIM2_Pulse = CCR1_Val    TIM2_OCPolarity = TIM2_OCPOLARITY_HIGH  */  
TIM2_OC1Init(TIM2_OCMODE_ACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);    TIM2_OC1PreloadConfig(DISABLE);  
/* Output Compare Active Mode configuration: Channel2 */  
  /*TIM2_Pulse = CCR2_Val  */   
TIM2_OC2Init(TIM2_OCMODE_ACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH);   TIM2_OC2PreloadConfig(DISABLE);
* /* Output Compare Active Mode configuration: Channel3 */
  /*  TIM2_Pulse = CCR3_Val  */  
TIM2_OC3Init(TIM2_OCMODE_ACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH);  TIM2_OC3PreloadConfig(DISABLE);  TIM2_ARRPreloadConfig(ENABLE);  
  /* TIM2 enable counter */
  TIM2_Cmd(ENABLE);
}

static void TIM2_Config(void)
{  /* Time base configuration 这里就没有置位UG,使得写入的预分频值生效*/
TIM2_TimeBaseInit(TIM2_PRESCALER_1, 999);
* /* PWM1 Mode configuration: Channel1 */  
TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);  TIM2_OC1PreloadConfig(ENABLE);  
/* PWM1 Mode configuration: Channel2 */  
TIM2_OC2Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH);  TIM2_OC2PreloadConfig(ENABLE);
* /* PWM1 Mode configuration: Channel3 */         
TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH);  TIM2_OC3PreloadConfig(ENABLE);
* TIM2_ARRPreloadConfig(ENABLE);   
/* TIM2 enable counter */  
TIM2_Cmd(ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。