稳定双色低亮度脉冲

This commit is contained in:
2026-07-27 17:42:32 +08:00
parent 2d818fcea2
commit ce4feeb67e
@@ -25,6 +25,7 @@
#define BRIDGE_FRAME_US 1000U #define BRIDGE_FRAME_US 1000U
#define BRIDGE_DEADTIME_US 50U #define BRIDGE_DEADTIME_US 50U
#define BRIDGE_DUAL_ACTIVE_US 900U #define BRIDGE_DUAL_ACTIVE_US 900U
#define BRIDGE_MIN_DUAL_PULSE_US 15U
#define BRIDGE_TIMER_TICKS_PER_US 16U #define BRIDGE_TIMER_TICKS_PER_US 16U
#define BRIDGE_GPIO_PORT 0U #define BRIDGE_GPIO_PORT 0U
@@ -326,16 +327,24 @@ __RAM_CODE void Bridge_Service_1ms(void)
*/ */
total_on_us = (BRIDGE_DUAL_ACTIVE_US * total + total_on_us = (BRIDGE_DUAL_ACTIVE_US * total +
(BRIDGE_MIX_SCALE / 2U)) / BRIDGE_MIX_SCALE; (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 + next_w_us = (uint16_t)((total_on_us * w_mix +
(total / 2U)) / total); (total / 2U)) / total);
if (next_w_us == 0U) { if (next_w_us < BRIDGE_MIN_DUAL_PULSE_US) {
next_w_us = 1U; next_w_us = BRIDGE_MIN_DUAL_PULSE_US;
} else if (next_w_us >= total_on_us) { } else if (next_w_us >
next_w_us = (uint16_t)(total_on_us - 1U); 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); next_c_us = (uint16_t)(total_on_us - next_w_us);