aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2018-01-24 18:27:44 -0700
committerSelene ToyKeeper2018-01-24 18:27:44 -0700
commit30b13cc13baba55ac1610ad471ca737a6c817683 (patch)
treea3893755b1a446b5d93b446eedeaebedd85a2768 /spaghetti-monster
parentMade thermal adjustment speed change depending on how far it needs to go. (diff)
downloadanduril-30b13cc13baba55ac1610ad471ca737a6c817683.tar.gz
anduril-30b13cc13baba55ac1610ad471ca737a6c817683.tar.bz2
anduril-30b13cc13baba55ac1610ad471ca737a6c817683.zip
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)
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/fsm-adc.c25
-rw-r--r--spaghetti-monster/fsm-adc.h1
-rw-r--r--spaghetti-monster/fsm-wdt.c4
3 files changed, 20 insertions, 10 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index 839fba8..d863b94 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -44,6 +44,13 @@ inline void ADC_off() {
#endif
// TODO: is this better done in main() or WDT()?
ISR(ADC_vect) {
+ // For some reason, the ADC interrupt is getting called a *lot*
+ // more often than it should be, like it's auto-triggering after each
+ // measurement, but I don't know why, or how to turn that off...
+ // So, skip every call except when explicitly requested.
+ if (! adcint_enable) return;
+ adcint_enable = 0;
+
static uint8_t adc_step = 0;
// LVP declarations
@@ -218,11 +225,13 @@ ISR(ADC_vect) {
// average prediction to reduce noise
int16_t avg_projected_temperature = 0;
- for (uint8_t i = 0;
+ uint8_t i;
+ for (i = 0;
(i < NUM_THERMAL_PROJECTED_HISTORY) && (avg_projected_temperature < 16000);
i++)
avg_projected_temperature += projected_temperature_history[i];
avg_projected_temperature /= NUM_THERMAL_PROJECTED_HISTORY;
+ //avg_projected_temperature /= i;
// cancel counters if appropriate
if (pt > THERM_FLOOR) {
@@ -240,15 +249,15 @@ ISR(ADC_vect) {
if (overheat_lowpass < OVERHEAT_LOWPASS_STRENGTH) {
overheat_lowpass ++;
} else {
+ // reset counters
+ overheat_lowpass = 0;
+ temperature_timer = TEMPERATURE_TIMER_START;
// how far above the ceiling?
int16_t howmuch = (avg_projected_temperature - THERM_CEIL) >> THERM_DIFF_ATTENUATION;
if (howmuch > 0) {
// try to send out a warning
emit(EV_temperature_high, howmuch);
}
- // reset counters
- temperature_timer = TEMPERATURE_TIMER_START;
- overheat_lowpass = 0;
}
}
@@ -257,6 +266,9 @@ ISR(ADC_vect) {
if (underheat_lowpass < UNDERHEAT_LOWPASS_STRENGTH) {
underheat_lowpass ++;
} else {
+ // reset counters
+ underheat_lowpass = 0;
+ temperature_timer = TEMPERATURE_TIMER_START;
// how far below the floor?
int16_t howmuch = (THERM_FLOOR - avg_projected_temperature) >> THERM_DIFF_ATTENUATION;
if (howmuch > 0) {
@@ -265,9 +277,6 @@ ISR(ADC_vect) {
if (voltage > VOLTAGE_LOW)
emit(EV_temperature_low, howmuch);
}
- // reset counters
- temperature_timer = TEMPERATURE_TIMER_START;
- underheat_lowpass = 0;
}
}
}
@@ -275,7 +284,7 @@ ISR(ADC_vect) {
#endif // ifdef USE_THERMAL_REGULATION
- // start another measurement for next time
+ // set the correct type of measurement for next time
#ifdef USE_THERMAL_REGULATION
#ifdef USE_LVP
if (adc_step < 2) ADMUX = ADMUX_VCC;
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();
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c
index 777bef0..ff96ffb 100644
--- a/spaghetti-monster/fsm-wdt.c
+++ b/spaghetti-monster/fsm-wdt.c
@@ -107,9 +107,9 @@ ISR(WDT_vect) {
// start a new ADC measurement every 4 ticks
static uint8_t adc_trigger = 0;
adc_trigger ++;
- if (adc_trigger > 3) {
- adc_trigger = 0;
+ if (0 == (adc_trigger & 3)) {
ADCSRA |= (1 << ADSC) | (1 << ADIE);
+ adcint_enable = 1;
}
#endif
}
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.