diff options
| author | Selene ToyKeeper | 2019-12-17 18:35:30 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-12-17 18:35:30 -0700 |
| commit | 6fb89b14ecae8e629b9d8ad754f988804d273828 (patch) | |
| tree | b5cd330aed040cde14056c1788e72c41446976a4 /spaghetti-monster/fsm-adc.c | |
| parent | changed voltage colors to better match Noctigon K1 (diff) | |
| parent | fixed too-slow thermal response (was introduced in the irq-refactor branch) (diff) | |
| download | anduril-6fb89b14ecae8e629b9d8ad754f988804d273828.tar.gz anduril-6fb89b14ecae8e629b9d8ad754f988804d273828.tar.bz2 anduril-6fb89b14ecae8e629b9d8ad754f988804d273828.zip | |
merged from fsm, mostly to get thermal regulation updates
Diffstat (limited to 'spaghetti-monster/fsm-adc.c')
| -rw-r--r-- | spaghetti-monster/fsm-adc.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index b8b00de..2a3c5c6 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -276,6 +276,8 @@ static inline void ADC_temperature_handler() { #define OVERHEAT_LOWPASS_STRENGTH (ADC_CYCLES_PER_SECOND*2) // lowpass for 2 seconds #define UNDERHEAT_LOWPASS_STRENGTH (ADC_CYCLES_PER_SECOND*2) // lowpass for 2 seconds + // TODO: left-shift this so the lowpass can get higher resolution + // TODO: increase the sampling rate, to keep the lowpass from lagging uint16_t measurement = adc_values[1]; // latest 10-bit ADC reading // Convert ADC units to Celsius (ish) @@ -322,15 +324,16 @@ static inline void ADC_temperature_handler() { // if it's time to rotate the thermal history, do it history_step ++; #if (THERMAL_UPDATE_SPEED == 4) // new value every 4s - #define THERM_HISTORY_STEP_MAX ((2*ADC_CYCLES_PER_SECOND)-1) + #define THERM_HISTORY_STEP_MAX (4*ADC_CYCLES_PER_SECOND) #elif (THERMAL_UPDATE_SPEED == 2) // new value every 2s - #define THERM_HISTORY_STEP_MAX (ADC_CYCLES_PER_SECOND-1) + #define THERM_HISTORY_STEP_MAX (2*ADC_CYCLES_PER_SECOND) #elif (THERMAL_UPDATE_SPEED == 1) // new value every 1s - #define THERM_HISTORY_STEP_MAX ((ADC_CYCLES_PER_SECOND/2)-1) + #define THERM_HISTORY_STEP_MAX (ADC_CYCLES_PER_SECOND) #elif (THERMAL_UPDATE_SPEED == 0) // new value every 0.5s - #define THERM_HISTORY_STEP_MAX ((ADC_CYCLES_PER_SECOND/4)-1) + #define THERM_HISTORY_STEP_MAX (ADC_CYCLES_PER_SECOND/2) #endif - if (0 == (history_step & THERM_HISTORY_STEP_MAX)) { + if (THERM_HISTORY_STEP_MAX == history_step) { + history_step = 0; // rotate measurements and add a new one for (uint8_t i=0; i<NUM_THERMAL_VALUES_HISTORY-1; i++) { temperature_history[i] = temperature_history[i+1]; |
