Dm00119042 PWM Resolution Enhancement Through A Dithering Technique For Stm32 Advancedconfiguration Generalpurpose and Lite Timers Stmicroelectronics
Dm00119042 PWM Resolution Enhancement Through A Dithering Technique For Stm32 Advancedconfiguration Generalpurpose and Lite Timers Stmicroelectronics
Dm00119042 PWM Resolution Enhancement Through A Dithering Technique For Stm32 Advancedconfiguration Generalpurpose and Lite Timers Stmicroelectronics
Application note
PWM resolution enhancement through a dithering technique for
STM32 advanced-configuration, general-purpose and lite timers
Introduction
Nowadays power-switching electronics exhibit remarkable performance enhancements, and
switching frequencies are constantly increasing to meet the requirements of modern power-
conversion systems. This presents increasing challenges in the field of control techniques.
Digitally-controlled Pulse Width Modulation (PWM) generators make a trade-off between
switching frequency and duty-cycle fine tuning. Achieving both high resolution and high
switching frequency implies that the control circuitries operate at high frequencies.
This application note presents a dithering technique that enhances the PWM resolution
while keeping the same switching frequency and operating frequency for the control
circuitry.
The PWM dithering technique demonstration covered in this application note uses one of
the STM32 16-bit general purpose timers. The implementation and the associated
X-CUBE-PWM-DITHR software expansion for STM32Cube both target the NUCLEO-
F302R8 Nucleo board, but can easily be tailored to any of the STM32 MCUs, regardless of
the hardware development environment.
Contents
3 Demonstration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1 Demonstration hardware environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 Demonstration firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.1 Utilization of the microcontroller hardware resources . . . . . . . . . . . . . . 15
3.2.2 Demonstration firmware description through flowcharts . . . . . . . . . . . . 16
3.2.3 Firmware Footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Experimental results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.3.1 Dithering effect on PWM resolution enhancement . . . . . . . . . . . . . . . . . 18
3.3.2 Low-pass filter dimensioning considerations . . . . . . . . . . . . . . . . . . . . . 19
4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
List of tables
List of figures
PWM resolution
Timer clock = PWM frequency × 2
1.2.1 Introduction
To overcome the trade-off presented above, the PWM dithering technique proposes to
enhance the PWM resolution while maintaining a constant PWM frequency and without any
need to increase the timer clock frequency.
Theoretically, any desired number of added resolution bits is possible. Practically, the added
resolution bits are limited to a few ones, in particular due to the firmware footprint
exponential increase (See Section 3.2.3: Firmware Footprint).
1.2.2 Concept
The PWM dithering is done by making the PWM duty-cycle not constant any more. The idea
is to adjust the duty-cycle by one LSB with a repetitive pattern over a given number of
consecutive PWM periods. An external low-pass filter is used to cut the extra switching
components and the result consists in an added DC offset with a resolution less than one
duty cycle LSB. The duty-cycle adjustment can be made following two possible approaches.
• The first approach consists in subtracting one LSB from the periods where a duty-cycle
adjustment should be made. In this case the DC offset is going to be negative.
• The other way is by adding one LSB to the periods where a duty-cycle adjustment
should be made. In this case the DC offset is going to be positive.
The added DC offset is proportional to the ratio between the number of PWM periods where
duty-cycle adjustment is made, divided by the number of consecutive PWM periods making
one PWM dithering pattern. Whatever the duty-cycle adjustment pattern, the obtained ratio
is always a positive sub-one fractional value. With this dithering technique, external devices
can be controlled with a resolution higher than the original PWM resolution.
The resulting PWM resolution is given by the below formula:
PWM Dither_Resolution
N PWM_Adjustment_Periods = 2
7 /6%GXW\F\FOHDGMXVWPHQW
2QH3:0GLWKHULQJSDWWHUQ
PDGHRIFRQVHFXWLYH3:0SHULRGV
069
For 1-added-resolution-bit PWM dithering, four patterns are possible. These patterns are
listed in Table 2 below.
The first and the last patterns give a fine tuning of one full LSB but this is already achievable
by hardware. The second and the third patterns are the ones targeted by the PWM dithering
technique. These patterns allow to control the PWM resolution by a smaller step (½ LSB).
For 1-added-resolution-bit PWM dithering, the two dithering-effect patterns are similar. Any
one of them can be used for achieving the ½ LSB fine-tuning step.
Table 3. PWM dithering pattern for generating 1/2 LSB dither effect (highest ripple magnitude)
Average
DC1 DC2 DC3 DC4 DC5 DC6 DC7 DC8
value
4/8 = ½ LSB 1 1 1 1 0 0 0 0
4/8 = ½ LSB 0 0 0 0 1 1 1 1
Table 4. PWM dithering pattern for generating 1/2 LSB dither effect
(lowest ripple magnitude)
Average
DC1 DC2 DC3 DC4 DC5 DC6 DC7 DC8
value
4/8 = ½ LSB 1 0 1 0 1 0 1 0
Carefully selecting the PWM dithering pattern helps reducing the output ripple induced by
the PWM dithering technique. Nevertheless, a slight degradation of the output ripple margin
is unavoidable. Table 5 lists the PWM dithering patterns that produce the lowest output
ripple for each average value achievable with a 3-added-resolution-bit PWM dithering
implementation.
0 LSB 0 0 0 0 0 0 0 0 None
1/8 LSB 0 0 0 0 0 0 0 1 Highest
2/8 LSB
3/8 LSB
0
0
0
0
0
0
1
1
0
0
0
1
0
0
1
1
↓
4/8 LSB 0 1 0 1 0 1 0 1 Lowest
5/8 LSB
6/8 LSB
0
0
1
1
0
1
1
1
1
0
0
1
1
1
1
1
↑
7/8 LSB 0 1 1 1 1 1 1 1 Highest
1 LSB 1 1 1 1 1 1 1 1 None
3:0
3:0
7,0B$55
7,0B&&5;
&RXQWHU
&RXQWHU
W
069
N
Table_size = 2 × 2
When using a 16-bit timer, the table of patterns should be a table of half-words, otherwise if
using a 32-bit timer, the table of patterns should be a table of words.
The firmware routines that initialize the peripherals needed for PWM dithering should
respect the following recommendations.
• The DMA should be configured to transfer values from the table of patterns located in
SRAM memory into the timer channel register. The DMA source address increment
should be configured in circular mode in order to roll over when it reaches the end of
the table of patterns and points again on the table top. The DMA destination address
should be fixed. The DMA half-transfer interrupt and transfer complete interrupt should
be enabled for the relevant channel (on some products it is called stream). The
firmware example provided with this application note presents a proposal on how to
configure the DMA for implementing the PWM dithering technique. For further details
about DMA modes and configurations, refer to the microcontroller corresponding
reference manual.
• The timer should have its time-base initialized with appropriate values in order to
generate the required PWM frequency. The “preload” function should be activated for
the timer channel register. The timer should be configured to send DMA requests
following each update event.
• The dithering patterns should be calculated based on the desired duty-cycle. If the
timer possible hardware resolution for duty-cycle is x-bit length and the desired dither-
effect added resolution is y-bit length, the duty-cycle passed to the dithering routines
should be (x+y)-bit length. The DMA half-transfer and transfer-complete interrupts can
be used as triggers for dithering patterns calculation routines. These DMA interrupts
are useful to know which part of the table of patterns is used by DMA and which one is
free and can be updated by the dithering patterns generation routines. The
demonstration firmware provided with this application note shows an example of
possible implementation of dithering patterns generation routines. This example, while
being functional, might be further enhanced in order to improve performance (e.g.
reduce footprint, reduce CPU load, etc.). Figure 3 illustrates how to assemble the
STM32 MCU features together in order to implement the required timer PWM output
resolution.
'0$
'RXEOHEXIIHUPRGHWKURXJK+7LQWHUUXSW
³[´RU³[/6%´
069
3 Demonstration
&
5
/RZSDVV
ILOWHU¶VRXWSXW
06Y9
The low-pass filter cut-off frequency calculation is based on several parameters including
the PWM period. For this demonstration example the cut-off frequency is around 160 kHz
(R = 1 kOhm, C = 1 nF). Our PWM switching frequency is around 1.125 MHz which is
definitely in the rejected bandwidth of the low-pass filter. The resistor and the capacitor
components should be mounted as close as possible to the timer output pin on the Nucleo
board. If the low-pass filter is placed on a daughter board, the connections between the
daughter board and the Nucleo board should be as short as possible in order to avoid
distortion of the filter parameters and the resulting waveform (e.g. switching noise may
become more important due to the inductance of the connection wires).
ŝƚŚĞƌŝŶŐƉĂƚƚĞƌŶƐĐĂůĐƵůĂƚŝŽŶĨŽƌ
ƚŚĞĨŝƌƐƚƉĂƌƚŽĨƚŚĞƚĂďůĞ
WĞƌŝƉŚĞƌĂůƐŝŶŝƚŝĂůŝnjĂƚŝŽŶ
/ĚůĞƐƚĂƚĞ
069
Before initializing the timer and DMA peripherals and start refreshing the timer channel
register, the first half of the table of patterns should be initialized. The following table
updates are handled by the DMA interrupt handler. The peripherals initialization function is
described in the flowchart Figure 6.
ZĐŽŶĨŝŐƵƌĂƚŝŽŶ;ĞŶĂďůĞƐDϭ͕'W/KĂŶĚd/DϭĐůŽĐŬƐͿ
'W/KƉŽƌƚĐŽŶĨŝŐƵƌĂƚŝŽŶ;W͘ϬϵŝƐƵƐĞĚĂƐd/DϭĐŚĂŶŶĞůϭŽƵƚƉƵƚͿ
DĐŽŶĨŝŐƵƌĂƚŝŽŶнEs/ĐŽŶĨŝŐƵƌĂƚŝŽŶ
d/DϭĐŽŶĨŝŐƵƌĂƚŝŽŶ
069
After completing the peripherals initialization, the CPU goes into an infinite loop. Dithering
patterns calculation task is handled by the DMA interrupt service routine (ISR) following
each DMA half-transfer or transfer-complete interrupt. The flowchart in Figure 7 describes
the DMA interrupt handler function (ISR).
'0$WUDQVIHUFRPSOHWH
'0$KDOIWUDQVIHULQWHUUXSW
LQWHUUXSW
ŝƚŚĞƌŝŶŐƉĂƚƚĞƌŶƐĐĂůĐƵůĂƚŝŽŶĨŽƌƚŚĞƐĞĐŽŶĚ ŝƚŚĞƌŝŶŐƉĂƚƚĞƌŶƐĐĂůĐƵůĂƚŝŽŶĨŽƌƚŚĞĨŝƌƐƚƉĂƌƚ
ƉĂƌƚŽĨƚŚĞƚĂďůĞнŝŶƚĞƌƌƵƉƚĨůĂŐĞƌĂƐĞ ŽĨƚŚĞƚĂďůĞнŝŶƚĞƌƌƵƉƚĨůĂŐĞƌĂƐĞ
069
Figure 8. Dithering effect applied on the rising slope of the triangular waveform
Figure 9. Low-pass filter cut-off frequency effect on the dithering technique efficiency
4 References
5 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.