STM32 - 定时器的设定 - 基础 01.1 - Repetition counter

时间:2024-03-23 22:23:52

前言:Repetition counter是一个STM32增强的计数器功能,有很多用途,本文尝试进行简单阐述:

我们理解为,就是定时器溢出再增加一个倍率rate 的控制。注意是倍率,也就是如果是定时1S,那么设定N为1,那么就是N+1=2倍


Section 14.3.1: Time-base unit describes how the update event (UEV) is generated with respect to the counter overflows/underflows. It is actually generated only when the repetition counter has reached zero. This can be useful when generating PWM signals.

我们简单的任务,UEV的产生就是计数器记到位就好了,其实,由于RC(Repetition Counter)的存在,正在事件的产生是由RC计数到0才真正开始。这一点对产生PWM信号非常重要,因为PWM信号的脉宽需要调整,RC要精确控制就必须硬件上具备这个功能。

STM32 - 定时器的设定 - 基础 01.1 - Repetition counter

This means that data are transferred from the preload registers to the shadow registers

也就是说,数据从preload reg 到 Shadow reg(包括下面三种情况)

(TIMx_ARR auto-reload register,

TIMx_PSC prescaler register,

but also TIMx_CCRx capture/compare registers in compare mode

)

every N+1 counter overflows or underflows, where N is the value in the TIMx_RCR repetition counter register.

每次溢出记一次数的话,达到RCR的N值,这时候才真正将UEV产生出来。同时更新shadow registers

The repetition counter is decremented:

At each counter overflow in upcounting mode,

At each counter underflow in downcounting mode,

At each counter overflow and at each counter underflow in center-aligned mode.

Although this limits the maximum number of repetition to 128 PWM cycles, it makes it possible to update the duty cycle twice per PWM period. When refreshing compare registers only once per PWM period in center-aligned mode, maximum resolution is 2xTck, due to the symmetry of the pattern.

STM32 - 定时器的设定 - 基础 01.1 - Repetition counter

The repetition counter is an auto-reload type; the repetition rate is maintained as defined by the TIMx_RCR register value (refer to Figure 72).

STM32 - 定时器的设定 - 基础 01.1 - Repetition counter

When the update event is generated by software (by setting the UG bit in TIMx_EGR register) or by hardware through the slave mode controller, it occurs immediately whatever the value of the repetition counter is and the repetition counter is reloaded with the content of the TIMx_RCR register.

STM32 - 定时器的设定 - 基础 01.1 - Repetition counter

In center-aligned mode(理解为从低到高计数然后紧接着从高到低计数), for odd values (奇数的时候计数两次)of RCR, the update event occurs either on the overflow or on the underflow depending on when the RCR register was written and when the counter was started. If the RCR was written before starting the counter, the UEV occurs on the overflow. If the RCR was written after starting the counter, the UEV occurs on the underflow. For example for RCR = 3, the UEV is generated on each 4th overflow or underflow event depending on when RCR was written.


参考:

STM32 定时器中TIM_RepetitionCounter 作用详解

https://blog.csdn.net/longgyue/article/details/80161380