Cheap ADC Multiplexing for HID and powerwall-BMS

What are you developing?
Post Reply
jeremy777
Posts: 5
Joined: Thu Sep 14, 2017 7:02 pm

Cheap ADC Multiplexing for HID and powerwall-BMS

Post by jeremy777 » Sun Oct 15, 2017 1:35 pm

I'm developing two threads of multiplexed input (because 9 inputs in nowhere near enough) one for simple MIDI modwheels, the other for monitoring individual cell voltages and various system currents in a diy lithium powerwall project. Perversely, the MIDI controller is going to be by far the more expensive project simply because of the cost of the pots...

I'm basing both projects on the maple mini for it's 2Msps 12-bit ADC and low cost/small size solderable boards, but the circuit design could be used effectively with almost any microcontroller.

The principle of this multiplexing is simple: present only one row of analog signals to the input pins at a time, with diode's or reverse-biased transistors blocking interference from the other rows.

Circuit for the MIDI controller: (only 2 rows of 2 knobs each shown)
MIDI controller circuit (small).jpg
MIDI controller circuit (small).jpg (55.2 KiB) Viewed 86 times
For those of you for whom this circuit isn't immediately obvious, the principle of operation is simple: the row select pins are active low, when low the row driver transistor is turned on and the pots give a voltage relative to their position to the pots transistor. whichever pot in each group has the highest voltage (the one which is turned on) will control the analog input pin. With the Vreg set to 4.3 volts (3.3V rail + ((3k3+6k8)/6k8)×(Vbe of transistor) ) a slight reduction is still needed of 10/11 to keep the input within 3.3V. The regulator is needed because not all USB ports provide the same voltage, a range from 4.5V to 5.5V could happen. The 3-transistor design is so that it can regulate well into the saturation range of the driving transistor to accommodate the lowest of the input range (only 0.2V headroom).

The choice of transistor isn't that critical - I'm listing 2N2222 and 2N3904 because they are supposedly quicker at switching than the BC546/556 that I have in stock, but even with the relatively slow BC546/556's it can work fine with enough time for settling between row changes. I am sampling all ten inputs continuously in pages of 20, discarding the first 4 rows to allow for settling time and giving 16 times oversampling. Hopefully less settling time will be needed with the 2N2222/3904's.




Partial circuit for the Battery Monitor: (just 2 inputs on one ADCin shown)
BMS-input-scan-small.jpg
BMS-input-scan-small.jpg (235.81 KiB) Viewed 86 times
In case my pencil notes and margin calculations don't make sense, I'll explain more.

I am building a diy powerwall from old lithium 18650 cells and in my researches I've come across many people using very expensive BMS systems, or coming up with expensive and impractical diy ideas like using solid-state relays to move the entire arduino to connect to each cell in turn.

This design can measure 27 independent 5-volt differential inputs anywhere between 0V and +70V, for less than £1.50 (if you get the components at the best prices I've found on ebay). With sufficient multisampling I'm getting 3 sets of 27 values each second with about 15bit precision before noise (0.15mV accuracy).

The diode inside the negative feedback loop of the differential amplifier means that only the highest op-amp has control of that input pin. The transistors pulling on the positive input form a current mirror fed by the select pin that should drop the input pin by about 3V, sending the op-amp's output to zero. Again, The select pins are active low, so when the row is selected the pull-down is inactive and the op-amp passes it's input differential to the output beyond the diode since this is where the nfb is connected. Because of the differential input resistor dividers set so that a 5V input will give a 3.3V output (150kΩ input, 100kΩ fb) the op-amp's inputs only rise to 2/5ths of the input voltage. The LM358 can have up to 30V power and inputs up to 2V below that, so 28V × 5/2 = 70V maximum input - enough for a 16-cell lithium pack to reach 4.2V/cell.

With so many extra inputs I can also have several ACS712 based current-sensors as well, since the DC system is complex and I want to see where my power is going. These can be modified with the addition of a few 1mΩ resistors to read ranges up to 350Amps with moderate accuracy.

My intention for the rest of the system is to have these values fed by serial to a Raspberry Pi for logging and presentation to the home network as a web-page, and maybe have a small LCD screen showing current charge-state as well. This is a setup I have had working now for over a year with a pro-micro (ATmega32u4) based 8-channel data acquisition, and the Pi has been doing other things as well like web/update caching and nocturnal downloads.

Both these circuits have been tested in reduced form with BC546/556 but I must wait long time for my cheap components to arrive... I will post further results/photo's/code when these circuits are built.

Post Reply