ADC for 8 button input to 8 bit - Page 1
Forum section: electronics / general

author: harveyf2801
author_rank: Newbie
timestamp: November 13, 2021, 12:47:18 am
content: Hi folks, for a uni project I’m creating a synth using an Arduino. I want to have at a minimum 8 buttons for an input but I’m restricted to using only 1 or 2 input pins. Therefore I wanted to use an ADC to convert the input to binary values.I wanted to use no IC’s if possible so tried using an R2R DAC in reverse as an ADC but the issue I had was the buttons were floating and not grounded when open… tried using 10ohm resisters to ground each button and although it works , if increases the load… too high of resistance messes with the R2R structure.If anyone could help me with a solution/schematic it would be much appreciated.

author: langwadt
author_rank: Super Contributor
timestamp: November 13, 2021, 01:02:21 am
content: if you have two pins, PCF8575 or similar

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 13, 2021, 01:06:47 am
content: Whatever the solution you use, one thing to consider will be to handle the simultaneous press of several buttons. Even if you don't care about reacting to that, if not handled properly, it could just pass as the push of another button entirely. I think that's typically called "ghosting" for keyboards.Then, not quite sure you mean about ADC here. Can't you use the internal ADC of the microcontroller?Then an R2R ladder, driven by the buttons, could actually be used as a simple DAC, output a voltage and feed the ADC input of the MCU. Maybe that's actually what you meant, because I don't see how you could implement an ADC with only resistors, while getting the result on one or two digital outputs...

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 13, 2021, 01:08:21 am
content: Quote from: langwadt on November 13, 2021, 01:02:21 amYes, that'd be an option. But it's I2C. If the two pins the OP has available are not I2C pins, that's going to suck. Admittedly I don't know Arduino much and maybe they have implemented software I2C? (Although I don't know how robust that is.)

author: langwadt
author_rank: Super Contributor
timestamp: November 13, 2021, 01:15:11 am
content: Quote from: SiliconWizard on November 13, 2021, 01:08:21 amsoftware I2C is pretty simple and probably at least as if not more reliable than most HW I2C

author: PCB.Wiz
author_rank: Super Contributor
timestamp: November 13, 2021, 01:21:32 am
content: Quote from: harveyf2801 on November 13, 2021, 12:47:18 amYou can use resistor strings and buttons, but 8 is pushing it, if you want to detect any-of-8. If you are ok with single left-most-button priority detect (1 of N), that is easier.You could do 2 strings of N-of-4 buttons on 2 pins quite easily.Resistor strings give better error bands when current driven, to emulate that you can select the lowest reference voltage and a higher value feeder resistor.You may need to do a power-up or calibrate step that defines the 'no button closed' string voltage.I'll find a link ...Here is a SCH for a 1-of-7 button detect, via ADChttp://www.piclist.com/techref/microchip/sw7_on_1pin.htmand for N-of-5 button detect, see attached LTSpice .ASC file, that simulates a Series and Shunt 5-resistor string, so you can see the effects of LSB step size vs topology.Best step size is current fed, (2.62%/step) with button across each resistor (but that needs precision current source)Next best is a series R value equal to resistor-sum, range is 50% of VCC, smallest step is 0.82% of VCC for 5 buttons ( 2 strings of 4 buttons will have larger LSB step).This is how it plots

author: langwadt
author_rank: Super Contributor
timestamp: November 13, 2021, 01:33:34 am
content: could use a buffer (e.g. 74HC541 with pullups/pulldowns in the inputs) between the buttons and the R2R dac

author: Dave
author_rank: Super Contributor
timestamp: November 17, 2021, 04:41:18 pm
content: Here's a reliable circuit that I've created in the past.The operation is pretty straightforward.Veb of Q4A is going to be somewhat constant at around 0.6-0.7V. The current drawn by the resistors (through the switches) is then simply going to be (Vcc - Veb)/R. The resistances can simply be weighed in 2^n steps and the current on the mirror is going to be linearly proportional to the entered code on the switches. On the other side you have a resistor and a small filtering capacitor (which may be omitted) to convert that into voltage.Using a resistor network like that is very practical, because even though the nominal resistance tolerance might be 5%, the relative difference between the resistors is going to be very small, ensuring consistent steps vs the entered code. It's also a neat way to reduce tedious, repetitive resistor placing (especially when you're hand soldering prototypes).You could probably also omit the emitter degeneration resistors, because the two transistors are in the same package anyway, so thermally very well coupled.I wouldn't go for more than 4 switches per ADC input, as you'd be unnecessarily tightening the tolerance spec for the circuit. You don't want to have to calibrate this sort of circuit if you plan on producing multiple boards.

author: nctnico
author_rank: Super Contributor
timestamp: November 17, 2021, 10:27:38 pm
content: There are dedicated key-matrix chips for this purpose but another option is to use a serial to parallel and parallel to serial shift register (2 chips in total + diodes needed to create an 8x8 matrix for potentially 256 keys).

author: PCB.Wiz
author_rank: Super Contributor
timestamp: November 18, 2021, 05:14:47 am
content: Quote from: Dave on November 17, 2021, 04:41:18 pmKeep in mind the transistor matching is never perfect, generic dual-devices have almost no matching specs.You will need to find rarer matched-pair partshttps://www.nexperia.com/products/bipolar-transistors/special-feature-transistors/matched-pair-transistors/even here, the best 2% HFE match of PMP5201 family, is not a current mirror match of 2%, you need to include VBE effects too, which are about 3.5%/mV

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 18, 2021, 05:19:06 pm
content: Ahah, yeah. Let's get real =) A properly designed resistor ladder will work plenty fine. Beware of ghosting, though, as I said. That can be solved in several ways. But I think that matters whatever your option. That pressing several buttons at the same time might trigger a totally unexpected action is not good. That might look fun in a kind of easter egg way, but that's just poor design. So, at least give it a thought!

author: Dave
author_rank: Super Contributor
timestamp: November 18, 2021, 09:23:18 pm
content: You can't "properly" design an R-2R circuit with momentary switches. The inputs need to be connected to either Vref or GND, not high impedance.The circuit that I posted works reliably with some filtering code that ignores the intermediate voltages as they transition between two stable levels.