News:

SMF for DIYStompboxes.com!

Main Menu

Multple inputs in an ADC

Started by potul, March 31, 2011, 09:26:19 AM

Previous topic - Next topic

potul

Hi

I have the idea of using a single ADC of a PIC to input multiple switches, and it is a requirement to be able to press multiple switches at a time and still be able to know which ones...

I first thought it was an easy thing... just use an R2R ladder and feed the analog value to the ADC. Theoretically it should work if you have a series of digital signals, you combine them into an analog one and all you have to do in the PIC is read the ADC and each bit will correspond to one of the signals.

But... (there is always a but), I don't see how to implement this with simple switches. My switches are not spdt, but spst, so I can drive each signal to 1, but not to 0 from the switch. But if I add some sort of pulldown resistor I screw up the 2R2 network... and the values are not as easy to use.

I know I will still have somehow unique ADC values for each combination of keys, but I would then need to lookup the values. I would love to have a solution that is "linear".

I've tried other R network topologies, trying to find something that satisfies my needs, but so far I haven't found any.

Anyone has a clever idea?

Mat

slacker

You could try something like this, it will mess up the accuracy slightly but hopefully not enough to matter.



The only problem is with all the switches grounded it will draw a lot of current. Scaling up all the resistor values by 10 would probably be better.
Another way would be to buffer the switches with a CMOS chips like a CD4069 or CD40106.

MoltenVoltage

I don't think you can do what you want because the pin will always read the top voltage, so you can't tell what other switches are being pressed.

You might be able to pull it off with a circuit that takes in a current from a resistor ladder with binary value resistor values (e.g. 200, 400, 800, 1.6K, 3.2K, etc.) and outputs a voltage to the pin based on the current, but why bother with that.  Just use a PIC with more digital inputs and skip the ADC.
MoltenVoltage.com for PedalSync audio control chips - make programmable and MIDI-controlled analog pedals!

potul

Quote from: slacker on March 31, 2011, 01:49:29 PM
You could try something like this, it will mess up the accuracy slightly but hopefully not enough to matter.

Thanks, I will give it a try. I tried a similar approach but instead of adding pullup resistors add pulldown, and the accuracy wasn't good for my purposes, but I will try again with this approach. Definitively resistors need to be scaled up though.

Quote from: MoltenVoltage
I don't think you can do what you want because the pin will always read the top voltage, so you can't tell what other switches are being pressed.
Sorry, I don't get this.

Quote from: MoltenVoltage
You might be able to pull it off with a circuit that takes in a current from a resistor ladder with binary value resistor values (e.g. 200, 400, 800, 1.6K, 3.2K, etc.) and outputs a voltage to the pin based on the current, but why bother with that.  Just use a PIC with more digital inputs and skip the ADC.
A R2R ladder is my main starting point, a binary ladder also would work. The problem is always the same though, how to pull up/pull down without affecting the ladder ratios.
If I would want/could change the PIC I wouldn't ask.... and I love the challenges. :)

Mat

potul

Today I did a quick test with only 2 inputs (I ran out of resistors....), and it worked well with some adjustments (I had to add some offset to the ADC value to center it into the bins and avoid points "in the edge")
Of course, with 2 switches accuracy does not matter that much... Later this week if I find time to go and buy resistors I'll try with 6 switches.

Mat

earthtonesaudio



A bit more calculation required in choosing switch resistor values (must all be different, every parallel combination must generate a unique voltage, etc.) once the math is done it's a very simple solution.

potul

Thanks for the idea.

this is the first approach I tried, but I was looking for something that does not require exotic values, and that I can simply take the ADC reading, and use the most significant bits as indicators of each switch status, instead of doing some lookup values.

I think the R2R approach with the small pull-up resistor will do the trick. I will try asap.

Mat

MoltenVoltage

#7
You need the exotic values or some way to generate unique voltages for every permutation.

I believe you will hit the limit at 5! with an 8 bit ADC and 6! with 10 or 12 bit.
MoltenVoltage.com for PedalSync audio control chips - make programmable and MIDI-controlled analog pedals!

slacker

#8
I don't get what you mean, using an 8 bit DAC, for example, gives you 256 unique voltages corresponding to 256 unique binary numbers on the inputs. If you use an R-2R DAC you can build this with 2 resistor values.
So in theory you can use a DAC to convert an 8 bit binary number into a voltage, run that through a ADC and convert it back into the same binary number. In reality you'd need really accurate DACs and ADCs to do this, especially if you both your converters were 8 bit. Potul only wants a 6 bit DAC though and should be able to sample this at a higher resolution with the PIC, which gives some room for inaccuracies in the conversion, so I can't see why this won't work.

potul

Quote from: slacker on April 02, 2011, 06:15:25 AM
I don't get what you mean, using an 8 bit DAC, for example, gives you 256 unique voltages corresponding to 256 unique binary numbers on the inputs. If you use an R-2R DAC you can build this with 2 resistor values.
So in theory you can use a DAC to convert an 8 bit binary number into a voltage, run that through a ADC and convert it back into the same binary number. In reality you'd need really accurate DACs and ADCs to do this, especially if you both your converters were 8 bit. Potul only wants a 6 bit DAC though and should be able to sample this at a higher resolution with the PIC, which gives some room for inaccuracies in the conversion, so I can't see why this won't work.

Exactly, this is my plan. Use the 12 bit ADC to read 6 inputs. This way I have some room for inaccuracies.
And only with 2 values and a R2R ladder it is done.
Yesterday I went to the local store, and damn.... I didn't think it would be so hard to find resistors of a high value (between 500k and 1M), one with double value of the other..... So, I had to order them online, I will recieve them in a couple of weeks...In the meantime I'll play with what I have and put some resistors in parallel / series to get the values.

Potul