aboutsummaryrefslogtreecommitdiff
path: root/hw/thefreeman/avr32dd20-devkit/hwdef.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/thefreeman/avr32dd20-devkit/hwdef.c')
-rw-r--r--hw/thefreeman/avr32dd20-devkit/hwdef.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.c b/hw/thefreeman/avr32dd20-devkit/hwdef.c
index e5b347f..133baca 100644
--- a/hw/thefreeman/avr32dd20-devkit/hwdef.c
+++ b/hw/thefreeman/avr32dd20-devkit/hwdef.c
@@ -103,3 +103,16 @@ bool gradual_tick_main(uint8_t gt) {
return false; // not done yet
}
+
+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)
+ // 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);
+ return result;
+}
+