From ce4feeb67e725dd996b8da475cddc7f6e15a9a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=90=AA?= Date: Mon, 27 Jul 2026 17:42:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E5=8F=8C=E8=89=B2=E4=BD=8E?= =?UTF-8?q?=E4=BA=AE=E5=BA=A6=E8=84=89=E5=86=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ble/ble_peripheral/app/src/bridge_pwm.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/project/example/ble/ble_peripheral/app/src/bridge_pwm.c b/project/example/ble/ble_peripheral/app/src/bridge_pwm.c index 3c09ec4..339e384 100644 --- a/project/example/ble/ble_peripheral/app/src/bridge_pwm.c +++ b/project/example/ble/ble_peripheral/app/src/bridge_pwm.c @@ -25,6 +25,7 @@ #define BRIDGE_FRAME_US 1000U #define BRIDGE_DEADTIME_US 50U #define BRIDGE_DUAL_ACTIVE_US 900U +#define BRIDGE_MIN_DUAL_PULSE_US 15U #define BRIDGE_TIMER_TICKS_PER_US 16U #define BRIDGE_GPIO_PORT 0U @@ -326,16 +327,24 @@ __RAM_CODE void Bridge_Service_1ms(void) */ total_on_us = (BRIDGE_DUAL_ACTIVE_US * total + (BRIDGE_MIX_SCALE / 2U)) / BRIDGE_MIX_SCALE; - if (total_on_us < 2U) { - total_on_us = 2U; + /* + * Timer/driver edge uncertainty becomes visible when a dual-color + * pulse is only a few microseconds wide. Keep both directions at + * least 15 us. This gives dual color a stable floor of about 3%, + * while single-color hardware PWM can still reach 1%. + */ + if (total_on_us < (2U * BRIDGE_MIN_DUAL_PULSE_US)) { + total_on_us = 2U * BRIDGE_MIN_DUAL_PULSE_US; } next_w_us = (uint16_t)((total_on_us * w_mix + (total / 2U)) / total); - if (next_w_us == 0U) { - next_w_us = 1U; - } else if (next_w_us >= total_on_us) { - next_w_us = (uint16_t)(total_on_us - 1U); + if (next_w_us < BRIDGE_MIN_DUAL_PULSE_US) { + next_w_us = BRIDGE_MIN_DUAL_PULSE_US; + } else if (next_w_us > + total_on_us - BRIDGE_MIN_DUAL_PULSE_US) { + next_w_us = + (uint16_t)(total_on_us - BRIDGE_MIN_DUAL_PULSE_US); } next_c_us = (uint16_t)(total_on_us - next_w_us);