Skip to content

Commit fddf80c

Browse files
author
Richard Unger
committed
add overflow check to STM32 HW dead-time calc
1 parent e72db3f commit fddf80c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/drivers/hardware_specific/stm32/stm32_mcu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ STM32DriverParams* _initHardware6PWMPair(long PWM_freq, float dead_zone, PinMap*
287287
// dead time is set in nanoseconds
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);
290+
if (dead_time>255) dead_time = 255;
290291
LL_TIM_OC_SetDeadTime(HT->getHandle()->Instance, dead_time); // deadtime is non linear!
291292
#if SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH==false
292293
LL_TIM_OC_SetPolarity(HT->getHandle()->Instance, getLLChannel(pinH), LL_TIM_OCPOLARITY_LOW);

0 commit comments

Comments
 (0)