Hrtim patch for 1/0 code #145
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The STM32G474RE does NOT support 1/0 on its outputs. To solve this issue, commit #109 put in place a swapping mechanism. This mechanism tests the value of the duty cycle prior to upload and swaps the outputs if the value is within 3 of the maximum (0xFFFF). This value "3" is refered here as the "swap window".
The fixed swap window has been reported to have problems during switching in #144.
The problem
The swap window is actually NOT static. It depends on the pre-scaler of the HRTIM, as shown by the table below from STM32 reference manual page 842 Rev8
Thus, the code that does the swapping needs to be patched to support different swapping windows depending on the pre-scaler value.
The solution
This patch updates the HRTIM driver to allow for dynamic choosing the swap window. These windows are written within the
hrtim_common.c. The structure that describes the timing units has been updated to hold the value of this variable as anuint16_t swap_window, which is updated during the calculation of the pre-scaler in the_period_ckpscfunction. Finally, this value is retrieved by theshield.power.setDutyCycleRawfunction to verify if the duty cycle is within the swap window or not.The test
This code was tested for a frequency of 200kHz and 10kHz.
It was tested using the code attached below.
It is a simple PWM example from the spin which has been modified to see the maximum period and the comparisons to trigger the swap.
main.cpp
The result is a seamless transition between the 1 and 0.99XX, as can be seen by the capture of a single run on the oscilloscope triggered on the transition between edge values.