diff options
Diffstat (limited to 'hw/thefreeman/avr32dd20-devkit')
| -rw-r--r-- | hw/thefreeman/avr32dd20-devkit/hwdef.c | 16 | ||||
| -rw-r--r-- | hw/thefreeman/avr32dd20-devkit/hwdef.h | 6 |
2 files changed, 11 insertions, 11 deletions
diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.c b/hw/thefreeman/avr32dd20-devkit/hwdef.c index 133baca..3e5dd79 100644 --- a/hw/thefreeman/avr32dd20-devkit/hwdef.c +++ b/hw/thefreeman/avr32dd20-devkit/hwdef.c @@ -104,15 +104,15 @@ bool gradual_tick_main(uint8_t gt) { } -uint16_t voltage_raw2cooked(uint16_t measurement) { - // In : 65535 * BATTLVL pin / 1.024 Vref - // Out: 65535 * (Vbat / 10) / 1.024V (i.e. FSM Volt units) +uint8_t voltage_raw2cooked(uint16_t measurement) { + // In : 65535 * BATTLVL / 1.024V + // Out: uint8_t: Vbat * 40 // BATTLVL = Vbat * (100.0/(330+100)) = Vbat / 4.3 - // So, Out = In * 4.3 / 10.24 - // (plus 1.5% based on measured hardware) - // (plus a fudge factor of +0.04V to round up to nearest 1/10th Volt) - uint16_t result = ((uint32_t)measurement * 436 / 1024) - + (65535 * 4 / 1024); + // So, Out = In * 4.3 / 1600 + // (plus a bit of fudging to fix the slope and offset, + // based on measuring actual hardware) + uint8_t result = (uint32_t)(measurement + (65535 * 4 / 1024)) + * 43 / 16128; return result; } diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.h b/hw/thefreeman/avr32dd20-devkit/hwdef.h index 7e1ad3d..a5b37a9 100644 --- a/hw/thefreeman/avr32dd20-devkit/hwdef.h +++ b/hw/thefreeman/avr32dd20-devkit/hwdef.h @@ -111,11 +111,11 @@ enum CHANNEL_MODES { // AVR datasheet table 3.1 I/O Multiplexing, PA6 ADC0 = AIN26 #define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is regulated #define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN26_gc -#define DUAL_VOLTAGE_FLOOR 21 // for AA/14500 boost drivers, don't indicate low voltage if below this level -#define DUAL_VOLTAGE_LOW_LOW 7 // the lower voltage range's danger zone 0.7 volts (NiMH) +#define DUAL_VOLTAGE_FLOOR (4*21) // for AA/14500 boost drivers, don't indicate low voltage if below this level +#define DUAL_VOLTAGE_LOW_LOW (4*7) // the lower voltage range's danger zone 0.7 volts (NiMH) // convert BATT LVL pin readings to FSM volt units #undef voltage_raw2cooked -uint16_t voltage_raw2cooked(uint16_t measurement); +uint8_t voltage_raw2cooked(uint16_t measurement); // average drop across diode on this hardware |
