From 73a5a6974a98aa73ab392272b4d69d285c85dee5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 19 Aug 2017 17:20:46 -0600 Subject: Completely reorganized SpaghettiMonster code into smaller logical pieces: fsm-*.c and fsm-*.h. --- spaghetti-monster/fsm-adc.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 spaghetti-monster/fsm-adc.h (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h new file mode 100644 index 0000000..ac42333 --- /dev/null +++ b/spaghetti-monster/fsm-adc.h @@ -0,0 +1,40 @@ +/* + * fsm-adc.h: ADC (voltage, temperature) functions for SpaghettiMonster. + * + * Copyright (C) 2017 Selene ToyKeeper + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef FSM_ADC_H +#define FSM_ADC_H + +#ifdef USE_LVP +// volts * 10 +#define VOLTAGE_LOW 30 +// MCU sees voltage 0.X volts lower than actual, add X to readings +#define VOLTAGE_FUDGE_FACTOR 2 +volatile uint8_t voltage; +void low_voltage(); +#endif +#ifdef USE_THERMAL_REGULATION +volatile int16_t temperature; +void low_temperature(); +void high_temperature(); +#endif + +inline void ADC_on(); +inline void ADC_off(); + +#endif -- cgit v1.2.3 From 5631564b329d0445fb282e5e387217ba4e4ff191 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 23 Aug 2017 19:22:22 -0600 Subject: Added thermal regulation to SpaghettiMonster / Baton. Made some LVP values configurable. Removed high_temperature() / low_temperature() shortcuts for now. --- spaghetti-monster/fsm-adc.h | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index ac42333..43d52a6 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -20,21 +20,54 @@ #ifndef FSM_ADC_H #define FSM_ADC_H + #ifdef USE_LVP -// volts * 10 -#define VOLTAGE_LOW 30 +// default 5 seconds between low-voltage warning events +#ifndef VOLTAGE_WARNING_SECONDS +#define VOLTAGE_WARNING_SECONDS 5 +#endif +// low-battery threshold in volts * 10 +#ifndef VOLTAGE_LOW +#define VOLTAGE_LOW 29 +#endif // MCU sees voltage 0.X volts lower than actual, add X to readings +#ifndef VOLTAGE_FUDGE_FACTOR #define VOLTAGE_FUDGE_FACTOR 2 +#endif volatile uint8_t voltage; void low_voltage(); #endif + + #ifdef USE_THERMAL_REGULATION +// default 5 seconds between thermal regulation events +#ifndef THERMAL_WARNING_SECONDS +#define THERMAL_WARNING_SECONDS 5 +#endif +// try to keep temperature below 45 C +#ifndef DEFAULT_THERM_CEIL +#define DEFAULT_THERM_CEIL 45 +#endif +// don't allow user to set ceiling above 70 C +#ifndef MAX_THERM_CEIL +#define MAX_THERM_CEIL 70 +#endif +// Local per-MCU calibration value +#ifndef THERM_CAL_OFFSET +#define THERM_CAL_OFFSET 0 +#endif +// temperature now, in C (ish) volatile int16_t temperature; -void low_temperature(); -void high_temperature(); +// temperature in a few seconds, in C (ish) * 4 (13.2 fixed-point) +volatile int16_t projected_temperature; // Fight the future! +uint8_t therm_ceil = DEFAULT_THERM_CEIL; +//void low_temperature(); +//void high_temperature(); #endif + inline void ADC_on(); inline void ADC_off(); + #endif -- cgit v1.2.3 From 39b30b41f92978a3e05a8de0a416279fb35b35b1 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 25 Aug 2017 02:14:31 -0600 Subject: Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( Added fsm-misc.*, which currently only has interruptible blink functions in it. (for blinking out numbers and such) --- spaghetti-monster/fsm-adc.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 43d52a6..f1b4477 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -36,6 +36,12 @@ #endif volatile uint8_t voltage; void low_voltage(); +#ifdef USE_BATTCHECK +void battcheck(); +#ifdef BATTCHECK_VpT +#define USE_BLINK_NUM +#endif +#endif #endif -- cgit v1.2.3 From 4052efbf6d7993c6b846105e870b1fcbcdb761e7 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 25 Aug 2017 02:32:43 -0600 Subject: Made 4bar and 8bar battcheck styles work. Added LVP handling for other modes, including battcheck. --- spaghetti-monster/fsm-adc.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index f1b4477..c12405c 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -41,6 +41,9 @@ void battcheck(); #ifdef BATTCHECK_VpT #define USE_BLINK_NUM #endif +#if defined(BATTCHECK_8bars) || defined(BATTCHECK_4bars) +#define USE_BLINK_DIGIT +#endif #endif #endif -- cgit v1.2.3 From a4be98cddedbbdfb87b18dd745ef468a536b1826 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 28 Aug 2017 01:59:06 -0600 Subject: Added thermal config mode... but I'm not sure if it's the right UI for this or not. --- spaghetti-monster/fsm-adc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index c12405c..af30b69 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -69,7 +69,7 @@ void battcheck(); volatile int16_t temperature; // temperature in a few seconds, in C (ish) * 4 (13.2 fixed-point) volatile int16_t projected_temperature; // Fight the future! -uint8_t therm_ceil = DEFAULT_THERM_CEIL; +volatile uint8_t therm_ceil = DEFAULT_THERM_CEIL; //void low_temperature(); //void high_temperature(); #endif -- cgit v1.2.3 From 0a801bff0f22be650aed6c3724c41cae03814d8f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 31 Aug 2017 23:45:36 -0600 Subject: Started a Meteor M43 clone UI. So far, UI1 and battcheck both work. UI2 and UI3 and other blinkies aren't implement yet. Added 6-bar battcheck style to match Meteor (ish). Increased maximum number of clicks to 12, because WTF. If your UI needs 12 clicks, what are you even doing in life? --- spaghetti-monster/fsm-adc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index af30b69..6317b0b 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -41,7 +41,7 @@ void battcheck(); #ifdef BATTCHECK_VpT #define USE_BLINK_NUM #endif -#if defined(BATTCHECK_8bars) || defined(BATTCHECK_4bars) +#if defined(BATTCHECK_8bars) || defined(BATTCHECK_6bars) || defined(BATTCHECK_4bars) #define USE_BLINK_DIGIT #endif #endif -- cgit v1.2.3 From fd3f600c7b17995ba6509802da71a3d2fd0fce6e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 9 Sep 2017 23:07:35 -0600 Subject: Reworked thermal regulation. Now actually works on turbo (was previously emitting "temp low" instead of "temp high" while in direct-drive, probably due to an overflow). Made stepdown work based on an average of the last few temperature predictions instead of just the most recent one. (reduced noise sensitivity) Made each temperature sample based on 8 measurements instead of 4, to reduce noise. Made standby mode re-init thermal measurement arrays, to avoid weird behavior next time light is used. Reduced fixed-point precision to avoid overflows. Reduced prediction strength to encourage stepping down faster while hot. (unfortunately also steps down later, I think, if it wasn't already hot) Not totally happy with new algorithm, but it's the least crappy of a whole bunch of things I tried. (for example, a PID approach with correction based mostly on I... didn't work very well) (taking an average of the last few predictions is very similar though, and works) (but the result is still kind of meh) Saving this so I'll have a functional base next time I try to improve it. --- spaghetti-monster/fsm-adc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 6317b0b..2a7c26d 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -72,6 +72,7 @@ volatile int16_t projected_temperature; // Fight the future! volatile uint8_t therm_ceil = DEFAULT_THERM_CEIL; //void low_temperature(); //void high_temperature(); +volatile uint8_t reset_thermal_history = 1; #endif -- cgit v1.2.3 From e4634255795f04a1d859aa691fbc6e729973b14d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 22 Sep 2017 07:22:16 -0600 Subject: Slightly increased resolution of VOLTAGE_FUDGE_FACTOR. My lights seemed to measure just a bit low, so hopefully this will help. It bumps up reported values by 0.05V. --- spaghetti-monster/fsm-adc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 2a7c26d..b9462f7 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -30,9 +30,9 @@ #ifndef VOLTAGE_LOW #define VOLTAGE_LOW 29 #endif -// MCU sees voltage 0.X volts lower than actual, add X to readings +// MCU sees voltage 0.X volts lower than actual, add X/2 to readings #ifndef VOLTAGE_FUDGE_FACTOR -#define VOLTAGE_FUDGE_FACTOR 2 +#define VOLTAGE_FUDGE_FACTOR 5 #endif volatile uint8_t voltage; void low_voltage(); -- cgit v1.2.3 From 30b13cc13baba55ac1610ad471ca737a6c817683 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 24 Jan 2018 18:27:44 -0700 Subject: Work around issues related to ADC interrupt auto-triggering itself. (was firing off 1000 times faster than desired, causing several issues) (now only executes when explicitly requested by the WDT) --- spaghetti-monster/fsm-adc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index b9462f7..5ffbb73 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -35,6 +35,7 @@ #define VOLTAGE_FUDGE_FACTOR 5 #endif volatile uint8_t voltage; +volatile uint8_t adcint_enable; // kludge, because adc auto-retrigger won't turn off void low_voltage(); #ifdef USE_BATTCHECK void battcheck(); -- cgit v1.2.3 From 5ee5845d4614cb8285cdf0bf529c26bec7ce7217 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 24 Jan 2018 19:43:00 -0700 Subject: FSM: added ability to adjust temperature calibration in UI (lower-case therm_cal_offset var). --- spaghetti-monster/fsm-adc.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 5ffbb73..1b16d01 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -66,11 +66,12 @@ void battcheck(); #ifndef THERM_CAL_OFFSET #define THERM_CAL_OFFSET 0 #endif -// temperature now, in C (ish) +// temperature now, in C (ish) * 2 (14.1 fixed-point) volatile int16_t temperature; -// temperature in a few seconds, in C (ish) * 4 (13.2 fixed-point) +// temperature in a few seconds, in C (ish) * 2 (14.1 fixed-point) volatile int16_t projected_temperature; // Fight the future! -volatile uint8_t therm_ceil = DEFAULT_THERM_CEIL; +uint8_t therm_ceil = DEFAULT_THERM_CEIL; +int8_t therm_cal_offset = 0; //void low_temperature(); //void high_temperature(); volatile uint8_t reset_thermal_history = 1; -- cgit v1.2.3 From d030518a314e838a0386182fbdfb65b56322cb6f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 1 May 2018 19:52:39 -0600 Subject: Use separate voltage adjustment value for pin7 readings. --- spaghetti-monster/fsm-adc.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 1b16d01..6256e2c 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -32,8 +32,12 @@ #endif // MCU sees voltage 0.X volts lower than actual, add X/2 to readings #ifndef VOLTAGE_FUDGE_FACTOR +#ifdef USE_VOLTAGE_DIVIDER +#define VOLTAGE_FUDGE_FACTOR 0 +#else #define VOLTAGE_FUDGE_FACTOR 5 #endif +#endif volatile uint8_t voltage; volatile uint8_t adcint_enable; // kludge, because adc auto-retrigger won't turn off void low_voltage(); -- cgit v1.2.3