Connect with us

reading 4 switches with one 10-bit ADC ?

Discussion in 'Electronic Design' started by Rodo, Apr 9, 2004.

Scroll to continue with content
  1. Rodo

    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
     
  2. budgie

    budgie Guest

    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).
     
  3. Ban

    Ban Guest


    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.
     
  4. 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
     
  5. Tim Wescott

    Tim Wescott Guest

    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.
     
  6. Rodo

    Rodo Guest

    Serial is the way ! I had the SWs in parallel.

    Thanks
     
  7. John Fields

    John Fields Guest

    ---

    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.
     
  8. John Fields

    John Fields Guest


    Oops... should read:
    and switch "1" made,
     
  9. JeffM

    JeffM Guest

    .Ein
    Having a plus sign as the first character on a line
    freaked out the drawing on the Google Groups archive.
     
  10. Fred Bloggs

    Fred Bloggs Guest

    If SWx=1 when "closed" and 0 when "open", and Rx parallels it, then Rv=
    /SWa*Ra+/SWb*Rb+...+/SWd*Rd. Therefore a simple current source driving
    the series string can be used to detect the one-to-one correspondence
    between the switch combination state and the resulting voltage:

    Please view in a fixed-width font such as Courier.

    I-src
    +------+
    +----------------| ---> |---------------
    | +------+ |
    | |
    | |
    | |
    | |
    | A B C D |
    | --- --- --- --- |
    +--o o---+---o o---+---o o---+---o o---+
    | | | | |
    | RA_ | RB_ | RC_ | RD_ | Uout
    +-|___|--+--|___|--+--|___|--+--|___|--+---o
    | 8k2 3k9 2k 1k
    ---
    ///



    _ _ _ _
    Uout= (A x RA + B x Rb + C x Rc + D x Rd)xIsrc


    Just for kicks, things can be changed around substituting I<->V, R<->Y,
    and /SW<->SW in the above equation:

    Please view in a fixed-width font such as
    Courier.


    Iout= (A x YA + B x YB + C x YC + D* YD)xVsrc


    and this corresponds to:




    A Iout
    YA_ --- <----
    +--|___|----o o---+-----------+
    | 8k2 | |
    | B | |
    | YB_ --- | |
    +--|___|----o o---+ +------+
    | 3k9 | | + |
    | C | | V-src|
    | YC_ --- | | - |
    +--|___|-----o o--+ +------+
    | 2k | |
    | D | |
    | YD_ --- | |
    +--|___|-----o o--+ |
    | 1k |
    | |
    +-----------------------------+
    |
     
  11. Fred Bloggs

    Fred Bloggs Guest

    Please view in a fixed-width font such as Courier.


    Iout= (A x YA + B x YB + C x YC + D* YD)xVsrc


    and this corresponds to:




    A Iout
    YA_ --- <----
    +--|___|----o o---+-----------+
    | 8k2 | |
    | B | |
    | YB_ --- | |
    +--|___|----o o---+ +------+
    | 3k9 | | + |
    | C | | V-src|
    | YC_ --- | | - |
    +--|___|-----o o--+ +------+
    | 2k | |
    | D | |
    | YD_ --- | |
    +--|___|-----o o--+ |
    | 1k |
    | |
    +-----------------------------+
    |
    ---
    ///




    And this has implementation:



    Iout
    <----
    R 2x Rb
    Vsrc +---/\/\---+ +----/\/\--+
    ---- | | | |
    A 2 | | | ---
    YA_ --- | |\ | | OA2 gnd
    +--|___|----o o---+------+---|- \ | Rb | |\
    | 8k2 | | >--+--/\/\-+---|+ \
    | B | +---|+ / Vx | >--+->Vout
    | YB_ --- | | |/ +---|- / |
    +--|___|----o o---+ | OA1 | |/ |
    | 3k9 | | | |
    | C | | Rb | 2x Rb |
    | YC_ --- | +-------------/\/\-+----/\/\--+
    +--|___|-----o o--+ |
    | 2k | +------+
    | D | | Vsrc |
    | YD_ --- | | ---- |
    +--|___|-----o o--+ | 2 |
    | 1k +------+
    | |
    +------------------------+
    |
    ---
    ///

    Vsrc
    OA1 maintains ---- across SW combination
    2

    R used to produce voltage proportional to Iout


    Vsrc Vsrc
    Iout= ---- x Y => V = ---- ( 1 + Y x R )
    2 sw x 2 sw

    Vsrc
    => Vout= 2 x ( Vx - ---- ) = Vsrc x Y x R
    2 sw


    Set Vsrc= FS of A/D ( sometimes Vcc)


    and 1/R= Y ,maximum (all sw's closed)
    SW

    then 0 <= Vout <=FS


    OA's are RRO
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-