HRTIM的移相配置
由于缺少独立的倍频器,H7最高仅支持主频频率的HRTIM,对于H750而言是480M一、时钟配置
首先在RCC中将HSE选好,并调整H7的版本,Y版最高400M,V版最高480M
Y版可以将Power Regulator Voltage Scale调整至0,V版只能调整至1
接下来进时钟树,将PLL达到HSE上(CSI RC也行,不过正常做东西都有外部时钟吧),System Clock Mux打到PLL上,系统时钟打个480让cube自己搜索,搜索完后拉到下面调整一下HRTIM Clock Mux
https://i0.hdslb.com/bfs/article/d97978f9eeb43ab2f497f9b3e1119b42d491b245.png@1192w.webp
Timer A~E的配置都类似,这里以A为例:
[*]时钟和周期与Master一致,其实周期随便配置,配成0xFFFF都没问题
[*]这里要改成单次触发模式,否则在调整移相角时占空比会出问题
[*]Preload和Repetition Update和Master一样
[*]这里一定要打开,将寄存器更新延后到了reset时刻
[*]Reset Trigger要改成Master Timer Compare event,这个和前面配置的Master Cpmpare Unit是对应的
[*]Compare Unit用于控制波形,我这里是占空比50%的半桥,所以前面Dead Time Insertion Mode改成了Deadtime is inserted,这里只需要使用一个Compare Unit
[*]死区按照自己想法设置
[*]输出配置,我这里配置的是Timer A被Master的trigger reset的同时输出拉高,并在Compare Unit 1处置低,这样占空比刚好是50%(0->480)
https://i0.hdslb.com/bfs/article/0fb500c13438c435cbc1366f62be14ed027358ba.png@1192w.webp
最后把Master的全局中断打开
https://i0.hdslb.com/bfs/article/b816930a30d16a50ee3ac2a5ac05a9aaae0671f5.png@1192w.webp HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TA1); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TA2); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TB1); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TB2); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TC1); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TC2); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TD1); HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TD2); HAL_HRTIM_WaveformCountStart_IT(&hhrtim, HRTIM_TIMERID_MASTER | HRTIM_TIMERID_TIMER_A | HRTIM_TIMERID_TIMER_B | HRTIM_TIMERID_TIMER_C | HRTIM_TIMERID_TIMER_D);中断回调函数是占空比与周期的调节可以通过直接写寄存器来完成,也可以通过HAL库提供的宏来实现 //调整周期 __HAL_HRTIM_SETPERIOD(&hhrtim, HRTIM_TIMERINDEX_MASTER, SPS_BASE_PERIOD + delta_tick / 2); //调整相位 __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_1, phaseAB); __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_2, phaseAB); __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_3, phaseCD); __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_4, phaseCD); //调整占空比 __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, phi_tick); __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, phi_tick); __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_TIMER_C, HRTIM_COMPAREUNIT_1, SPS_BASE_PERIOD / 2); __HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_1, SPS_BASE_PERIOD / 2);这套配置默认使用了缓冲寄存器(影子寄存器),Master寄存器的更新时刻是repetition事件,slave寄存器的更新时刻是reset时刻
这个程序能规整一点就更好的
页:
[1]