Skip to content

Commit 84a4aba

Browse files
committed
Fix inline current sense for B-G431B
1 parent 11ff608 commit 84a4aba

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/drivers/hardware_specific/stm32_mcu.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ void _alignTimersNew() {
196196
#ifdef SIMPLEFOC_STM32_DEBUG
197197
SIMPLEFOC_DEBUG("STM32-DRV: Restarting timer ", getTimerNumber(get_timer_index(timers[i]->getHandle()->Instance)));
198198
#endif
199+
200+
// Skip 1 on the repetition counter. This shifts TIM_TRGO_UPDATE to align with the pwm peaks instead of the troughs.
201+
// note: the documentation states that "In center-aligned mode, for odd values of RCR, the update event occurs either on the
202+
// overflow or on the underflow depending on when the RCR register was written and when the counter was started. If the RCR
203+
// was written before starting the counter, the UEV occurson the overflow." However, I was unable to get this to work.
204+
timers[0]->getHandle()->Instance->CNT = timers[0]->getHandle()->Instance->ARR;
199205
}
200206

201207
for (int i=0; i<numTimers; i++) {
@@ -260,6 +266,10 @@ STM32DriverParams* _initHardware6PWMPair(long PWM_freq, float dead_zone, PinMap*
260266
HardwareTimer_Handle[index]->handle.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED3;
261267
HardwareTimer_Handle[index]->handle.Init.RepetitionCounter = 1;
262268
// HardwareTimer_Handle[index]->handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
269+
270+
// Set Trigger out for inline current sense DMA transfer
271+
LL_TIM_SetTriggerOutput(HardwareTimer_Handle[index]->handle.Instance, LL_TIM_TRGO_UPDATE);
272+
263273
HAL_TIM_Base_Init(&(HardwareTimer_Handle[index]->handle));
264274
((HardwareTimer *)HardwareTimer_Handle[index]->__this)->setOverflow((uint32_t)PWM_freq, HERTZ_FORMAT);
265275
}

0 commit comments

Comments
 (0)