PDA

View Full Version : Decoding rotary switches



AndrewC
- 28th March 2009, 14:35
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

Archangel
- 28th March 2009, 17:11
Hi Andrew,
I think what you want is BCD, (Binary Code Decimal) lots of examples in here.

AndrewC
- 28th March 2009, 17:35
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

mister_e
- 28th March 2009, 17:57
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/en/AppNotes/00234a.pdf

8-pin PIC - Tips 'n Tricks
http://ww1.microchip.com/downloads/en/devicedoc/40040b.pdf

aratti
- 28th March 2009, 18:48
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.

timmers
- 28th March 2009, 22:36
.... or use a parallel in serial out shift register. By cascading several registers you can have as many inputs/outputs as you like.

Tim.

AndrewC
- 28th March 2009, 22:58
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

mister_e
- 29th March 2009, 00:51
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 ;)

AndrewC
- 29th March 2009, 10:26
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