From 013174374f87a2c3f9a3427cc63f7211f5bf7fd5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 17 Sep 2023 06:31:55 -0600 Subject: converted noctigon-m44 build, and greatly reduced flicker with a new ramp and some new hwdef algorithms --- hwdef-noctigon-m44.c | 84 ++++++++++++++-------------- hwdef-noctigon-m44.h | 4 +- spaghetti-monster/anduril/cfg-noctigon-m44.h | 12 ++-- 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c index 0c73005..776cb82 100644 --- a/hwdef-noctigon-m44.c +++ b/hwdef-noctigon-m44.c @@ -7,6 +7,8 @@ #include "chan-rgbaux.c" +void set_level_zero(); + void set_level_ch1(uint8_t level); void set_level_ch2(uint8_t level); void set_level_both(uint8_t level); @@ -53,26 +55,33 @@ Channel channels[] = { // set new values for both channels, // handling any possible combination // and any before/after state -void set_pwms(uint16_t ch1_pwm, uint16_t ch2_pwm, uint16_t top) { - bool was_on = (CH1_PWM>0) | (CH2_PWM>0); - bool now_on = (ch1_pwm>0) | (ch2_pwm>0); - - if (! now_on) { - CH1_PWM = 0; - CH2_PWM = 0; - PWM_TOP = PWM_TOP_INIT; - PWM_CNT = 0; - CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp - CH2_ENABLE_PORT &= ~(1 << CH2_ENABLE_PIN); // disable opamp - return; - } +void set_pwms(uint16_t ch1_pwm, uint16_t ch2_pwm, uint16_t top, + uint8_t ch1_on, uint8_t ch2_on) { + + bool was_on = (CH1_PWM>0) || (CH2_PWM>0) + || ( CH1_ENABLE_PORT & (1 << CH1_ENABLE_PIN) ) + || ( CH2_ENABLE_PORT & (1 << CH2_ENABLE_PIN) ); + bool now_on = (ch1_pwm>0) || (ch2_pwm>0) || ch1_on || ch2_on; + + // phase-correct PWM at zero (for flicker-free moon), + // fast PWM otherwise + if (ch1_pwm || ch2_pwm) + TCCR1B = (0< 0)) ch2_pwm = 1; - - set_pwms(ch1_pwm, ch2_pwm, top); + set_pwms(ch1_pwm, ch2_pwm, top, + blend < 255, blend > 0); } void set_level_auto(uint8_t level) { - if (0 == level) - return set_pwms(0, 0, PWM_TOP_INIT); - - level --; PWM_DATATYPE ch1_pwm, ch2_pwm; PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); PWM_DATATYPE top = PWM_GET(pwm_tops, level); @@ -153,7 +149,9 @@ void set_level_auto(uint8_t level) { calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); - set_pwms(ch1_pwm, ch2_pwm, top); + // don't turn off either emitter entirely + // (it blinks pretty bright when the regulator turns on mid-ramp) + set_pwms(ch1_pwm, ch2_pwm, top, 1, 1); } diff --git a/hwdef-noctigon-m44.h b/hwdef-noctigon-m44.h index f69fdd5..d02d8dd 100644 --- a/hwdef-noctigon-m44.h +++ b/hwdef-noctigon-m44.h @@ -163,6 +163,7 @@ inline void hwdef_setup() { // pre-scale for timer: N = 1 // Linear opamp PWM for both main and 2nd LEDs (10-bit) // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) + // WGM1[3:0]: 1,1,1,0: PWM, Fast, adjustable (DS table 12-5) // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4) @@ -171,7 +172,8 @@ inline void hwdef_setup() { | (1<