From 8d4f94cea1b80fa6be14d5f0d992a0ec94f0ed24 Mon Sep 17 00:00:00 2001 From: Jan Mrna Date: Sat, 16 May 2026 18:39:30 +0200 Subject: [PATCH] Add delay after switching off H-bridge --- fw/Core/Src/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index bcfddbf..7036529 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -60,6 +60,15 @@ uint16_t ADC_ReadChannel(uint32_t channel); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +void H_bridge_delay() +{ + // very rough calculation: body of the loop takes 8 instructions, + // freq is 12 MHz: 8 / 12e6 * 100 = 0.000066 s, so about 66 ns + // This calculation could be way off, but it doesn't matter that much + volatile uint32_t delay = 100; + while(--delay > 0) {} +} + void H_bridge_turn_off() { HAL_GPIO_WritePin(LS_A_GPIO_Port, LS_A_Pin, GPIO_PIN_RESET); @@ -71,6 +80,9 @@ void H_bridge_turn_off() void H_bridge_set_direction(bool positive) { H_bridge_turn_off(); + // delay to make sure all FETs are turned off; + // not measured, just eyeballing the time + H_bridge_delay(); if (positive) { HAL_GPIO_WritePin(HS_A_GPIO_Port, HS_A_Pin, GPIO_PIN_SET);