aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2021-08-12 05:32:51 -0600
committerSelene ToyKeeper2021-08-12 05:32:51 -0600
commit73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61 (patch)
treef81c6bd9c835cf16d563c1b4436b6fe76c62e4c7
parentchanged Noctigon KR4 from fixed to dynamic PWM TOP value, for later use (diff)
downloadanduril-73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61.tar.gz
anduril-73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61.tar.bz2
anduril-73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61.zip
got PFM / dynamic PWM actually working on Noctigon KR4
(and also added "jump start moon" to it) (and generally finished adding dynamic PWM support to FSM)
-rwxr-xr-xbin/level_calc.py2
-rw-r--r--hwdef-Noctigon_KR4.h9
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-kr4-219.h4
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-kr4-219b.h4
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h21
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-kr4.h48
-rw-r--r--spaghetti-monster/fsm-ramping.c26
-rw-r--r--spaghetti-monster/fsm-ramping.h8
8 files changed, 89 insertions, 33 deletions
diff --git a/bin/level_calc.py b/bin/level_calc.py
index e194331..acac332 100755
--- a/bin/level_calc.py
+++ b/bin/level_calc.py
@@ -16,9 +16,9 @@ dyn_pwm = False
def main(args):
"""Calculates PWM levels for visually-linear steps.
"""
- pwm_arg = str(max_pwm)
cli_answers = []
global max_pwm, max_pwms, dyn_pwm
+ pwm_arg = str(max_pwm)
i = 0
while i < len(args):
diff --git a/hwdef-Noctigon_KR4.h b/hwdef-Noctigon_KR4.h
index 58492ac..eee4e08 100644
--- a/hwdef-Noctigon_KR4.h
+++ b/hwdef-Noctigon_KR4.h
@@ -41,8 +41,9 @@
#include <avr/io.h>
#define PWM_CHANNELS 2
-#define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz
-#define PWM_TOP 1023
+#define PWM_BITS 16 // data type needs 16 bits, not 8
+#define PWM_TOP 255 // highest value used in top half of ramp
+#define USE_DYN_PWM // dynamic frequency and speed
#define SWITCH_PIN PB2 // pin 17
#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt
@@ -58,13 +59,13 @@
#define PWM1_PIN PB3 // pin 16, Opamp reference
#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3
+#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase
#define PWM2_PIN PA6 // pin 1, DD FET PWM
#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6
// PWM parameters of both channels are tied together because they share a counter
#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM
-#define PWM2_TOP ICR1 // holds the TOP value for for variable-resolution PWM
#define LED_ENABLE_PIN PB0 // pin 19, Opamp power
#define LED_ENABLE_PORT PORTB // control port for PB0
@@ -144,7 +145,7 @@ inline void hwdef_setup() {
;
// set PWM resolution
- PWM1_TOP = 1023;
+ PWM1_TOP = PWM_TOP;
// set up e-switch
//PORTB = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC?
diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-219.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-219.h
index e0e9317..28fc595 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-kr4-219.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-219.h
@@ -6,8 +6,8 @@
// don't turn off first channel at turbo level
#undef PWM1_LEVELS
-#define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,15,17,19,20,22,24,26,28,30,33,35,38,40,43,46,49,52,55,59,62,66,70,74,78,82,86,91,96,100,105,111,116,121,127,133,139,145,151,158,165,172,179,186,193,201,209,217,225,234,243,251,261,270,280,289,299,310,320,331,342,353,364,376,388,400,412,425,438,451,464,478,492,506,521,536,551,566,582,597,614,630,647,664,681,699,717,735,754,772,792,811,831,851,871,892,913,935,956,978,1001,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023
+#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
// 60% FET power
#undef PWM2_LEVELS
-#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,31,48,66,83,101,119,138,156,176,195,215,234,254,275,296,317,338,359,381,403,425,448,471,494,517,541,565,590,614
+#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,12,18,25,32,38,45,53,60,68,75,83,91,99,108,117,125,135,144,153
diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-219b.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-219b.h
index c1cac84..39ac57c 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-kr4-219b.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-219b.h
@@ -6,8 +6,8 @@
// don't turn off first channel at turbo level
#undef PWM1_LEVELS
-#define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,15,17,19,20,22,24,26,28,30,33,35,38,40,43,46,49,52,55,59,62,66,70,74,78,82,86,91,96,100,105,111,116,121,127,133,139,145,151,158,165,172,179,186,193,201,209,217,225,234,243,251,261,270,280,289,299,310,320,331,342,353,364,376,388,400,412,425,438,451,464,478,492,506,521,536,551,566,582,597,614,630,647,664,681,699,717,735,754,772,792,811,831,851,871,892,913,935,956,978,1001,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023
+#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
// 50% FET power
#undef PWM2_LEVELS
-#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,26,40,55,69,84,99,115,130,146,162,179,195,212,229,246,264,281,299,317,336,354,373,392,411,431,451,471,491,512
+#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,10,15,21,26,32,38,44,50,56,63,69,76,83,90,97,104,112,120,128
diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h
index 3043035..871a405 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h
@@ -10,13 +10,16 @@
// 0/1023: 0.35 lm
// 1/1023: 2.56 lm
// max regulated: 1740 lm
-// level_calc.py 3.0 1 150 7135 0 5 1740
#undef PWM_CHANNELS
#define PWM_CHANNELS 1
#define RAMP_LENGTH 150
+// prioritize low lows, at risk of visible ripple
+// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255
#undef PWM1_LEVELS
-#define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,16,17,18,20,21,23,24,26,27,29,31,33,35,37,39,41,43,45,48,50,53,55,58,61,63,66,69,72,75,79,82,85,89,92,96,100,104,108,112,116,120,125,129,134,138,143,148,153,158,163,169,174,180,185,191,197,203,209,215,222,228,235,242,248,255,263,270,277,285,292,300,308,316,324,333,341,350,359,368,377,386,395,405,414,424,434,444,454,465,475,486,497,508,519,531,542,554,566,578,590,603,615,628,641,654,667,680,694,708,722,736,750,765,779,794,809,825,840,856,872,888,904,920,937,954,971,988,1005,1023
+#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255
#undef PWM2_LEVELS
+#undef PWM_TOPS
+#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
#undef DEFAULT_LEVEL
#define DEFAULT_LEVEL 50
#undef MAX_1x7135
@@ -28,14 +31,14 @@
#undef RAMP_DISCRETE_CEIL
#undef RAMP_DISCRETE_STEPS
-#define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable
+#define RAMP_SMOOTH_FLOOR 1 // level 1 may be unreliable
#define RAMP_SMOOTH_CEIL 130
// 10, 30, [50], 70, 90, 110, 130 (plus [150] on turbo)
#define RAMP_DISCRETE_FLOOR 10
#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL
#define RAMP_DISCRETE_STEPS 7
-// safe limit ~67% power / ~1200 lm (can sustain 900 lm)
+// safe limit ~1000 lm (can sustain 900 lm)
#undef SIMPLE_UI_FLOOR
#undef SIMPLE_UI_CEIL
#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR
@@ -49,9 +52,13 @@
// (only needed on no-FET build)
#define PARTY_STROBE_ONTIME 2
-// stop panicking at ~90% power or ~1600 lm
+// jump start a bit higher than base driver
+#undef JUMP_START_MOON
+#define JUMP_START_MOON 25
+
+// stop panicking at ~1300 lm
#undef THERM_FASTER_LEVEL
-#define THERM_FASTER_LEVEL 143
+#define THERM_FASTER_LEVEL 140
#undef MIN_THERM_STEPDOWN
-#define MIN_THERM_STEPDOWN DEFAULT_LEVEL
+#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range
diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4.h b/spaghetti-monster/anduril/cfg-noctigon-kr4.h
index 82b8df5..f5625c7 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-kr4.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-kr4.h
@@ -24,31 +24,40 @@
// 1/1023: 2.56 lm
// max regulated: 1740 lm
// FET: ~3700 lm
-// maxreg at 130: level_calc.py cube 2 150 7135 0 2.5 1740 FET 1 10 2565
-// maxreg at 120: level_calc.py cube 2 150 7135 0 2.5 1740 FET 1 10 3190
#define RAMP_LENGTH 150
-#define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,15,17,19,20,22,24,26,28,30,33,35,38,40,43,46,49,52,55,59,62,66,70,74,78,82,86,91,96,100,105,111,116,121,127,133,139,145,151,158,165,172,179,186,193,201,209,217,225,234,243,251,261,270,280,289,299,310,320,331,342,353,364,376,388,400,412,425,438,451,464,478,492,506,521,536,551,566,582,597,614,630,647,664,681,699,717,735,754,772,792,811,831,851,871,892,913,935,956,978,1001,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,0
-#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,51,79,109,138,168,198,229,260,292,324,357,390,423,457,492,527,562,598,634,671,708,746,784,822,861,901,941,982,1023
-#define DEFAULT_LEVEL 46
-#define MAX_1x7135 120
-#define HALFSPEED_LEVEL 10
-#define QUARTERSPEED_LEVEL 2
-
-#define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable
-#define RAMP_SMOOTH_CEIL 120
-// 10, 28, [46], 65, 83, 101, [120]
+#define USE_DYN_PWM
+// nice low lows, but might have visible ripple on some lights:
+// maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:16384:255
+// (plus one extra level at the beginning for moon)
+#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0
+#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255
+#define PWM_TOPS 16383,16383,11750,14690,9183,12439,13615,13955,13877,13560,13093,12529,13291,12513,12756,12769,11893,11747,12085,11725,11329,11316,10851,10713,10518,10282,10016,9729,9428,9298,8971,8794,8459,8257,8043,7715,7497,7275,7052,6753,6538,6260,5994,5798,5501,5271,5006,4758,4525,4268,4030,3775,3508,3263,3010,2752,2517,2256,1998,1763,1512,1249,994,749,497,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
+// less ripple, but lows are a bit higher than ideal:
+// maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:4096:255
+// (plus one extra level at the beginning for moon)
+//#define PWM1_LEVELS 0,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,7,8,8,9,10,11,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,32,33,33,34,34,34,34,34,34,33,32,31,30,28,26,24,21,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0
+//#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255
+//#define PWM_TOPS 4095,4095,3760,3403,3020,2611,2176,3582,3062,2515,1940,3221,2761,2283,2998,2584,3004,2631,2899,2555,2735,2836,2538,2606,2636,2638,2387,2382,2361,2328,2286,2238,2185,2129,2070,2010,1949,1887,1826,1766,1706,1648,1591,1536,1482,1429,1379,1329,1242,1199,1122,1084,1016,953,895,842,791,723,659,602,549,482,422,367,302,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
+#define MAX_1x7135 130
+#define DEFAULT_LEVEL 50
+#define HALFSPEED_LEVEL 12
+#define QUARTERSPEED_LEVEL 4
+
+#define RAMP_SMOOTH_FLOOR 3 // level 1 may be unreliable
+#define RAMP_SMOOTH_CEIL 130
+// 10 30 [50] 70 90 110 [130]
#define RAMP_DISCRETE_FLOOR 10
#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL
#define RAMP_DISCRETE_STEPS 7
-// safe limit ~30% power / ~1400 lm (can sustain 900 lm)
+// safe limit ~30% power / ~1300 lm (can sustain 900 lm)
#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR
-#define SIMPLE_UI_CEIL 110
+#define SIMPLE_UI_CEIL 120
#define SIMPLE_UI_STEPS 5
-// stop panicking at ~25% power or ~1000 lm
-#define THERM_FASTER_LEVEL 100
-#define MIN_THERM_STEPDOWN DEFAULT_LEVEL
+// stop panicking at ~1300 lm
+#define THERM_FASTER_LEVEL 120
+#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range
#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting
#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments
@@ -58,5 +67,10 @@
#define THERM_CAL_OFFSET 5
+// the power regulator is a bit slow, so push it harder for a quick response from off
+#define JUMP_START_MOON 25
+#define BLINK_BRIGHTNESS DEFAULT_LEVEL
+#define BLINK_ONCE_TIME 12
+
// can't reset the normal way because power is connected before the button
#define USE_SOFT_FACTORY_RESET
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index d6a14ef..503f90f 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -151,6 +151,32 @@ void set_level(uint8_t level) {
#endif
#endif // ifdef USE_TINT_RAMPING
+
+ #ifdef USE_DYN_PWM
+ // pulse frequency modulation, a.k.a. dynamic PWM
+ PWM1_TOP = PWM_GET(pwm_tops, level);
+ #ifdef PMW2_TOP
+ PWM2_TOP = PWM_GET(pwm_tops, level);
+ #endif
+ #ifdef PMW3_TOP
+ PWM3_TOP = PWM_GET(pwm_tops, level);
+ #endif
+
+ // reset the phase, to avoid random long pulses
+ // see attiny1634 reference manual page 103 for a warning about
+ // the timing of changing the TOP value (section 12.8.4)
+ // (we don't care about being phase-correct, so the brute-force
+ // approach can be used to reset it here)
+ #ifdef PWM1_CNT
+ PWM1_CNT = 0;
+ #endif
+ #ifdef PWM2_CNT
+ PWM2_CNT = 0;
+ #endif
+ #ifdef PWM3_CNT
+ PWM3_CNT = 0;
+ #endif
+ #endif
}
#endif // ifdef OVERRIDE_SET_LEVEL
#ifdef USE_DYNAMIC_UNDERCLOCKING
diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h
index 8fd89c7..d1ef6bc 100644
--- a/spaghetti-monster/fsm-ramping.h
+++ b/spaghetti-monster/fsm-ramping.h
@@ -53,7 +53,9 @@ void gradual_tick();
#define PWM_GET(x,y) pgm_read_byte(x+y)
#else
#define PWM_DATATYPE uint16_t
+#ifndef PWM_TOP
#define PWM_TOP 1023 // 10 bits by default
+#endif
// pointer plus 2*y bytes
//#define PWM_GET(x,y) pgm_read_word(x+(2*y))
// nope, the compiler was already doing the math correctly
@@ -74,6 +76,12 @@ PROGMEM const PWM_DATATYPE pwm3_levels[] = { PWM3_LEVELS };
PROGMEM const PWM_DATATYPE pwm4_levels[] = { PWM4_LEVELS };
#endif
+// pulse frequency modulation, a.k.a. dynamic PWM
+// (different ceiling / frequency at each ramp level)
+#ifdef USE_DYN_PWM
+PROGMEM const PWM_DATATYPE pwm_tops[] = { PWM_TOPS };
+#endif
+
// default / example ramps
#ifndef PWM1_LEVELS
#if PWM_CHANNELS == 1
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.