please dont rip this site

Hardware Input/Output Interfacing to Rotary Switches

Morgan Olsson (morgans.rt at TELIA.COM) says

One pin only (!) low component count solution!! - And fast, and cheap, and failure detecting, possible to use only two wires (incl power and ground) to a panel daughterboard, and... ...an I think it will work, too... ;)

Components: 1 IC, 1 diode (might be eliminated), 1 cap, 1-4 resistors (depending on how good you want it) For phantom feeding (true 2-wire incl power and GND): 1 tantalum cap, 1 1N4148.

The solution is based on a HC4017. It is a 5-stage Johnson counter with decoder, giving ten outputs "Qx" where x=0..9, one high at at time counting 0..9, (wrapping), and also a carry output "Cout" high during counts 0..4, giving us a total 11 outputs to play with.

CIRQUIT

ADDITION:

To detect error when the rotor has no contact with any position: If possible, enable pullup on the PIC pin, else you need to connect a separate pullup resistor (10k?), preferrable directly from the rotor to Vdd. This will always pull the PIC input high when set as input.

PROGRAM ROUTINE:

Initialize:
Keep the pin a output high during execution of your other routines. This will reset the 4017. Calculate the C and R time on 4017 reset pin accordingly. Also keep in mind that during execution
Prepare:
Set the pin low, and wait for the C to discharge throught the diode, and its resistor to bring the 4017 safely out of reset, with margin. (a few µs)
Read:
(Read the switch and advance the 4017)
  1. Tristate the pin. The output will remain low or rise depending on to which position the rotary switch is. No worry about clocking the 4017; we have set it to advance in *falling* edge. :)
  2. Write high to PIC output latch for later use
  3. Wait a few µs for input to stabilize ("goto $+1" make a one instr 2 cycle delay). Maybe use longer time, if using pullup to detect open connection error.
  4. Read the pin.
  5. Set the pin as output, (we did set the latch high earlier)
  6. then set it low. This will clock the 4017 (falling edge). This should be done ASAP, to avoid unneccessarily rising the reset cap voltage by keeping the pin low as much as possible, therefor processing the input after this:
  7. Store the read value for later use with table lookup (see below) (i.e shift into 2 registers)

Execute the read 10 times. The last time execute only paragraph 1..5, leaving the output high, eventually resetting the 4017 until next time.

Decode: Now just look up in the table below to decode :)
TRUTH TABLE: 
============ 
Position Pin Stored readings 
1 Q0 HLLLLLLLLL 
2 Q1 LHLLLLLLLL 
3 Q2 LLHLLLLLLL 
4 Q3 LLLHLLLLLL 
5 Q4 LLLLHLLLLL 
6 Q5 LLLLLHLLLL 
7 Q6 LLLLLLHLLL 
8 Q7 LLLLLLLHLL 
9 Q8 LLLLLLLLHL 
10 Q9 LLLLLLLLLH 
11 Cout HHHHHLLLLL 
12 Vss LLLLLLLLLL 
Open None HHHHHHHHHH (error detection, if pullup added as described above) 

The open condition may also occour during movement. Any other input data indicate movement, noise, or error.

NOTES:

DISCLAIMER:

  1. I´m tired; might be thingking or writing erroneousky...
  2. Check component values, especailly if using PIC internal pullup
  3. Check reset timing R and C.
  4. If long wires, there might be problem with ringing affecting 4017 clock, then decouple it using a R and small C in series to Vss.

Untested, but I see no problems.
Enjoy !
PS Please tell me when/how it works for anyone who tries it out.
-I wanna know! DS

James Newton says:

Try 12 same value resistors, and a cap. Two pins, one to feed the resistor array, and one to read the cap voltage (just a CMOS input, not A/D) Take both pins to output, low for a short time. Take the cap pin to input, no pullup, start counting time Take the resistor pin to output high. When the cap pin reads high, stop counting. The time value will tell you how many resistors are in series.
P1----R1-+-R2-+-R3-+.......R12-+ 
          The switch connects one of the + symbols to P2
P2-------------------------+ 
                          Cap 
                          _|_
                         / / /

If you have the time/inclination add another R in between P2 and the cap, and use the discharge time to facator out the cap value/tolerance. Discharge time = RC, and charge time = NRC, so NRC/RC = N, which is the number of resistors switched into circuit, and therefore the switch position.

If you want to do it digital, a pair of HC164 shift registers will let you shift a bit till you see it on the input, with the switch selecting which SR output is looked at. Literally N clocks = switch position.


file: /Techref/io/rotarysw.htm, 7KB, , updated: 2000/6/6 12:18, local time: 2024/12/24 08:59,
TOP NEW HELP FIND: 
3.144.224.30:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/Techref/io/rotarysw.htm"> Hardware Input/Output Interfacing to Rotary Switches</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .