打印
[STM8]

STM8S定时器的预分频问题

[复制链接]
2045|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xufangjian1989|  楼主 | 2014-4-11 16:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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);
}
沙发
mmuuss586| | 2014-4-11 19:21 | 只看该作者
or through the trigger controller when configured in trigger reset mode

使用特权

评论回复
板凳
xufangjian1989|  楼主 | 2014-4-11 20:37 | 只看该作者
mmuuss586 发表于 2014-4-11 19:21
or through the trigger controller when configured in trigger reset mode

可是程序中并没有设置成trigger reset mode啊?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

16

帖子

1

粉丝