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-standby.c | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 spaghetti-monster/fsm-standby.c (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c new file mode 100644 index 0000000..bef0533 --- /dev/null +++ b/spaghetti-monster/fsm-standby.c @@ -0,0 +1,53 @@ +/* + * fsm-standby.c: standby mode 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_STANDBY_C +#define FSM_STANDBY_C + +#include +#include + +#include "fsm-adc.h" +#include "fsm-wdt.h" +#include "fsm-pcint.h" + +// low-power standby mode used while off but power still connected +#define standby_mode sleep_until_eswitch_pressed +void sleep_until_eswitch_pressed() +{ + WDT_off(); + ADC_off(); + + // make sure switch isn't currently pressed + while (button_is_pressed()) {} + + PCINT_on(); // wake on e-switch event + + sleep_enable(); + sleep_bod_disable(); + sleep_cpu(); // wait here + + // something happened; wake up + sleep_disable(); + PCINT_on(); + ADC_on(); + WDT_on(); +} + +#endif -- cgit v1.2.3 From f881184e490bc13bb5d2436fc67ede0c1eb0c4c0 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 30 Aug 2017 22:16:37 -0600 Subject: Made event handling a bit more reliable while asleep. (was sometimes having difficulty getting out of soft lockout mode) --- spaghetti-monster/fsm-standby.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index bef0533..86c5f0d 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -36,6 +36,7 @@ void sleep_until_eswitch_pressed() // make sure switch isn't currently pressed while (button_is_pressed()) {} + empty_event_sequence(); // cancel pending input on suspend PCINT_on(); // wake on e-switch event @@ -45,7 +46,8 @@ void sleep_until_eswitch_pressed() // something happened; wake up sleep_disable(); - PCINT_on(); + //PCINT_on(); // should be on already + // FIXME? if button is down, make sure a button press event is added to the current sequence ADC_on(); WDT_on(); } -- 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-standby.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 86c5f0d..44a2e0a 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -46,6 +46,11 @@ void sleep_until_eswitch_pressed() // something happened; wake up sleep_disable(); + + // forget what the temperature was last time we were on + reset_thermal_history = 1; + + // go back to normal running mode //PCINT_on(); // should be on already // FIXME? if button is down, make sure a button press event is added to the current sequence ADC_on(); -- cgit v1.2.3 From 520f5cdb983045c5518325f3c3665f59ca85435e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 24 Sep 2017 20:54:07 -0600 Subject: Added idle_mode() for slightly lower power use without turning off any regular functions. (PWM, ADC, WDT all still enabled; only useful in moon mode) Changed default ceilings in Anduril FW3A config. --- spaghetti-monster/fsm-standby.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 44a2e0a..5312f94 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -40,6 +40,9 @@ void sleep_until_eswitch_pressed() PCINT_on(); // wake on e-switch event + // configure sleep mode + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + sleep_enable(); sleep_bod_disable(); sleep_cpu(); // wait here @@ -57,4 +60,18 @@ void sleep_until_eswitch_pressed() WDT_on(); } +#ifdef USE_IDLE_MODE +void idle_mode() +{ + // configure sleep mode + set_sleep_mode(SLEEP_MODE_IDLE); + + sleep_enable(); + sleep_cpu(); // wait here + + // something happened; wake up + sleep_disable(); +} +#endif + #endif -- cgit v1.2.3 From 3a7c25ceaccaeca36c2ba5db2deba975ec54aa68 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 28 Sep 2017 16:25:18 -0600 Subject: Rearranged some build options and made sure the build still works if some are turned off. --- spaghetti-monster/fsm-standby.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 5312f94..5ef666f 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -50,8 +50,10 @@ void sleep_until_eswitch_pressed() // something happened; wake up sleep_disable(); + #ifdef USE_THERMAL_REGULATION // forget what the temperature was last time we were on reset_thermal_history = 1; + #endif // go back to normal running mode //PCINT_on(); // should be on already -- cgit v1.2.3 From d50c46d08a6d7f52dffb9b43784c62b11d78df8c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 11 Dec 2017 19:56:15 -0700 Subject: Greatly improved button debouncing. Helps a lot on FW3A and my light saber. Debouncing isn't 100% yet though. --- spaghetti-monster/fsm-standby.c | 1 + 1 file changed, 1 insertion(+) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 5ef666f..eb631d6 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -37,6 +37,7 @@ void sleep_until_eswitch_pressed() // make sure switch isn't currently pressed while (button_is_pressed()) {} empty_event_sequence(); // cancel pending input on suspend + PCINT_since_WDT = 0; // ensure PCINT won't ignore itself PCINT_on(); // wake on e-switch event -- cgit v1.2.3 From 8c13fd82557dadbe81023c534cd19c31ec40bde4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 12 Dec 2017 15:22:42 -0700 Subject: Debouncing finally works (at least, it does on my two test hosts). --- spaghetti-monster/fsm-standby.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index eb631d6..b90ccea 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -37,7 +37,7 @@ void sleep_until_eswitch_pressed() // make sure switch isn't currently pressed while (button_is_pressed()) {} empty_event_sequence(); // cancel pending input on suspend - PCINT_since_WDT = 0; // ensure PCINT won't ignore itself + //PCINT_since_WDT = 0; // ensure PCINT won't ignore itself PCINT_on(); // wake on e-switch event -- cgit v1.2.3