STM32F334 series and G474 series HRTIMCubeMax configuration explanation and four-way complementary full bridge

Foreword

The main purpose of this article is to introduce the related use and configuration process of HRTIM. Compared with ordinary TIM, the most significant feature of HRTIM is that it can multiply the frequency to a maximum of 32 times. For example, F334 can reach 4.68GHZ and G474 can reach 5.44GHZ. This allows the timer to still operate even if it works at a higher frequency. Higher resolution. Therefore, it is mainly used in applications such as digital power supply, lighting, power supplies, solar inverters, radio frequency circuits and wireless charging.

Tools used:

  1. Development module:STM32G474RE
  2. Development environment: STM32CubeMX latest version + Keil5

Basic components of HRTIM

1. Composition

It consists of a master timer and independent timers (Timer A~Timer F). The master timer is generally used to synchronize other independent timers. Why does it need to be synchronized? It should be because each independent timer works independently, and each timer has a certain error, so each timer will not be synchronized at this time. At this time, the main timer can be involved and reset. Independent timer to achieve synchronization purposes.

2. Master Timer:
Based on 16-bit up counter. It can set/reset the output of the timer through 4 comparison units and provide synchronization signals to other independent timer units (Timer A~Timer F). Its main purpose is to enable the timer unit to be controlled by a unique clock source. Full-bridge Buck-Boost digital power supplies are a typical application example where a master timer manages the phase shift between multiple units.

3. Independent timer (Timer A~Timer F):
It can work independently or in conjunction with other timers (including the main timer). Each timer can control two outputs. Output set/reset events can be triggered by the timing unit compare register, or by a main timer event, an event from another timer, or an external event. Two outputs per timer:
1) Support PWM complementary output and add dead time.
2) Add the carrier frequency to the modulated signal.
3) Manage fault events by setting asynchronous outputs to predefined safe levels.

4. External events (can be used for any timer unit)
Programmable polarity and edge validity.
5 events for fast asynchronous mode.
5 events for programmable digital filters.
Implement pseudo-event filtering using blanking and windowing modes.

5. Channels (connect to built-in analog peripherals)
4 trigger signals for ADC converters.
3 trigger signals for DAC converters.
3 for comparators.

6. Protection mechanism
The 5 fault inputs can be combined and linked to any timing unit.
Programmable polarity and edge validity.
The resonant converter is equipped with special time delay protection.

STM32CubeMX HRTIM configuration

Clock source configuration

Clock tree configuration (I use an external 8M crystal oscillator here. If you use the default configuration, it can only reach 150M)

HRTIM configuration
Enable Master Timer
1. Select other suitable independent timers,

3. The TimerE channel 1 and channel 2 are selected. They need to be configured to complement each other later. There is no need to complement each other, just select one channel.

4. The Timer F channel 1 and channel 2 are selected. They need to be configured to complement each other later. There is no need to complement each other, just select one channel.

1.Select the HRTIM tab

2. Set the main timer
3. Select the appropriate frequency multiplier or frequency division number
4. Set the period counter length to get the control frequency

5. Enable preload register

6. Enable update repetition

Interrupts are not turned on here because the frequency is particularly high. Turning on interrupts will affect the normal operation of the program.

Enable independent timer (Timer A~Timer F)

In the same way, select the appropriate frequency multiplier or frequency division number
Set the period counter length to get the control frequency

Step 6 is to configure the reset trigger source. Select here: the timer counter is reset when the main timer cycle event occurs, that is, the main timer is reset when it overflows.

If you want to set the dead zone here, select: dead zone time is inserted between output 1 and output 2

Set the comparison channel. The comparison value here is also limited. You can check the manual for details. If the distance between the two comparison values is too short, there will be problems with the output PWM. Please read the manual for the specific reason. The manual says this, set it within this range. Well, I don’t know exactly why this range exists, and I couldn’t find any relevant documentation.

Enable dead time configuration

Select frequency division coefficient

Set dead time
Is the dead zone on the rising edge or the falling edge

Set effective output frequency
Setting source: reset source, startup source

TimerF has the same configuration, so there won’t be too much repetition.

Next generate the project

After the main function is initialized, call the following code to start the timer output:

HAL_HRTIM_WaveformOutputStart( & amp;hhrtim1, HRTIM_OUTPUT_TE2 + HRTIM_OUTPUT_TE1 + HRTIM_OUTPUT_TF1 + HRTIM_OUTPUT_TF2);
HAL_HRTIM_WaveformCounterStart( & amp;hhrtim1, HRTIM_TIMERID_MASTER + HRTIM_TIMERID_TIMER_E + HRTIM_TIMERID_TIMER_F);

Stop timer output:

HAL_HRTIM_WaveformOutputStop( & amp;hhrtim1, HRTIM_OUTPUT_TE2 + HRTIM_OUTPUT_TE1 + HRTIM_OUTPUT_TF1 + HRTIM_OUTPUT_TF2);
HAL_HRTIM_WaveformCounterStop( & amp;hhrtim1, HRTIM_TIMERID_MASTER + HRTIM_TIMERID_TIMER_E + HRTIM_TIMERID_TIMER_F);

If you need to change the comparator comparison value or reload the value:

//Change the reload value
__HAL_HRTIM_SETPERIOD( & amp;hhrtim1, HRTIM_TIMERINDEX_MASTER, _period);
__HAL_HRTIM_SETPERIOD( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_E, _period);
__HAL_HRTIM_SETPERIOD( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_F, _period);

//Change comparison value
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_E , HRTIM_COMPAREUNIT_1, a1);
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_E, HRTIM_COMPAREUNIT_3, a2);
\t
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_F , HRTIM_COMPAREUNIT_1, b1);
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_F, HRTIM_COMPAREUNIT_3, b2);

Now comes the point of this article. Two pairs complement each other to form a full bridge. How to operate the phase shift in addition? It may be confusing for newbies.

Look at the code below. By calling these two functions, you can get the waveform of pairwise complementation and phase shift.

#define HRTIMCLOCKFREQ 5440000000

typedef struct
{
uint32_t freq; //frequency
uint32_t proportion; //duty ratio
float angle;// phase shift angle
}tim_struct;

typedef struct
{
uint32_t period;
uint32_t a1;
uint32_t a2;
uint32_t b1;
uint32_t b2;
}pwm_para;
void cmp_by_angle(tim_struct * tm, pwm_para * pwm)
{
//Calculate reload value
uint32_t _period = HRTIMCLOCKFREQ/tm->freq;
pwm->period = _period;
//Calculate the baseline comparison value
uint32_t _cmp = _period * tm->proportion / 100;
\t
pwm->a1 = _cmp;
pwm->a2 = _period;
//Calculate offset degree
uint32_t _shifting = _cmp + _period * tm->angle / 360;
\t
if(_shifting > _period) _shifting %= _period;
pwm->b1 = _shifting;
\t
_shifting = _shifting + _cmp;
\t
if(_shifting > _period) _shifting %= _period;
pwm->b2 = _shifting;

//rt_kprintf("b1:%d, b2:%d, c1:%d, c3:%d\
", pwm->a1, pwm->a2, pwm->b1, pwm->b2);
return;
}



void set_pwm_value(pwm_para * pwm)
{
uint32_t _period = pwm->period, a1 = pwm->a1, a2 = pwm->a2, b1 = pwm->b1, b2 = pwm->b2;
__HAL_HRTIM_SETPERIOD( & amp;hhrtim1, HRTIM_TIMERINDEX_MASTER, _period);
__HAL_HRTIM_SETPERIOD( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_E, _period);
__HAL_HRTIM_SETPERIOD( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_F, _period);
\t
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_E , HRTIM_COMPAREUNIT_1, a1);
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_E, HRTIM_COMPAREUNIT_3, a2);
\t
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_F , HRTIM_COMPAREUNIT_1, b1);
__HAL_HRTIM_SETCOMPARE( & amp;hhrtim1, HRTIM_TIMERINDEX_TIMER_F, HRTIM_COMPAREUNIT_3, b2);
}

Okay, the article ends here. Next, there are articles on the use of DMA + HRTIM to be updated. You can click and follow!