Skip to content

Commit 5e274ad

Browse files
author
Richard Unger
committed
add check for dead-time overflow on STM32
1 parent fddf80c commit 5e274ad

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/drivers/hardware_specific/stm32/stm32_mcu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ STM32DriverParams* _initHardware6PWMPair(long PWM_freq, float dead_zone, PinMap*
288288
uint32_t dead_time_ns = (float)(1e9f/PWM_freq)*dead_zone;
289289
uint32_t dead_time = __LL_TIM_CALC_DEADTIME(SystemCoreClock, LL_TIM_GetClockDivision(HT->getHandle()->Instance), dead_time_ns);
290290
if (dead_time>255) dead_time = 255;
291+
if (dead_time==0 && dead_zone>0) {
292+
dead_time = 255; // LL_TIM_CALC_DEADTIME returns 0 if dead_time_ns is too large
293+
SIMPLEFOC_DEBUG("STM32-DRV: WARN: dead time too large, setting to max");
294+
}
291295
LL_TIM_OC_SetDeadTime(HT->getHandle()->Instance, dead_time); // deadtime is non linear!
292296
#if SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH==false
293297
LL_TIM_OC_SetPolarity(HT->getHandle()->Instance, getLLChannel(pinH), LL_TIM_OCPOLARITY_LOW);

0 commit comments

Comments
 (0)