diff options
| author | Selene ToyKeeper | 2023-11-28 10:30:04 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-11-28 10:30:04 -0700 |
| commit | 00af846f2d4d269a447d27f6ce2b0307f18bdca8 (patch) | |
| tree | 36e8b376d0e21f1f5210bbeb6f948aa0265f41ee | |
| parent | FW3X: multiple upgrades... (diff) | |
| download | anduril-00af846f2d4d269a447d27f6ce2b0307f18bdca8.tar.gz anduril-00af846f2d4d269a447d27f6ce2b0307f18bdca8.tar.bz2 anduril-00af846f2d4d269a447d27f6ce2b0307f18bdca8.zip | |
FW3X: fixed external temperature sensor
(the MCU's internal sensor works too, but external is a bit better I guess?)
Diffstat (limited to '')
| -rw-r--r-- | hw/lumintop/fw3x-lume1/hwdef.c | 32 | ||||
| -rw-r--r-- | hw/lumintop/fw3x-lume1/hwdef.h | 16 |
2 files changed, 41 insertions, 7 deletions
diff --git a/hw/lumintop/fw3x-lume1/hwdef.c b/hw/lumintop/fw3x-lume1/hwdef.c index 0a8a62e..791a080 100644 --- a/hw/lumintop/fw3x-lume1/hwdef.c +++ b/hw/lumintop/fw3x-lume1/hwdef.c @@ -108,3 +108,35 @@ bool gradual_tick_main(uint8_t gt) { return false; // not done yet } +////////// external temperature sensor ////////// + +void hwdef_set_admux_therm() { + // put the ADC in temperature mode + // ADCSRB: [VDEN, VDPD, -, -, ADLAR, ADTS2, ADTS1, ADTS0] + ADCSRB = (1 << ADLAR); // left-adjust, free-running + // DS table 19-3, 19-4 + // [refs1, refs0, refen, adc0en, mux3, mux2, mux1, mux0] + // refs=0b00 : VCC (2.5V) + // mux=0b1011 : ADC11 (pin PC2) + ADMUX = ADMUX_THERM_EXTERNAL_SENSOR; + // other stuff is already set, so no need to re-set it +} + +uint16_t temp_raw2cooked(uint16_t measurement) { + // In: (raw ADC average) << 6 + // Out: Kelvin << 6 + /* notes from old versions of the code... + // Used for Lume1 Driver: MCP9700 - T_Celsius = 100*(VOUT - 0.5V) + // ADC is 2.5V reference, 0 to 1023 + // due to floating point, this calculation takes 916 extra bytes + // (should use an integer equivalent instead) + //#define EXTERN_TEMP_FORMULA(m) (((m)-205)/4.09) + //int16_t celsius = (((measurement-205)/4.09)) + THERM_CAL_OFFSET + (int16_t)therm_cal_offset; + */ + + // this formula could probably be simplified... but meh, it works + uint16_t k6 = ((uint32_t)(measurement - (205 << 6)) * 100 / 409) + + (273 << 6); // convert back from C to K + return k6; +} + diff --git a/hw/lumintop/fw3x-lume1/hwdef.h b/hw/lumintop/fw3x-lume1/hwdef.h index bee98db..92a177f 100644 --- a/hw/lumintop/fw3x-lume1/hwdef.h +++ b/hw/lumintop/fw3x-lume1/hwdef.h @@ -142,13 +142,15 @@ uint8_t ch1_pwm, ch1_dsm; // Modified fsm-adc.c to use different ADMUX and ADC_temperature_handler() // based on USE_EXTERNAL_TEMP_SENSOR // See line 34 and line 209 -#define USE_EXTERNAL_TEMP_SENSOR -#define ADMUX_THERM_EXTERNAL_SENSOR 0b00001011 // VCC reference (2.5V), Channel PC2 -// Used for Lume1 Driver: MCP9700 - T_Celsius = 100*(VOUT - 0.5V) -// ADC is 2.5V reference, 0 to 1023 -// FIXME: due to floating point, this calculation takes 916 extra bytes -// (should use an integer equivalent instead) -#define EXTERN_TEMP_FORMULA(m) (((m)-205)/4.09) +//#define USE_EXTERNAL_TEMP_SENSOR + +// override the default temperature sensor code +#undef hwdef_set_admux_therm +void hwdef_set_admux_therm(); +#undef temp_raw2cooked +uint16_t temp_raw2cooked(uint16_t measurement); +// VCC reference (2.5V), Channel PC2 +#define ADMUX_THERM_EXTERNAL_SENSOR 0b00001011 // this driver allows for aux LEDs under the optic #define AUXLED_R_PIN PA3 // pin 2 |
