1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#!/usr/bin/env python
from sys import stdout
# Table of ADC-value : Voltage
tab = {
# 360 : 4.2,
# 352 : 4.15,
# 334 : 4.1,
# 322 : 4.05,
# 320 : 4,
# 319 : 3.95,
# 318 : 3.9,
316 : 3.85,
313 : 3.8,
309 : 3.75,
300 : 3.7,
291 : 3.65,
287 : 3.6,
286 : 3.55,
282 : 3.5,
274 : 3.45,
# 259 : 3.4,
# 257 : 3.35,
# 256 : 3.3,
# 255 : 3.25,
# 254 : 3.2,
# 253 : 3.15,
# 252 : 3.1,
# 250 : 3.05,
# 247 : 3,
}
print "/**************************"
print " * THIS FILE IS GENERATED *"
print " * DO NOT EDIT! *"
print " **************************/"
print ""
print "#include <avr/pgmspace.h>"
print ""
print ""
print "/* Analog-digital-converter-7 value to voltage table. */"
col = 0
stdout.write("static const prog_uint8_t battery_adc7_tab[] = {")
for i in range(min(tab), max(tab) + 1):
try:
volt = tab[i]
except KeyError: pass
value = (volt * 100) - 300
if col % 7 == 0:
stdout.write("\n\t%3d," % value)
else:
stdout.write(" %3d," % value)
col += 1
stdout.write("\n};\n\n")
print "/* The ADC value that matches table index 0. */"
print "#define ADC7_MIN %d" % min(tab)
print "/* The ADC value that matches table index sizeof(table)-1. */"
print "#define ADC7_MAX %d" % max(tab)
print "/* Macro to convert a table value to millivolts. */"
print "#define batt_adc7_millivolts(v) (((v) + 300) * 10)"
|