From 1b40078c673d9af8f691ed4c88e2238ae231a176 Mon Sep 17 00:00:00 2001 From: Jan Mrna Date: Sat, 16 May 2026 19:13:26 +0200 Subject: [PATCH] Rework polarity switching to get rid of flicker --- fw/Core/Src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index eb2b3d4..6b9956c 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -137,8 +137,8 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ GPIO_PinState state = GPIO_PIN_RESET; - const uint32_t polarity_switch_period_ms = 1; - uint32_t next_polarity_switch_ms = HAL_GetTick() + polarity_switch_period_ms; + const uint32_t polarity_switch_period_iter = 10; + uint32_t next_polarity_switch_iter = polarity_switch_period_iter; bool polarity = true; while (1) { @@ -162,9 +162,9 @@ int main(void) HAL_GPIO_WritePin(VDD_LEDL_EN_GPIO_Port, VDD_LEDL_EN_Pin, state); // Polarity switch (H-bridge control) - if (HAL_GetTick() > next_polarity_switch_ms) + if (--next_polarity_switch_iter == 0) { - next_polarity_switch_ms = HAL_GetTick() + polarity_switch_period_ms; + next_polarity_switch_iter = polarity_switch_period_iter; polarity = !polarity; H_bridge_set_direction(polarity); }