STM32 - 定时器基础应用说明 - 02 - The preload feature of the timer registers - 预制值和精确同步

The preload feature in the context of the STM32 timer peripheral, refers to the duplication of some timer registers or some timer control bit-fields. As the content of some timer registers and some control bit-fields impacts directly the waveforms outputted by the timer channels,

the update of the content of those registers and control bit-fields should be perfectly synchronized with the timer “update event” triggered next to a new counting-cycle start. This tight synchronization would be practically impossible to achieve, if those registers and control bit-fields were not Preload.

说的很在理,如果要精确同步的话,必须先预制值。


When a timer register features the preload capability, two physical instances of that timer register exist:

• The active register instance (also called the shadow register instance): its content is used by the timer peripheral logic to generate the timer channel outputted waveforms.

The preload register instance: this is the register instance accessed by the software when the preload feature of the concerned register is enabled. If the preload feature is turned off as shown in Figure 5, there are two main characteristics to highlight:

STM32 - 定时器基础应用说明 - 02 - The preload feature of the timer registers - 预制值和精确同步

The preload register instance looks as inexistent

• Any write access to the concerned register by software is performed on the active register instance. If the preload feature is enabled as shown in Figure 6, the two characteristics to highlight are:

STM32 - 定时器基础应用说明 - 02 - The preload feature of the timer registers - 预制值和精确同步

• Any access to the concerned register is performed on the preload register instance while the content of the active register instance is not changed.

• As soon as an “update event” is generated within the timer peripheral, the content of the preload register instance is transferred to the active register instance immediately. The content of the preload register is transferred in perfect synchronization with the “update event”, in other words, it is in perfect synchrony with the new counting cycle corresponding to a new cycle in the outputted waveform.

The preload feature is available for:

The auto-reload timer register (TIMx_ARR) 主动装载寄存器

The timer prescaler register (TIMx_PSC) (cannot be turned off) 预分频

The timer channel registers (TIMx_CCRy) 通道比较器

The CCxE and CCxNE control bit-fields within the TIMx_CCER timer register 通道使能

The OCxM control bit-field within the TIMx_CCMRn timer registers.输出比较模式

The preload feature can be of big interest when outputting a PWM signal on a certain timer channel. The channel output level depends on the continuous comparison between the 1 timer counter value and the 2 TIMx_CCRy timer channel register value, this is why any change to the timer channel register may induce an immediate timer channel output level change.

As a consequence(结果), writing directly to the channel register in the middle of a PWM period may generate spurious (错误的)waveforms. To overcome this problem, the preload feature should be enabled for the concerned timer channel register. When the preload feature is enabled, any write access is made to the channel preload register instance while the channel active register instance remains unchanged. There is no perturbation (担心)on the ongoing PWM period. As soon as an “update event” is generated within the timer, the preload register instance content is transferred into the active register instance. The active register instance is used during the next PWM period to carry the comparison operation and to define the new duty cycle ratio.

In summary, the preload feature guarantees that no spurious waveforms are generated while accessing the timer registers and control bit-fields that have direct impact on the timer channels output; especially in the middle of a waveform output cycle.