aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorGabriel Hart2021-08-20 10:06:00 -0500
committerGabriel Hart2021-08-20 10:06:00 -0500
commitf92e07dc18e4eaf9e84f36ef3d476af688f62b5b (patch)
treea2e5860dea9a49d2298c0766d1716d7102f2f947 /spaghetti-monster
parentfrom Tom E, support PB4 for any of the 3 PWM channels (diff)
parentmerged digitalcircuit's branch to make autolock timer configurable at build time (diff)
downloadanduril-f92e07dc18e4eaf9e84f36ef3d476af688f62b5b.tar.gz
anduril-f92e07dc18e4eaf9e84f36ef3d476af688f62b5b.tar.bz2
anduril-f92e07dc18e4eaf9e84f36ef3d476af688f62b5b.zip
Merge in TK's repo thru revision 613
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h8
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-kr4.h13
-rw-r--r--spaghetti-monster/anduril/config-default.h14
-rw-r--r--spaghetti-monster/anduril/factory-reset.c7
-rw-r--r--spaghetti-monster/anduril/lockout-mode.h5
-rw-r--r--spaghetti-monster/fsm-ramping.c41
6 files changed, 53 insertions, 35 deletions
diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h
index 871a405..383a0c8 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h
@@ -31,10 +31,10 @@
#undef RAMP_DISCRETE_CEIL
#undef RAMP_DISCRETE_STEPS
-#define RAMP_SMOOTH_FLOOR 1 // level 1 may be unreliable
+#define RAMP_SMOOTH_FLOOR 11 // low levels may be unreliable
#define RAMP_SMOOTH_CEIL 130
-// 10, 30, [50], 70, 90, 110, 130 (plus [150] on turbo)
-#define RAMP_DISCRETE_FLOOR 10
+// 11, 30, [50], 70, 90, 110, 130 (plus [150] on turbo)
+#define RAMP_DISCRETE_FLOOR 11
#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL
#define RAMP_DISCRETE_STEPS 7
@@ -54,7 +54,7 @@
// jump start a bit higher than base driver
#undef JUMP_START_MOON
-#define JUMP_START_MOON 25
+#define JUMP_START_MOON 31
// stop panicking at ~1300 lm
#undef THERM_FASTER_LEVEL
diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4.h b/spaghetti-monster/anduril/cfg-noctigon-kr4.h
index f5625c7..d584445 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-kr4.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-kr4.h
@@ -43,10 +43,10 @@
#define HALFSPEED_LEVEL 12
#define QUARTERSPEED_LEVEL 4
-#define RAMP_SMOOTH_FLOOR 3 // level 1 may be unreliable
+#define RAMP_SMOOTH_FLOOR 11 // low levels may be unreliable
#define RAMP_SMOOTH_CEIL 130
-// 10 30 [50] 70 90 110 [130]
-#define RAMP_DISCRETE_FLOOR 10
+// 11 30 [50] 70 90 110 [130]
+#define RAMP_DISCRETE_FLOOR 11
#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL
#define RAMP_DISCRETE_STEPS 7
@@ -58,8 +58,9 @@
// 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
+// no longer needed, after switching to dynamic PWM
+//#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting
+//#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments
// slow down party strobe; this driver can't pulse for 1ms or less
// (only needed on no-FET build)
@@ -68,7 +69,7 @@
#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 JUMP_START_MOON 26
#define BLINK_BRIGHTNESS DEFAULT_LEVEL
#define BLINK_ONCE_TIME 12
diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h
index 31fcbf4..a50be5d 100644
--- a/spaghetti-monster/anduril/config-default.h
+++ b/spaghetti-monster/anduril/config-default.h
@@ -37,7 +37,19 @@
// overheat protection
#define USE_THERMAL_REGULATION
#define DEFAULT_THERM_CEIL 45 // try not to get hotter than this (in C)
-
+// Comment out to disable automatic calibration on factory reset
+// - If so, be sure to set THERM_CAL_OFFSET to the correct calibration offset
+// - Calibration can still be overridden in temperature check mode
+// Or uncomment to use the default auto-calibrate on factory reset
+//
+// To determine THERM_CAL_OFFSET, comment out USE_THERM_AUTOCALIBRATE to
+// disable auto-calibration, compile and flash, let flashlight rest at a known
+// temperature, then enter temp check mode (do NOT enter calibration mode).
+//
+// THERM_CAL_OFFSET = known_temperature - temp_check_blinks + THERM_CAL_OFFSET
+//
+// (include THERM_CAL_OFFSET in sum as it might already be a non-zero number)
+#define USE_THERM_AUTOCALIBRATE
// Include a simplified UI for non-enthusiasts?
#define USE_SIMPLE_UI
diff --git a/spaghetti-monster/anduril/factory-reset.c b/spaghetti-monster/anduril/factory-reset.c
index f05b5eb..ecb4cc2 100644
--- a/spaghetti-monster/anduril/factory-reset.c
+++ b/spaghetti-monster/anduril/factory-reset.c
@@ -43,13 +43,12 @@ void factory_reset() {
}
// explode, if button pressed long enough
if (reset) {
- #ifdef USE_THERMAL_REGULATION
- #ifdef AVRXMEGA3 // AVR 1-Series has factory calibrated thermal sensor, remove the offset
+ // AVR 1-Series has factory calibrated thermal sensor, always remove the offset on reset
+ #if defined(USE_THERMAL_REGULATION) && defined(AVRXMEGA3)
thermal_config_save(1,temperature - therm_cal_offset); // this will cancel out the offset
- #else
+ #elif defined(USE_THERMAL_REGULATION) && defined(USE_THERM_AUTOCALIBRATE)
// auto-calibrate temperature... assume current temperature is 21 C
thermal_config_save(1, 21);
- #endif // AVRXMEGA3
#endif
// save all settings to eeprom
// (assuming they're all at default because we haven't loaded them yet)
diff --git a/spaghetti-monster/anduril/lockout-mode.h b/spaghetti-monster/anduril/lockout-mode.h
index 021d34a..1c9c081 100644
--- a/spaghetti-monster/anduril/lockout-mode.h
+++ b/spaghetti-monster/anduril/lockout-mode.h
@@ -24,7 +24,10 @@
uint8_t lockout_state(Event event, uint16_t arg);
#ifdef USE_AUTOLOCK
-uint8_t autolock_time = 0;
+#ifndef DEFAULT_AUTOLOCK_TIME
+#define DEFAULT_AUTOLOCK_TIME 0 // autolock time in minutes, 0 = disabled
+#endif
+uint8_t autolock_time = DEFAULT_AUTOLOCK_TIME;
uint8_t autolock_config_state(Event event, uint16_t arg);
#endif
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index 503f90f..1a08149 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -153,30 +153,33 @@ void set_level(uint8_t level) {
#endif // ifdef USE_TINT_RAMPING
#ifdef USE_DYN_PWM
+ uint16_t top = PWM_GET(pwm_tops, level);
+ #ifdef PWM1_CNT
+ // wait to ensure compare match won't be missed
+ // (causes visible flickering when missed, because the counter
+ // goes all the way to 65535 before returning)
+ // (see attiny1634 reference manual page 103 for a warning about
+ // the timing of changing the TOP value (section 12.8.4))
+ // to be safe, allow at least 64 cycles to update TOP
+ while(PWM1_CNT > (top - 64)) {}
+ #endif
// pulse frequency modulation, a.k.a. dynamic PWM
- PWM1_TOP = PWM_GET(pwm_tops, level);
+ PWM1_TOP = top;
+
+ // repeat for other channels if necessary
#ifdef PMW2_TOP
- PWM2_TOP = PWM_GET(pwm_tops, level);
+ #ifdef PWM2_CNT
+ while(PWM2_CNT > (top - 64)) {}
+ #endif
+ PWM2_TOP = top;
#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;
+ #ifdef PWM3_CNT
+ while(PWM3_CNT > (top - 64)) {}
+ #endif
+ PWM3_TOP = top;
#endif
- #endif
+ #endif // ifdef USE_DYN_PWM
}
#endif // ifdef OVERRIDE_SET_LEVEL
#ifdef USE_DYNAMIC_UNDERCLOCKING
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.