aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2020-02-05 22:12:45 -0700
committerSelene ToyKeeper2020-02-05 22:12:45 -0700
commit46af6026a2dc2bae92d41609a8ecd6144082825e (patch)
tree1ebd699f0a26176bec773ac71faa9edca4783413 /spaghetti-monster
parentfirst pass at a smaller simpler thermal regulation algorithm... (diff)
downloadanduril-46af6026a2dc2bae92d41609a8ecd6144082825e.tar.gz
anduril-46af6026a2dc2bae92d41609a8ecd6144082825e.tar.bz2
anduril-46af6026a2dc2bae92d41609a8ecd6144082825e.zip
still doesn't work, but at least it's a bit less broken than before...
(ceiling value was all wrong, and the response magnitude was way too big) (also, temperatures here are unsigned, since freezing is about 270 in ADC units)
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/fsm-adc.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index d1efff3..2df884e 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -275,7 +275,7 @@ static inline void ADC_voltage_handler() {
static inline void ADC_temperature_handler() {
// coarse adjustment
#ifndef THERM_LOOKAHEAD
- #define THERM_LOOKAHEAD 5 // can be tweaked per build target
+ #define THERM_LOOKAHEAD 3 // can be tweaked per build target
#endif
// fine-grained adjustment
// how proportional should the adjustments be? (not used yet)
@@ -323,7 +323,7 @@ static inline void ADC_temperature_handler() {
history_step = (history_step + 1) & (NUM_TEMP_HISTORY_STEPS-1);
// PI[D]: guess what the temperature will be in a few seconds
- int16_t pt; // predicted temperature
+ uint16_t pt; // predicted temperature
pt = measurement + (diff * THERM_LOOKAHEAD);
// P[I]D: average of recent measurements
@@ -331,11 +331,15 @@ static inline void ADC_temperature_handler() {
for(uint8_t i=0; i<NUM_TEMP_HISTORY_STEPS; i++)
avg += (temperature_history[i]>>3);
- uint16_t ceil = therm_ceil << 6;
+ // convert temperature limit from C to raw 16-bit ADC units
+ // C = (ADC>>6) - 275 + THERM_CAL_OFFSET + therm_cal_offset;
+ // ... so ...
+ // (C + 275 - THERM_CAL_OFFSET - therm_cal_offset) << 6 = ADC;
+ uint16_t ceil = (therm_ceil + 275 - therm_cal_offset - THERM_CAL_OFFSET) << 6;
//uint16_t floor = ceil - (THERM_WINDOW_SIZE << 6);
int16_t offset_pt, offset_avg;
- offset_pt = pt - ceil;
- offset_avg = avg - ceil;
+ offset_pt = (pt - ceil) >> 1;
+ offset_avg = (avg - ceil) >> 1;
int16_t offset = offset_pt + offset_avg;
//int16_t offset = (pt - ceil) + (avg - ceil);
@@ -351,7 +355,7 @@ static inline void ADC_temperature_handler() {
temperature_timer = TEMPERATURE_TIMER_START;
// how far above the ceiling?
//int16_t howmuch = (offset >> 6) * THERM_RESPONSE_MAGNITUDE / 128;
- int16_t howmuch = (offset >> 6);
+ int16_t howmuch = (offset >> 8);
// send a warning
emit(EV_temperature_high, howmuch);
}
@@ -359,12 +363,12 @@ static inline void ADC_temperature_handler() {
// Too cold?
// (if it's too cold and not getting warmer...)
else if ((offset < -(THERM_WINDOW_SIZE << 6))
- && (diff < (1 << 5))) {
+ && (diff < (1 << 4))) {
// reset counters
temperature_timer = TEMPERATURE_TIMER_START;
// how far below the floor?
//int16_t howmuch = (((-offset) - (THERM_WINDOW_SIZE<<6)) >> 7) * THERM_WINDOW_SIZE / 128;
- int16_t howmuch = ((-offset) - (THERM_WINDOW_SIZE<<6)) >> 7;
+ int16_t howmuch = ((-offset) - (THERM_WINDOW_SIZE<<6)) >> 9;
// send a notification (unless voltage is low)
// (LVP and underheat warnings fight each other)
if (voltage > VOLTAGE_LOW)
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.