aboutsummaryrefslogtreecommitdiff
path: root/bin/dac-scale.py
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-30 09:19:45 -0700
committerSelene ToyKeeper2023-11-30 09:19:45 -0700
commitf745e12c3bc48d8fe544893871191086cf3cccc9 (patch)
tree0e7f6c2c5f362719ac4efad9d5c2365f3ed3c159 /bin/dac-scale.py
parentadded md5sum to build-all.sh output per target (diff)
parenteliminated direct CCP register access from arch/attiny1616 (diff)
downloadanduril-f745e12c3bc48d8fe544893871191086cf3cccc9.tar.gz
anduril-f745e12c3bc48d8fe544893871191086cf3cccc9.tar.bz2
anduril-f745e12c3bc48d8fe544893871191086cf3cccc9.zip
Merge branch 'avr32dd20-devkit' into trunk
Added support for AVR DD MCUs, particularly avr32dd20. Also did a bunch of refactoring for how MCU support works, cleaned up the ADC code, switched to consistent internal formats for voltage and temperature, fixed the FW3X, and some other little things. * avr32dd20-devkit: (28 commits) eliminated direct CCP register access from arch/attiny1616 made the avr32dd20 flashing script more universal added a build target for FW3X with manually-fixed RGB aux wiring prevent future issues like the FW3X had fixed FW3X thermal regulation fixed incorrect temperature history for a few seconds after waking fsm/adc: removed dead code FW3X: fixed external temperature sensor FW3X: multiple upgrades... fw3x: fixed swapped red+blue, fixed battery measurements, added police color strobe fixed ADC on sp10-pro fixed ADC on attiny85 and related builds fixed ADC on attiny1634 and related builds more ADC / DAC / MCU progress... avr32dd20-devkit: make the defaults a bit more dev friendly (realtime voltage colors, and no simple UI by default) ADC voltage: battcheck 3 digits, fixed t1616, switched back to 8-bit internal volt unit got ADC voltage+temp working on avrdd... but broke all other builds/MCUs 1.55V AA battery should not show as "white" voltage color, only purple started refactoring fsm/adc.*, but need a checkpoint before continuing added dac-scale.py: short script to calculate avrdd DAC+Vref values from level_calc.py ramp data ...
Diffstat (limited to '')
-rwxr-xr-xbin/dac-scale.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/bin/dac-scale.py b/bin/dac-scale.py
new file mode 100755
index 0000000..d57f8c9
--- /dev/null
+++ b/bin/dac-scale.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+#
+# Calculates DAC values and Vref values from a list of raw intensity values
+# Usage: dac-scale.py 5,11,18,25,...,370474,384985,400000
+# Output: #defines suitable for use in hw/*/anduril.h
+# Assumptions:
+# - DAC data range is 0 to 1023
+# - DAC Vrefs are 1.024V and 2.5V
+# - HDR is available and has 2 steps
+# - HDR channel ratio is "highest_ramp_value / 2500"
+#
+# Output values thus have 4 "engine gears":
+# - HDR low , 1.024V Vref
+# - HDR low , 2.5 V Vref
+# - HDR high, 1.024V Vref
+# - HDR high, 2.5 V Vref
+#
+
+def main(args):
+ max_pwm = 1023
+ raw_pwm = [int(x) for x in args[0].split(',')]
+ ratio = raw_pwm[-1] / 2500.0
+ cooked = [[]]
+
+ def limit(p):
+ return min(max_pwm, int(p))
+
+ phase = 0
+ for raw in raw_pwm:
+ if 0 == phase:
+ if raw <= 1023:
+ cooked[-1].append(limit(raw))
+ else:
+ phase += 1
+ cooked.append([])
+ if 1 == phase:
+ if raw <= int(2500):
+ cooked[-1].append(limit(raw * 1.024 / 2.5))
+ else:
+ phase += 1
+ cooked.append([])
+ if 2 == phase:
+ if raw <= int(1024 * ratio):
+ cooked[-1].append(limit(raw / ratio))
+ else:
+ phase += 1
+ cooked.append([])
+ if 3 == phase:
+ cooked[-1].append(limit(raw * 1.024 / 2.5 / ratio))
+
+ # "gear change" boundaries
+ b1 = len(cooked[0])
+ b2 = b1 + len(cooked[1])
+ b3 = b2 + len(cooked[2])
+ b4 = b3 + len(cooked[3])
+
+ #print(','.join(['%4i' % n for n in cooked]))
+
+ def fmt_pwms(l):
+ return ','.join(['%4i' % n for n in l])
+
+ def fmt_tops(v, l):
+ return ','.join([' %s' % v for n in l])
+
+ lines = []
+
+ lines.append('// top level for each "gear": %i %i %i %i' % (b1, b2, b3, b4))
+
+ lines.append('#define PWM1_LEVELS \\')
+ lines.append(' ' + fmt_pwms(cooked[0]) + ', \\')
+ lines.append(' ' + fmt_pwms(cooked[1]) + ', \\')
+ lines.append(' ' + fmt_pwms(cooked[2]) + ', \\')
+ lines.append(' ' + fmt_pwms(cooked[3]))
+ lines.append('#define PWM2_LEVELS \\')
+ lines.append(' ' + fmt_tops('V10', cooked[0]) + ', \\')
+ lines.append(' ' + fmt_tops('V25', cooked[1]) + ', \\')
+ lines.append(' ' + fmt_tops('V10', cooked[2]) + ', \\')
+ lines.append(' ' + fmt_tops('V25', cooked[3]))
+
+ lines.append('#define MAX_1x7135 %3i' % b2)
+ lines.append('#define HDR_ENABLE_LEVEL_MIN %3i' % (b2+1))
+
+ print('\n'.join(lines))
+
+if __name__ == "__main__":
+ import sys
+ main(sys.argv[1:])
+