One of my biggest fears for the Arduino code is that a bug will turn on inappropriate analog switches, resulting in a short or other undesired connection, probably damaging either the mux chip or the Arduino itself. To help avoid that, I should probably have an “all off” function that is called after every voltage measurement. Before each measurement, a function that turns on just the desired connections should be called.
The turn on function probably needs 2 params in:
- type (total V, current, cell V)
- cell # (only used for cell V)
Code is pretty simple:
- setup – port inits, etc
- initialize/config dialog over serial port
- wait for start command
- maybe initial open circuit voltage?
- turn on relay
- main loop
- loop thru N cells, measure each voltage
- measure current
- measure total voltage
- spit out this cycle’s measurements to serial or eeprom
- if total voltage < threshold, turn off relay, end
- sleep
- end code – maybe some arithmetic?
Hmm – does the “measure the voltage” function need to take an input parameter of whether to use 5V as its scale or use the 2.4V Zener reference voltage I supply? The cell measurements are all nicely under 2.4V. The current sense is 0.2V at 2 amps, so that’s small. And I guess I can scale the total end-end voltage to whatever I want – so I guess that one’s OK as well. I suppose I could get twice the resolution for current sense if I switched to the internal 1.1V reference voltage for that measurement. For the 3 lines of code, it’s probably worth it.