Skip to content

Conversation

@luizvilla
Copy link
Member

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

image

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 an uint16_t swap_window, which is updated during the calculation of the pre-scaler in the _period_ckpsc function. Finally, this value is retrieved by the shield.power.setDutyCycleRaw function 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.

scope_7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants