AN4539
Application note
HRTIM cookbook
Introduction
Among STM32 microcontrollers, STM32F334xx products have been developed to address
market segments requiring digital signals with highly accurate timings, and especially digital
power conversion applications. Among them:
•
digital power supplies;
•
lighting;
•
uninterruptible Power Supplies;
•
solar inverters;
•
wireless chargers.
The STM32F334xx microcontrollers feature an High Resolution Timer (HRTIM) peripheral
that can generate up to 10 signals and is able to handle a large variety of input signals for
control, synchronization or protection purposes. Its modular architecture allows to address
most of conversion topologies and multiple parallel converters, with the possibility to
reconfigure them during run-time.
At first glance, reading the STM32F334 reference manual, this peripheral may appear
complex, mostly because of the large control register set. To complement this extensive
description, we have prepared an additional document that includes quick-start informations
and a collection of examples.
In its first section, this cookbook aims to show that HRTIM programming is simple. The
environment (the kitchen...) setup is first explained, followed by a number of simple
examples given for understanding by practicing. These basic cases are provided to
introduce step by step the timer features and to provide programming guidelines. This
section should be read extensively by people not familiar with the HRTIM.
The second part is a collection of converter recipes to be used when starting a new design,
either to pick up a ready-made code example, or to get ideas and programming tricks when
dealing with a topology not described in this document. It shall be noted however that this
cookbook does not cover the converter design itself (control techniques and components
dimensioning) which may be described in dedicated application notes.
Each example is provided with a brief converter description when necessary (topology and
connections to the MCU), the control waveform(s) and a code snippet. These snippets (and
the equivalent code done based the STM32 HAL library) can be downloaded from
www.st.com.
Table 1. Applicable products
Type
Microcontrollers
Part numbers and product categories
STM32F334xx
June 2014
DocID026506 Rev 1
1/33
www.st.com
Contents
AN4539
Contents
1
Getting the kitchen ready . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1
1.2
1.3
1.4
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Hardware set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Tools set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
STM32F334 and HRTIM set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.1
1.4.2
1.4.3
1.4.4
1.4.5
1.4.6
System clock initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
HRTIM initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
HRTIM DLL initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
HRTIM I/Os initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Other peripherals initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
HRTIM functionality check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2
HRTIM operating principles basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1
2.2
2.3
2.4
Single PWM generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Generating multiple PWMs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Generating PWM with other timing units and the master timer . . . . . . . . 15
Arbitrary waveform generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3
4
Voltage mode dual buck converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Voltage mode buck converter with synchronous
rectification and fault protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Non-inverting buck-boost converter . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Transition mode power factor controller . . . . . . . . . . . . . . . . . . . . . . . 27
Other examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5
6
7
8
2/33
DocID026506 Rev 1
AN4539
List of tables
List of tables
Table 1.
Table 2.
Table 3.
Applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Timer resolution and min PWM frequency for fHRTIM = 144 MHz. . . . . . . . . . . . . . . . . . . 13
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
DocID026506 Rev 1
3/33
3
List of figures
AN4539
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
Figure 12.
Figure 13.
Figure 14.
Figure 15.
Figure 16.
Basic PWM generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
HRTIM configuration for generating basic PWM signals . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Generation of multiple PWM signals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
PWM generation with the master timer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Arbitrary waveform generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Voltage-mode buck converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
VM buck waveforms, including ADC sampling and interrupts . . . . . . . . . . . . . . . . . . . . . . 20
PWM interrupts and register update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Voltage mode buck with synchronous rectification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Buck operation with FAULT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Non-inverting buck-boost converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Buck-boost operating mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Buck-boost converter operating waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Transition mode PFC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Transition mode PFC operation at Ton max and during over-current. . . . . . . . . . . . . . . . . 28
Transition mode PFC operation at Toff max and Toff min . . . . . . . . . . . . . . . . . . . . . . . . . 29
4/33
DocID026506 Rev 1
AN4539
Getting the kitchen ready
1
Getting the kitchen ready
In this section, we’ll make sure to have all the necessary ingredients ready before starting,
so that we can concentrate on the HRTIM programming only.
The following documents are to be considered as reference:
•
•
•
•
•
•
•
STM32F334x4/x6/x8 Datasheet
STM32F334x4/x6/x8 Errata sheet
RM0364 Reference manual STM32F334xx advanced ARM
®
-based 32-bit MCUs
UM1733: Getting Started with STM32F334 Discovery Kit
UM1735: Discovery kit for STM32F3 series - with STM32F334C8 MCU
UM1736: Getting started with STM32F334 Discovery software development tools
AN4885: High brightness LED dimming using the STM32F3348 Discovery
A preliminary reading of the HRTIM chapter in the RM0364 will be useful.
1.1
Prerequisites
Before enjoying the flavors of the HRTIM, let’s list the prerequisites. It is expected from the
reader basic C programming skills and minimal experience on MCUs and development
environments, as well as a theoretical background on switched mode power supplies.
Control strategies and components dimensioning details are exceeding the scope of this
application note, they are available in a vast literature.
For the sake of simplicity, this cookbook only considers logic signals or analog voltages
conditioned to be directly handled by the MCU, so as to be voltage level agnostic. However
some references are made to external components interfacing and side effects from power
switchings, whenever the timer or MCU has some features to handle them.
Last, it is reminded that it is required to have power applications operated by skilled
technical personnel to avoid risks of electrical shocks, burns or even death, should the
STM32F334 and the HRTIM may be used in applications with hazardous voltage levels.
1.2
Hardware set-up
The STM32F334 Discovery board is a very affordable tool and is the best option to start
(and go on) experimenting with the HRTIM (order code: STM32F3348-DISCO). It includes
the programming interface and a USB cable is the only necessary additional material to
have the chip programmed and debugged. All I/Os are made available on 2.54 mm spaced
pins so that it can also be connected to a perfboard / stripboard / breadboard. The kit also
features two power converters: an inverted buck for LED drive and a low-voltage buck/boost
converter with independent inputs and outputs.
An oscilloscope is mandatory, eventually coupled with a logic analyzer for the configurations
where more than 4 channels must be monitored. To visualize the subtle high-resolution
steps, the oscilloscope has to have a sampling rate above 1GS/s at least with an option to
have interleaved acquisition so as to increase the timing accuracy above the 217ps timer
resolution.
DocID026506 Rev 1
5/33
32