2024-05-15 12:31 AM
Hi all, I'm currently developing a project with STM32G474RETx. I find on the HRTIM module, there is a function called swap mode (as the figure showed). I'm really curious when this function will be applied, is there any scenario?
2024-05-28 12:25 PM - edited 2024-05-28 12:27 PM
Hello @Element147 ,
The swap mode in HRTIM is applied by using the SWPD bit in the HRTIM_CR2 register.
The procedure is the following:
During initialization: Set the PREEN bit to 1 during the initialization of the HRTIM (to prepare the HRTIM for swapping).
It is important to keep the PREEN bit set to 1 even after the output swapping. It must remain enabled even after the swap: The swap occurs on the update following the toggling of the swap bit.
During run-time:
- To Swap Output (0.normal output): If the current output is normal, set the SWPD bit to 1 in the HRTIM_CR2 register (The outputs will be swapped on the following update event).
- To Return to Normal Output (0.swap output): If the output is currently swapped, set the SWPD bit to 0 in the HRTIM_CR2 register (The outputs will be swapped back to normal on the following update event).
This process allows for the swapping of the outputs without stopping the timer, ensuring continuous operation.
You can use this HRTIM example project (and update it according to your needs) for swap mode: