From 9c0d1832464e4ee7ee8c4c63092ac4337347483b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 29 Jan 2020 05:08:14 -0700 Subject: rewrote ADC code to use a continuous lowpass system on all measurements, to eliminate noise and maybe increase precision (thermal code still needs to be rewritten though) --- spaghetti-monster/fsm-wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 0c49a75..e9dca3a 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -181,9 +181,11 @@ void WDT_inner() { // start a new ADC measurement every 4 ticks adc_trigger ++; if (0 == (adc_trigger & 3)) { + // in case we're in standby mode and auto-retrigger is turned off ADC_start_measurement(); - irq_adc_stable = 0; - adcint_enable = 1; + adc_sample_count = 0; + // allow regulation logic to run + adc_deferred_enable = 1; } #endif } -- cgit v1.2.3 From d275f50525ed9a0950c743faa317c7aa4fe9420b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 30 Jan 2020 23:10:25 -0700 Subject: saving state of ADC / WDT refactoring before doing more changes... what changed so far: - removed LVP lowpass and thermal regulation lowpass logic; it's probably redundant now - slowed ADC deferred logic timing to 4X per second instead of 16X, because there doesn't seem to be much reason to do it any faster - reduced thermal event rate-limit to just 1 second, for more responsive regulation - added "EV_temperature_okay" signal, to help stop adjustments at an appropriate time instead of going to far - sped up sleep LVP to one measurement every 8 seconds instead of 16, to help the aux LEDs respond to voltage changes faster (effect on standby time is negligible) - make sure the WDT doesn't set the ADC channel or counter... except in standby mode --- spaghetti-monster/fsm-wdt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index e9dca3a..459010f 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -119,7 +119,7 @@ void WDT_inner() { return; // no sleep LVP needed if nothing drains power while off #else // stop here, usually... but proceed often enough for sleep LVP to work - if (0 != (ticks_since_last & 0x7f)) return; + if (0 != (ticks_since_last & 0x3f)) return; adc_trigger = 255; // make sure a measurement will happen ADC_on(); // enable ADC voltage measurement functions temporarily @@ -178,12 +178,15 @@ void WDT_inner() { #endif #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) - // start a new ADC measurement every 4 ticks + // start a new ADC measurement every 16 ticks adc_trigger ++; - if (0 == (adc_trigger & 3)) { - // in case we're in standby mode and auto-retrigger is turned off + if (0 == (adc_trigger & 15)) { + // in case we're in standby mode and the ADC is turned off + if (go_to_standby) { + //set_admux_voltage(); + ADC_on(); + } ADC_start_measurement(); - adc_sample_count = 0; // allow regulation logic to run adc_deferred_enable = 1; } -- cgit v1.2.3 From 930752b496ad8a1d9f3db96184839022c16a5c7f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 28 Feb 2020 02:06:53 -0700 Subject: went back to continuous lowpass because it had the best noise reduction (also, now treating smoothed ADC values as 11-bit, with the lowest 5 bits chopped off to eliminate noise) --- spaghetti-monster/fsm-wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 459010f..12aab7b 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -180,7 +180,7 @@ void WDT_inner() { #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) // start a new ADC measurement every 16 ticks adc_trigger ++; - if (0 == (adc_trigger & 15)) { + if (0 == (adc_trigger & 31)) { // in case we're in standby mode and the ADC is turned off if (go_to_standby) { //set_admux_voltage(); -- cgit v1.2.3 From 7110fdbae15c6303eb405705bf0b319fc1381a4f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 13 Mar 2020 18:06:27 -0600 Subject: tried to make thermal code a bit less twitchy... it regulates really fast on D4, but once it's stable, the adjustments are too large --- spaghetti-monster/fsm-wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 12aab7b..1d630a4 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -178,7 +178,7 @@ void WDT_inner() { #endif #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) - // start a new ADC measurement every 16 ticks + // enable the deferred ADC handler every 32 ticks adc_trigger ++; if (0 == (adc_trigger & 31)) { // in case we're in standby mode and the ADC is turned off -- cgit v1.2.3 From 6e7884cf5b4756ffba9f6dc9dd1fb94184779bf1 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 16 Mar 2020 00:13:44 -0600 Subject: cleaned up WDT ADC timer code slightly, and removed a bit of redundant code --- spaghetti-monster/fsm-wdt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 1d630a4..9858e09 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -111,7 +111,7 @@ void WDT_inner() { #ifdef TICK_DURING_STANDBY // handle standby mode specially if (go_to_standby) { - // emit a halfsleep tick, and process it + // emit a sleep tick, and process it emit(EV_sleep_tick, ticks_since_last); process_emissions(); @@ -121,7 +121,7 @@ void WDT_inner() { // stop here, usually... but proceed often enough for sleep LVP to work if (0 != (ticks_since_last & 0x3f)) return; - adc_trigger = 255; // make sure a measurement will happen + adc_trigger = 0; // make sure a measurement will happen ADC_on(); // enable ADC voltage measurement functions temporarily #endif } @@ -178,18 +178,20 @@ void WDT_inner() { #endif #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) - // enable the deferred ADC handler every 32 ticks - adc_trigger ++; - if (0 == (adc_trigger & 31)) { + // enable the deferred ADC handler once in a while + if (! adc_trigger) { + /* redundant; it was already turned on earlier in this function // in case we're in standby mode and the ADC is turned off if (go_to_standby) { //set_admux_voltage(); ADC_on(); } + */ ADC_start_measurement(); - // allow regulation logic to run adc_deferred_enable = 1; } + // timing for the ADC handler is every 32 ticks (~2Hz) + adc_trigger = (adc_trigger + 1) & 31; #endif } -- cgit v1.2.3 From 46e0f50a224c300b7e66ef00719edc0cef1f4c8d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 16 Mar 2020 00:15:19 -0600 Subject: deleted commented-out WDT code from previous revision (had only saved it so there would be a note in history about why it's gone) --- spaghetti-monster/fsm-wdt.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 9858e09..94266c1 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -180,13 +180,6 @@ void WDT_inner() { #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) // enable the deferred ADC handler once in a while if (! adc_trigger) { - /* redundant; it was already turned on earlier in this function - // in case we're in standby mode and the ADC is turned off - if (go_to_standby) { - //set_admux_voltage(); - ADC_on(); - } - */ ADC_start_measurement(); adc_deferred_enable = 1; } -- cgit v1.2.3