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); } |
从零开始操作STM8寄存器(风驰iCreate奉献)
【中文资料】初学STM8库函数的中文帮助软件
绝对经典的中文STM8学习手册,淘宝上学习板资料,友情大放送!
【原创教程】风驰iCreate独家开源STM8 27个例程和10多万字的pdf教程
STM8的LCD1602 4线驱动,为什么不工作
【精华资料】由零开始开发STM8
STM8S 的触摸库是如何在主程序中查询键的呢、
【精华资料】STM8的C语言编程1-14讲完整版
【精品教程】STM8系列单片机入门教程系列
STM8 第一次进中断不准【悬赏问答】
RE:STM8S定时器的预分频器问题
RE:STM8S定时器的预分频器问题
TIM2_ARRPreloadConfig(ENABLE);
下次更新事件发生时,分频值生效,使能预加载了,第一个是立即生效的