-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat stm32 synctimers #374
Conversation
…er aligned PWM for stm32 (when using more than one timer)
Hi Antun, Just as a FYI, the hoverboard FOC firmware is also using this feature to run DUAL FOC, but there is another trick. The trick is to start the timers with a different counter value, to account for the time it takes to sample the phase currents for one motor. So both motor's phase current is sampled a the righ time. Another thing I tried is to use the same trick to run both timers half a PWM period appart, and swap the adc channels from one motor to another in the interrupt, but it's much more tricky. [EDIT] Sorry, one more clarification. But with 2 ADCs, it's not needed: [EDIT2] This approach requires the shifting the timer as well by the time it takes to sample and convert on phase current, and needs allowing multiple ADC for the same current sense instance. It makes the sampling synchronous/shorter. That how the hoverboard firmware works |
stm32g4
stm32f4
stm32f1
stm32l4
Remarks
|
Merging :D |
This branch proposes a code which synchronizes all the stm32 timers.
It enables using multiple timers per motor and producing sync center aligned PWM (2pwm, 3pwm, 4pwm and 6pwm).
The proposed code will attempt to sync all the timers used for pwm (even if they are used with multiple motors).
The code works well with the low-side current sensing as well, this is especially a big change for simplefocshield based setups used with nucleos, as they usually never use only one timer for 3 pwm signals. Now they are aligned and the current measurement is much better.
Basically the code in the funciton
_alignTimersNew()
which now finds the master timer between the used timers and all the other timers are configured as slave ones that are started at the same time as the master one. To start the slaves the master timer emitsTRGO_ENABLE
event.If there is no timer that can be master timer, the timers are not synchronized, and the debug error is shown (but the driver is initialised anyway).
If we use low-side current sensing at the same time, the adc sync requires
TRGO_UPDATE
(cannot triggerTRGO_UPDATE
andTRGO_ENABLE
at the same time) event and there, I've given the priority to the ADC code to find the timer which can trigger theTRGO_UPDATE
. Once the timer and the ADC are configured for current sensing the timer synchronization is attempted by finding the timer between the other ones (the ones not used for sync with the ADC) which can be the master and the others are configured to be the slaves.This code now allows to have the trully synced software 6pwm and use it properly with low-side current sensing.
I've just tested the code for hardware 6pwm (even with low-side current sensing) on f4, g4 and f1 boards. It seems to work as expected. 😄
Some potential "wild-west" use-cases