reading 4 switches with one 10-bit ADC ?

R

Rodo

Guest
Hi all,

I was trying to reduce the pins used by a keypad (4 keys) and I thought I
should be able to read the value with one channel of a PIC ADC. I'm getting
the feeling is not possible. With 4 sw I figure I need to detect 16
combinations (0000=vcc=5v=no key pressed, 1111=all sw on=least resistance).
I was doing some calculations with on resistor in series (1k) after Vcc and
then, the 4 sw in parallel (each sw has a series resistor with it).

I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the voltage
when they are in parallel with one or two more sw and the output voltage
does not match my table.Since this stuff is all linear, I came to the
conclusion that It can not be done. Actually the massive headache I have at
the moment is impairing my thought process :).

Any comments, suggestions, or application notes :) available are welcome.

Thanks
 
On Fri, 09 Apr 2004 05:02:51 GMT, "Rodo" <dsp1024@yahoo.com> wrote:

Hi all,

I was trying to reduce the pins used by a keypad (4 keys) and I thought I
should be able to read the value with one channel of a PIC ADC. I'm getting
the feeling is not possible. With 4 sw I figure I need to detect 16
combinations (0000=vcc=5v=no key pressed, 1111=all sw on=least resistance).
I was doing some calculations with on resistor in series (1k) after Vcc and
then, the 4 sw in parallel (each sw has a series resistor with it).

I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the voltage
when they are in parallel with one or two more sw and the output voltage
does not match my table.Since this stuff is all linear, I came to the
conclusion that It can not be done. Actually the massive headache I have at
the moment is impairing my thought process :).
Without repeating your deliberations and risking a sore head myself, consdier
the following approach:

Each key enables a current source (eg LM317LZ). Currents are binary weighted eg
1,2,4,8 mA. All currents go to common/ground via a scaling resistor (eg 1k if
your ADC can handle 15V input). Voltage across resistor = 0 to 15V (0000 to
1111).
 
Rodo wrote:
I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the
voltage when they are in parallel with one or two more sw and the
output voltage does not match my table.Since this stuff is all
linear, I came to the conclusion that It can not be done. Actually
the massive headache I have at the moment is impairing my thought
process :).

Any comments, suggestions, or application notes :) available are
welcome.

Thanks

A B C D
--- --- --- ---
VCCo+--o o---+---o o---+---o o---+---o o---+
| | | | |
| ___ | ___ | ___ | ___ | Uout
+-|___|--+--|___|--+--|___|--+--|___|--+---o
8k2 3k9 2k 1k |
.-.
| |
Uout= 5V*1k/(1k+Rv) 1k| |
'-'
|
===
GND
created by Andy´s ASCII-Circuit v1.24.140803 Beta www.tech-chat.de
view\font\fixed
smallest step is from 1/16 to 1/15 so an 8-bit accuracy is sufficient. There
are other possibilities as well, but require more resistors. You can also
change GND and Vcc, if your ADC has a smaller input range.

--
ciao Ban
Bordighera, Italy
 
"Rodo" <dsp1024@yahoo.com> wrote in message
news:%7qdc.3097$F9.398@nwrddc01.gnilink.net...
Hi all,

I was trying to reduce the pins used by a keypad (4 keys) and I thought I
should be able to read the value with one channel of a PIC ADC. I'm
getting
the feeling is not possible. With 4 sw I figure I need to detect 16
combinations (0000=vcc=5v=no key pressed, 1111=all sw on=least
resistance).
I was doing some calculations with on resistor in series (1k) after Vcc
and
then, the 4 sw in parallel (each sw has a series resistor with it).

I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the voltage
when they are in parallel with one or two more sw and the output voltage
does not match my table.Since this stuff is all linear, I came to the
conclusion that It can not be done. Actually the massive headache I have
at
the moment is impairing my thought process :).

Any comments, suggestions, or application notes :) available are welcome.
Do your calculations again. Measure the voltage when one switch is closed,
and perform the conversion with your ADC

You will find you have done a simple error - this should be piece of cake
:)

Cheers

Klaus
 
Ban wrote:

Rodo wrote:

I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the
voltage when they are in parallel with one or two more sw and the
output voltage does not match my table.Since this stuff is all
linear, I came to the conclusion that It can not be done. Actually
the massive headache I have at the moment is impairing my thought
process :).

Any comments, suggestions, or application notes :) available are
welcome.

Thanks



A B C D
--- --- --- ---
VCCo+--o o---+---o o---+---o o---+---o o---+
| | | | |
| ___ | ___ | ___ | ___ | Uout
+-|___|--+--|___|--+--|___|--+--|___|--+---o
8k2 3k9 2k 1k |
.-.
| |
Uout= 5V*1k/(1k+Rv) 1k| |
'-'
|
===
GND
created by Andy´s ASCII-Circuit v1.24.140803 Beta www.tech-chat.de
view\font\fixed
smallest step is from 1/16 to 1/15 so an 8-bit accuracy is sufficient. There
are other possibilities as well, but require more resistors. You can also
change GND and Vcc, if your ADC has a smaller input range.
You could also bias this with a transistor instead of a 1K resistor to
ground:

to Uout node
|
___ |/
VCC o-+-|___|-+--|
| |\
.-. |
| | .-.
| | | |
'-' | |
| '-'
=== |
GND ===
GND

Pick your base resistors to give you about 2V and your emitter resistor
to give you about 0.2mA, then your Uout node will go in 16 more or less
equally spaced increments.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
 
Serial is the way ! I had the SWs in parallel.

Thanks

"Ban" <bansuri@web.de> wrote in message
news:h4rdc.32350$hc5.1444383@news3.tin.it...
Rodo wrote:
I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the
voltage when they are in parallel with one or two more sw and the
output voltage does not match my table.Since this stuff is all
linear, I came to the conclusion that It can not be done. Actually
the massive headache I have at the moment is impairing my thought
process :).

Any comments, suggestions, or application notes :) available are
welcome.

Thanks


A B C D
--- --- --- ---
VCCo+--o o---+---o o---+---o o---+---o o---+
| | | | |
| ___ | ___ | ___ | ___ | Uout
+-|___|--+--|___|--+--|___|--+--|___|--+---o
8k2 3k9 2k 1k |
.-.
| |
Uout= 5V*1k/(1k+Rv) 1k| |
'-'
|
===
GND
created by Andy´s ASCII-Circuit v1.24.140803 Beta www.tech-chat.de
view\font\fixed
smallest step is from 1/16 to 1/15 so an 8-bit accuracy is sufficient.
There
are other possibilities as well, but require more resistors. You can also
change GND and Vcc, if your ADC has a smaller input range.

--
ciao Ban
Bordighera, Italy
 
On Fri, 09 Apr 2004 05:02:51 GMT, "Rodo" <dsp1024@yahoo.com> wrote:

Hi all,

I was trying to reduce the pins used by a keypad (4 keys) and I thought I
should be able to read the value with one channel of a PIC ADC. I'm getting
the feeling is not possible. With 4 sw I figure I need to detect 16
combinations (0000=vcc=5v=no key pressed, 1111=all sw on=least resistance).
I was doing some calculations with on resistor in series (1k) after Vcc and
then, the 4 sw in parallel (each sw has a series resistor with it).

I assigned voltages in a truth table from all sw open (Vout=5v) to all
closed (1111=5v/16=0.3125). I calculate the value for the individual
resistors when they're closed by themselves. Then, I checked the voltage
when they are in parallel with one or two more sw and the output voltage
does not match my table.Since this stuff is all linear, I came to the
conclusion that It can not be done. Actually the massive headache I have at
the moment is impairing my thought process :).
---

Ein
| __8__
+--O O---[R]---+
| __4__ |
+--O O---[2R]--+
| __2__ |
+--O O---[4R]--+
| __1__ |
+--O O---[8R]--+
| _
+---[R]--+ _| 0100
| | _| 0011
+--|-\ | _| 0010
| >--+--> Eout _| 0001
+--|+/ 0000
| ^^^^
0V 8421

With all the switches open, Eout = 0V.

With Ein = -10V on the switches,Eout = |-V| (R/8R) = 1.25V.

Thereafter, Eout will increase monotonically as the swithes are thrown
in a binary sequence, like this:

8421 Eout
------|------
0000 0.00
0001 1.25
0010 2.50
0011 3.75
0100 5.00
0101 6.25
0110 7.50
0111 8.75
1000 10.00
1001 11.25
1010 12.50
1011 13.75
1100 15.00
1101 16.25
1110 17.50
1111 18.75

So, you can see that by choosing Ein properly (it must stay negative,
though) you can get whatever you want out of the op amp equally
divided into 15 chunks.

--
John Fields
 
On Sat, 10 Apr 2004 07:52:59 -0500, John Fields
<jfields@austininstruments.com> wrote:


Ein
| __8__
+--O O---[R]---+
| __4__ |
+--O O---[2R]--+
| __2__ |
+--O O---[4R]--+
| __1__ |
+--O O---[8R]--+
| _
+---[R]--+ _| 0100
| | _| 0011
+--|-\ | _| 0010
| >--+--> Eout _| 0001
+--|+/ 0000
| ^^^^
0V 8421

With all the switches open, Eout = 0V.

Oops... should read:
and switch "1" made,
With Ein = -10V on the switches ^ Eout = |-V| (R/8R) = 1.25V.
--
John Fields
 
.Ein
. | __8__
. +--O O---[R]---+
. | __4__ |
. +--O O---[2R]--+
. | __2__ |
. +--O O---[4R]--+
. | __1__ |
. +--O O---[8R]--+
. | _
. +---[R]--+ _| 0100
. | | _| 0011
. +--|-\ | _| 0010
. | >--+--> Eout _| 0001
. +--|+/ 0000
. | ^^^^
. 0V 8421

John Fields
Having a plus sign as the first character on a line
freaked out the drawing on the Google Groups archive.
 

Welcome to EDABoard.com

Sponsor

Back
Top