aboutsummaryrefslogtreecommitdiff
path: root/hw/thefreeman/avr32dd20-devkit/hwdef.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2024-03-27 07:13:26 -0600
committerSelene ToyKeeper2024-03-27 07:13:26 -0600
commit7b49797be1da97f54e9df3a1b0342ab20d7f02d5 (patch)
tree1aab20b6979c781419fc61c8be73facf332ad8e2 /hw/thefreeman/avr32dd20-devkit/hwdef.c
parentfixed inaccurate comment (thanks to xikteny for spotting it) (diff)
downloadanduril-7b49797be1da97f54e9df3a1b0342ab20d7f02d5.tar.gz
anduril-7b49797be1da97f54e9df3a1b0342ab20d7f02d5.tar.bz2
anduril-7b49797be1da97f54e9df3a1b0342ab20d7f02d5.zip
increased voltage precision from 0.025V to 0.02V
(so 0 to 255 now goes from 0.00V to 5.10V)
Diffstat (limited to 'hw/thefreeman/avr32dd20-devkit/hwdef.c')
-rw-r--r--hw/thefreeman/avr32dd20-devkit/hwdef.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.c b/hw/thefreeman/avr32dd20-devkit/hwdef.c
index 460082f..5b534d2 100644
--- a/hw/thefreeman/avr32dd20-devkit/hwdef.c
+++ b/hw/thefreeman/avr32dd20-devkit/hwdef.c
@@ -119,13 +119,13 @@ bool gradual_tick_main(uint8_t gt) {
uint8_t voltage_raw2cooked(uint16_t measurement) {
// In : 65535 * BATTLVL / 1.024V
- // Out: uint8_t: Vbat * 40
+ // Out: uint8_t: Vbat * 50
// BATTLVL = Vbat * (100.0/(330+100)) = Vbat / 4.3
- // So, Out = In * 4.3 / 1600
+ // So, Out = In * 4.3 / 1280
// (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;
+ * 43 / 12880;
return result;
}