From 4b4353ade4c026c196e2b6edacbb0dc437e3ddda Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 31 Oct 2021 02:35:49 -0600 Subject: added "200%" turbo on tint-ramping lights: D4S and LT1 Normal ramp from 0% to 100% power on levels 1 to 130, then 101% to 200% power at levels 131 to 150 using both channels at maximum for turbo. When either channel would go over 100%, the extra spills over to the other channel. --- spaghetti-monster/fsm-ramping.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 05c2e0e..ee72cd7 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -293,8 +293,14 @@ void update_tint() { // calculate actual PWM levels based on a single-channel ramp // and a global tint value //PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE brightness = PWM1_LVL; - PWM_DATATYPE warm_PWM, cool_PWM; + uint16_t brightness = PWM1_LVL; + uint16_t warm_PWM, cool_PWM; + #ifdef USE_DYN_PWM + uint16_t top = PWM1_TOP; + //uint16_t top = PWM_GET(pwm_tops, actual_level-1); + #else + const uint16_t top = PWM_TOP; + #endif // auto-tint modes uint8_t mytint; @@ -311,18 +317,37 @@ void update_tint() { // stretch 1-254 to fit 0-255 range (hits every value except 98 and 198) else { mytint = (tint * 100 / 99) - 1; } - // middle tints sag, so correct for that effect PWM_DATATYPE2 base_PWM = brightness; - // correction is only necessary when PWM is fast #if defined(TINT_RAMPING_CORRECTION) && (TINT_RAMPING_CORRECTION > 0) + // middle tints sag, so correct for that effect + // by adding extra power which peaks at the middle tint + // (correction is only necessary when PWM is fast) if (level > HALFSPEED_LEVEL) { base_PWM = brightness + ((((PWM_DATATYPE2)brightness) * TINT_RAMPING_CORRECTION / 64) * triangle_wave(mytint) / 255); } + // fade the triangle wave out when above 100% power, + // so it won't go over 200% + if (brightness > top) { + base_PWM -= 2 * ( + ((brightness - top) * TINT_RAMPING_CORRECTION / 64) + * triangle_wave(mytint) / 255 + ); + } + // guarantee no more than 200% power + if (base_PWM > (top << 1)) { base_PWM = top << 1; } #endif cool_PWM = (((PWM_DATATYPE2)mytint * (PWM_DATATYPE2)base_PWM) + 127) / 255; warm_PWM = base_PWM - cool_PWM; + // when running at > 100% power, spill extra over to other channel + if (cool_PWM > top) { + warm_PWM += (cool_PWM - top); + cool_PWM = top; + } else if (warm_PWM > top) { + cool_PWM += (warm_PWM - top); + warm_PWM = top; + } TINT1_LVL = warm_PWM; TINT2_LVL = cool_PWM; -- cgit v1.2.3 From c890237f5ed6fba2f200cba23cff5622818a9ad0 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 31 Oct 2021 02:51:38 -0600 Subject: fixed flicker on inactive tint ramp channel during ramping --- spaghetti-monster/fsm-ramping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index ee72cd7..49e173f 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -102,6 +102,7 @@ void set_level(uint8_t level) { #endif } else { // enable the power channel, if relevant + #ifndef USE_TINT_RAMPING // update_tint handles this better #ifdef LED_ENABLE_PIN #ifndef LED_ENABLE_PIN_LEVEL_MIN LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); @@ -117,6 +118,7 @@ void set_level(uint8_t level) { #ifdef LED2_ENABLE_PIN LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); #endif + #endif // ifndef USE_TINT_RAMPING // PWM array index = level - 1 level --; @@ -354,11 +356,15 @@ void update_tint() { // disable the power channel, if relevant #ifdef LED_ENABLE_PIN - if (! warm_PWM) + if (warm_PWM) + LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); + else LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); #endif #ifdef LED2_ENABLE_PIN - if (! cool_PWM) + if (cool_PWM) + LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); + else LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); #endif } -- cgit v1.2.3 From 02521ee8094ff79ff5e927856008c4fa153be6eb Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 6 Nov 2021 02:30:08 -0600 Subject: reduced SP10 downward ramp flicker even more (reduced PWM_TOP minimum timing window to 32 cpu cycles, to allow TOP value of 64 to work better) --- spaghetti-monster/fsm-ramping.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 49e173f..abbfbde 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -146,8 +146,8 @@ void set_level(uint8_t level) { // the timing of changing the TOP value (section 12.8.4)) // (but don't wait when turning on from zero, because // it'll reset the phase below anyway) - // to be safe, allow at least 64 cycles to update TOP - while(prev_level && (PWM1_CNT > (top - 64))) {} + // to be safe, allow at least 32 cycles to update TOP + while(prev_level && (PWM1_CNT > (top - 32))) {} #endif // pulse frequency modulation, a.k.a. dynamic PWM PWM1_TOP = top; @@ -155,13 +155,13 @@ void set_level(uint8_t level) { // repeat for other channels if necessary #ifdef PMW2_TOP #ifdef PWM2_CNT - while(prev_level && (PWM2_CNT > (top - 64))) {} + while(prev_level && (PWM2_CNT > (top - 32))) {} #endif PWM2_TOP = top; #endif #ifdef PMW3_TOP #ifdef PWM3_CNT - while(prev_level && (PWM3_CNT > (top - 64))) {} + while(prev_level && (PWM3_CNT > (top - 32))) {} #endif PWM3_TOP = top; #endif -- cgit v1.2.3