diff options
| author | Selene ToyKeeper | 2024-03-12 14:30:19 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2024-03-12 14:30:19 -0600 |
| commit | 26a30c2171fcfd7ab12666059ac855a0c1538daf (patch) | |
| tree | 3ee0ffa31a19f53e8e016ff923108cd2854685fc /arch | |
| parent | Merge branch 'trunk' into wurkkos-ts25-boost (diff) | |
| download | anduril-26a30c2171fcfd7ab12666059ac855a0c1538daf.tar.gz anduril-26a30c2171fcfd7ab12666059ac855a0c1538daf.tar.bz2 anduril-26a30c2171fcfd7ab12666059ac855a0c1538daf.zip | |
attiny1616 mcu_vdivider_raw2cooked: factor in the offset, not just slope
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/attiny1616.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/arch/attiny1616.c b/arch/attiny1616.c index c5499dd..317552d 100644 --- a/arch/attiny1616.c +++ b/arch/attiny1616.c @@ -129,14 +129,15 @@ inline uint16_t mcu_vdd_raw2fine(uint16_t measurement) { #ifdef USE_VOLTAGE_DIVIDER inline uint8_t mcu_vdivider_raw2cooked(uint16_t measurement) { - // In : 4095 * Vdiv / 1.1V + // In : (4095 * Vdiv / 1.1V) << 4 // Out: uint8_t: Vbat * 40 // Vdiv = Vbat / 4.3 (typically) // 1.1 = ADC Vref const uint16_t adc_per_volt = (((uint16_t)ADC_44 << 4) - ((uint16_t)ADC_22 << 4)) / (4 * (44-22)); - uint8_t result = measurement / adc_per_volt; + const uint16_t adc_offset = (ADC_22 - (ADC_44 - ADC_22)) << 4; + uint8_t result = (measurement - adc_offset) / adc_per_volt; return result; } #endif |
