提升Gamma调光输出精度
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#define BRIDGE_PWM_SCALE 1000U
|
#define BRIDGE_PWM_SCALE 1000U
|
||||||
#define BRIDGE_PWM_PERIOD 7U
|
#define BRIDGE_PWM_PERIOD 7U
|
||||||
#define BRIDGE_MIX_SCALE 100U
|
#define BRIDGE_MIX_SCALE 1000U
|
||||||
#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
|
||||||
|
|||||||
@@ -4,9 +4,10 @@
|
|||||||
|
|
||||||
volatile uint8_t Light_Transition_FadeActive;
|
volatile uint8_t Light_Transition_FadeActive;
|
||||||
|
|
||||||
#define LIGHT_FADE_STEP 1U
|
|
||||||
#define BRIGHTNESS_SMOOTH_SHIFT 4U
|
#define BRIGHTNESS_SMOOTH_SHIFT 4U
|
||||||
#define BREATH_MIN_OUTPUT 1U
|
#define OUTPUT_SMOOTH_SHIFT 4U
|
||||||
|
#define LIGHT_OUTPUT_SCALE 1000U
|
||||||
|
#define BREATH_MIN_OUTPUT (LIGHT_OUTPUT_SCALE / 100U)
|
||||||
#define POWER_FADE_Q12_MAX 4096U
|
#define POWER_FADE_Q12_MAX 4096U
|
||||||
#define POWER_FADE_ON_TICKS 140U
|
#define POWER_FADE_ON_TICKS 140U
|
||||||
#define POWER_FADE_OFF_TICKS 160U
|
#define POWER_FADE_OFF_TICKS 160U
|
||||||
@@ -57,6 +58,7 @@ static uint16_t current_brightness_q12;
|
|||||||
static uint16_t power_fade_progress_q12;
|
static uint16_t power_fade_progress_q12;
|
||||||
static uint16_t power_fade_remainder;
|
static uint16_t power_fade_remainder;
|
||||||
static uint8_t power_fade_direction;
|
static uint8_t power_fade_direction;
|
||||||
|
static uint8_t transition_sync_pending;
|
||||||
|
|
||||||
static uint16_t brightness_scale_for_level(uint8_t level)
|
static uint16_t brightness_scale_for_level(uint8_t level)
|
||||||
{
|
{
|
||||||
@@ -88,17 +90,22 @@ static uint16_t approach_brightness_scale(uint16_t current, uint16_t target)
|
|||||||
|
|
||||||
static uint16_t approach_target(uint16_t current, uint16_t target)
|
static uint16_t approach_target(uint16_t current, uint16_t target)
|
||||||
{
|
{
|
||||||
|
uint16_t delta;
|
||||||
|
uint16_t step;
|
||||||
|
|
||||||
|
if(current == target) return current;
|
||||||
if(current < target)
|
if(current < target)
|
||||||
{
|
{
|
||||||
uint16_t delta = target - current;
|
delta = target - current;
|
||||||
return current + ((delta > LIGHT_FADE_STEP) ? LIGHT_FADE_STEP : delta);
|
step = (uint16_t)((delta + ((1U << OUTPUT_SMOOTH_SHIFT) - 1U)) >>
|
||||||
|
OUTPUT_SMOOTH_SHIFT);
|
||||||
|
return current + step;
|
||||||
}
|
}
|
||||||
if(current > target)
|
|
||||||
{
|
delta = current - target;
|
||||||
uint16_t delta = current - target;
|
step = (uint16_t)((delta + ((1U << OUTPUT_SMOOTH_SHIFT) - 1U)) >>
|
||||||
return current - ((delta > LIGHT_FADE_STEP) ? LIGHT_FADE_STEP : delta);
|
OUTPUT_SMOOTH_SHIFT);
|
||||||
}
|
return current - step;
|
||||||
return current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t power_fade_scale(uint16_t progress_q12)
|
static uint16_t power_fade_scale(uint16_t progress_q12)
|
||||||
@@ -176,6 +183,7 @@ void Light_Transition_SyncBrightness(uint8_t level)
|
|||||||
level == 0U ? 0U : POWER_FADE_Q12_MAX;
|
level == 0U ? 0U : POWER_FADE_Q12_MAX;
|
||||||
power_fade_remainder = 0U;
|
power_fade_remainder = 0U;
|
||||||
power_fade_direction = 0U;
|
power_fade_direction = 0U;
|
||||||
|
transition_sync_pending = 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Light_Transition_Task(void)
|
void Light_Transition_Task(void)
|
||||||
@@ -205,9 +213,11 @@ void Light_Transition_Task(void)
|
|||||||
: (power_fade_progress_q12 != 0U);
|
: (power_fade_progress_q12 != 0U);
|
||||||
|
|
||||||
target_w =
|
target_w =
|
||||||
(uint16_t)(((uint32_t)W_PWM * brightness_scale + 2048U) >> 12);
|
(uint16_t)(((uint32_t)W_PWM * brightness_scale *
|
||||||
|
(LIGHT_OUTPUT_SCALE / 100U) + 2048U) >> 12);
|
||||||
target_c =
|
target_c =
|
||||||
(uint16_t)(((uint32_t)C_PWM * brightness_scale + 2048U) >> 12);
|
(uint16_t)(((uint32_t)C_PWM * brightness_scale *
|
||||||
|
(LIGHT_OUTPUT_SCALE / 100U) + 2048U) >> 12);
|
||||||
|
|
||||||
if(Mode == mode1 && powered_on && !power_transitioning)
|
if(Mode == mode1 && powered_on && !power_transitioning)
|
||||||
{
|
{
|
||||||
@@ -217,7 +227,8 @@ void Light_Transition_Task(void)
|
|||||||
target_c = BREATH_MIN_OUTPUT;
|
target_c = BREATH_MIN_OUTPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((Mode == mode2 && powered_on) || power_transitioning)
|
if((Mode == mode2 && powered_on) || power_transitioning ||
|
||||||
|
transition_sync_pending)
|
||||||
{
|
{
|
||||||
W_PWM_duty = target_w;
|
W_PWM_duty = target_w;
|
||||||
C_PWM_duty = target_c;
|
C_PWM_duty = target_c;
|
||||||
@@ -227,6 +238,7 @@ void Light_Transition_Task(void)
|
|||||||
W_PWM_duty = approach_target(W_PWM_duty, target_w);
|
W_PWM_duty = approach_target(W_PWM_duty, target_w);
|
||||||
C_PWM_duty = approach_target(C_PWM_duty, target_c);
|
C_PWM_duty = approach_target(C_PWM_duty, target_c);
|
||||||
}
|
}
|
||||||
|
transition_sync_pending = 0U;
|
||||||
|
|
||||||
Light_Transition_FadeActive =
|
Light_Transition_FadeActive =
|
||||||
!powered_on && (power_fade_progress_q12 != 0U ||
|
!powered_on && (power_fade_progress_q12 != 0U ||
|
||||||
|
|||||||
Reference in New Issue
Block a user