Decoding rotary switches


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104

    Default Decoding rotary switches

    This is similar to decoding a matrix keypad but has the problem that it implicitly can have several "keys" pressed at the same time. Basically I've got some rotary switches which have a hex output - 4 bits. I'll have 3 switches and want to read them sequentially. Is there a smart way of reading them with only 7 pins (4c x 3r) ? Are there any dedicated chips out there that would do the same job ? I could of course dedicate a pic to be my decoder but would prefer not to go that route.

    Andrew

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Andrew,
    I think what you want is BCD, (Binary Code Decimal) lots of examples in here.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    The issue isn't how to use or read BCD, and actually this is hex 'cos these are 16 positions switches. The issue is how to multiplex several rotary switches - each of which has 4 bit lines. It can look a bit like a matrix keypad except that it will have multiple "keypresses". you can get round that by using loads of diodes to prevent crosstalk but someone might have come up with a smart solution.

    Andrew

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You can probably use 1 ADC line for each rotary switch (or mix all of them, then feed it to a single ADC input). Basically you convert BCD to voltage with R2R resistor ladder, then you feed this output to your PIC.

    Hardware technique
    http://ww1.microchip.com/downloads/e...tes/00234a.pdf

    8-pin PIC - Tips 'n Tricks
    http://ww1.microchip.com/downloads/e...doc/40040b.pdf
    Last edited by mister_e; - 28th March 2009 at 18:10.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    The rotary switch should have a common plus four outs (bits). If this is the case then connect all the bits of the three rotary in parallel, using diodes, (total 12) and feed four pic pins inputs (better Rb0; Rb1; Rb2 and Rb3). Activate the internal pullup and connect Rb4; Rb5 and Rb6 (outputs) to the commons of the rotary switches .

    Set high Rb4; Rb5; and Rb6. Scan the rotary setting to low Rb4 and read the first rotary switch, set high Rb4 and Low Rb5 and read the second rotary etc.

    Your true reading will be 15-x; where x is the pic reading. If you want a direct reading you have to pulldown the input pins, reverse the diodes and reverse the scanning outputs level.

    Al.
    Last edited by aratti; - 28th March 2009 at 19:02.
    All progress began with an idea

  6. #6
    timmers's Avatar
    timmers Guest


    Did you find this post helpful? Yes | No

    Default

    .... or use a parallel in serial out shift register. By cascading several registers you can have as many inputs/outputs as you like.

    Tim.

  7. #7
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Steve:

    Figure 3 illustrates a resistor network, which changes a
    4x4 keypad into a switchable resistor matrix. The
    resulting resistance is read by an ADC or a capacitor
    charge timer, which determines the key that is pressed.
    This is practical only when one key is pressed at a time.

    ... so that doesn't really work in this case, but those are good links from Microchip, thanks

    Al: I think the usual solution is to use diodes like you say.

    Tim: I'll have to think about that

    Thanks for the inputs

    Andrew

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    So I haven't explain it correctly then... and i wasn't refer to a 4x4 matrix directly but multiple switch with a single I/O and a single (or multiple) ADC channel. Food for thoughts
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Actually this is really one of those situations where I'm trying to force a solution to a problem - I picked up a bag of these switches for a couple of dollars and now I'm looking for a use. The application is just to provide a knob to control the duty cycle of three different PWM module. The easiest solution is just using a pot and an ADC channel - three pins, some case commands and it's done.

    Sometimes one's head gets lost in a dark place !

    Andrew
    Last edited by AndrewC; - 29th March 2009 at 10:33.

Similar Threads

  1. scanning BCD switches
    By dsicon in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th June 2008, 17:57
  2. Rotary encoders
    By mister_e in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st February 2007, 16:57
  3. two BCD switches
    By Mugel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st November 2006, 22:53
  4. switches & LEDs ... my first attempt
    By yankee in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 28th January 2006, 12:51
  5. Two switches per pin!!!
    By picnaut in forum General
    Replies: 4
    Last Post: - 18th June 2004, 19:02

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts