High-resolution timer ,HRTIM(一)

       我是使用STM32G474进行MPPT(Maximum Power Point Tracking)程序移植。RM0440文件第27章,有给出HRTIM的详细介绍。27章开头指出HRTIM可以产生12路高精度时序数字信号,主要用于电力驱动转换系统,例如开关电源、光电系统。在芯片应用过程中,我发现HRTIM相对于STM32高级定时器,基础定时器提供了一些非常方便的功能。repetition counter和死区时间高级定时器和HRTIM均有。但是ADC采样触发配置功能为HRTIM所独有,HRTIM独特的从定时器功能使其可以很方便的做到在PWM中点处进行采样。此外,HRTIM PWM最高可倍频至5.44G(32倍频)。

时钟配置

       将HRTIM1时钟调整为170MHz

        8倍频,时钟频率调整至1.36GHz。

对了,如果想要使用HSE作为HRTIM的时钟源,还需要开启RCC的HSE功能。

PWM配置

       PWM由从定时器TimerB,TimerC输出。

         按照上图操作,可以将TB1,TB2,TC1,TC2配置为PWM引脚,且PWM 频率为250KHz(170MHz*8/5440=250KHz)f=170MHz*主定时器倍频系数/周期。我没有尝试主从定时器频率不一样会怎么样,有兴趣的朋友可以试试。

      此外,我所移植的程序PWM占空比设置比较特殊,从定时器TimerB,TimerC输出的PWM占空比由主定时器Compare Value决定。这是由从定时器的set source selection,Reset Source Selection功能决定的。以TimerB配置为例,主定时器计数值等于Compare Unit1数值时,PWM开始输出高电平,等于Compare Unit 2数值时,PWM开始输出低电平,故Timer2 TB1占空比为:Duty = (HRTIM_MCM2R-HRTIM_MCM2R)/(HRTIM_MPER)。

HRTIM_MPER代表HRTIM主定时器周期寄存器数值,内容与图形化界面设置的Period数值相同。HRTIM_MCMP1R代表HRTIM主定时器比较寄存器1数值,内容与Compare Unit 1数值相同。

      当然你也可以配置为由从定时器自己的Compare Value数值决定,这样你就需要先设置从定时器的Compare Value数据。我因为只配置了TimerB的Compare Unit3 value,所以,配置占空比时只能选timer compare 3 event,配置该参数会改变HRTIM_CMP3xR寄存器数值。

      因为我设置了死区时间功能,所以只用设置TB1,TC1通道的占空比,TB2,TC2通道的占空比也就固定下来了。

然后,在main.c文件中添加如下代码,即可输出2组互补PWM波形。

HAL_HRTIM_WaveformCounterStart(&hhrtim1,HRTIM_TIMERID_MASTER | HRTIM_TIMERID_TIMER_B | HRTIM_TIMERID_TIMER_C); 

HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TB1 | HRTIM_OUTPUT_TB2 | HRTIM_OUTPUT_TC1 | HRTIM_OUTPUT_TC2);

### STM32G474 HRTIM Configuration Using CubeMX For configuring the High-Resolution Timer (HRTIM) on an STM32G474 microcontroller with STM32CubeMX, a series of specific settings must be applied within the software environment to ensure proper functionality and integration into projects. #### Opening STM32CubeMX and Selecting the Microcontroller Start by opening STM32CubeMX and selecting the appropriate part number for your project, which is STM32G474RET6 or another variant depending on requirements[^2]. #### Configuring System Clock Settings Adjust system clock configurations according to application needs. This includes setting up PLLs, dividers, and multipliers as necessary to achieve desired frequencies while ensuring stability and performance criteria are met. #### Enabling HRTIM Peripheral Navigate through peripheral selections until reaching "Advanced Control Timers". Here, enable support for HRTIM peripherals that provide advanced timing capabilities beyond standard timers found elsewhere in the device family. Once enabled, proceed further down this menu path where more detailed options become available specifically related to how these high-resolution timers operate internally including but not limited to: - **Master Repetition Counter**: Controls repetition count during operation. - **Timer A/B/C/D/E/F Channels Setup**: Each channel can function independently offering flexibility when designing complex waveforms or control schemes requiring precise synchronization between multiple outputs. ```c // Example code snippet showing initialization structure setup after generating files from CubeMX void MX_HRTIM_Init(void) { /* USER CODE BEGIN HRTIM_Init 0 */ /* USER CODE END HRTIM_Init 0 */ hrtim.Instance = HRTIM; hrtim.Init.HRTClockSource = HRTIM_CLOCKSOURCE_INTERNAL; hrtim.Init.SyncOptions = HRTIM_SYNCOPTION_NONE; if (HAL_HRTIM_Init(&hrtim) != HAL_OK) { Error_Handler(); } // Additional configuration... } ``` This example demonstrates initializing structures based upon parameters set inside STM32CubeMX before compilation begins; actual implementations may vary slightly due to differing project specifications. --related questions-- 1. What are some common applications utilizing HRTIM features? 2. How does one configure interrupt handling routines associated with HRTIM events? 3. Can you explain methods used to synchronize external signals with internal timer operations via HRTIM inputs? 4. Are there any limitations regarding resolution versus frequency trade-offs when working with HRTIM channels?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值