Hmm.. yes and thanks for the correction on self pulsing. But I think what you mean by pinB is actually pinA. We can further reduce the pin usage to 1 only. By adding R, C and D, diode. R2 from pinA to Reset pin of the ripple counter. Parallel it with 1N4148 diode, cathode to pinA. Then C between GND and the reset pin. Choose the correct time constant so that it takes longer time to reset the ripple counter. When done with reading the SW position leave pinA high to reset the counter and do other routines. The next SW reading cycle, diode will quickly discharge C. Use the routine as suggested by James below. I'd forget about the RC thing method. It take bigger board design space and more program memory. The circuit is something like this... ripple count input o----------------------------------------o PIC pinA | | | k| | | D R2 R1 a| | | | | | o-------o-------- o SW CT Reset | | C | | GND I have not tested it but it should work. sam ----- Original Message ----- From: James Newton To: Sent: Thursday, June 24, 1999 2:59 AM Subject: Re: Best way to interface a 12 pos rotary switch Ripple counter vs binary with decoder is an excellent idea! I'm a little concirned about the combining of count and readback... I think circuit should be direct from pinA to count and then on to center tap via 10k resister so that pic can override the center tap return signal. Also.. you must be very carefull to avoid the return signal pulsing itself away when you get to the correct pin. Ripple counter must count on rising edge (standard) and the sequence is: 1. write 0 to pinB 2. pinB is output 3. write 1 to pinB 4. pinB is input (don't write 0 to pinB THEN make pinB input) 5. read pinB I was also musing about the RC thing, seems like you ought to be able to setup resistor bridge between each switch positions to gnd and also to next position and then a cap from center to pic pin and adjust the RC constant until the readback requires NO delay. Just pulse the ouput pin and then loop: read pin increment counter branch to loop if high and get a count of 12 if in 12th position, 1 if in first, etc... This requires less expensive external circuit and no additional processor time. James Newton, webmaster http://get.to/techref jamesnewton@geocities.com 1-619-652-0593 phone > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Sam S Man > Sent: Wednesday, June 23, 1999 11:32 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: Best way to interface a 12 pos rotary switch > > > Well, good idea, but try this! It uses only 2 pin and 1# 16-pin IC instead > of 24 (4 to 16 decoder) > > Use 12 stage ripple counter. Each of the 12 output connects to the 12 > different known position. i.e pos1, pos2.... pos12. The centre > tap connects > to PIC pinA via a R1 10K resistor. The same PIC pinA also connects via R2 > 10K res to the pulse input pin of the ripple counter. PIC pinB simply used > to reset the external ripple counter. > > To read the switch position follow the steps below; > 1- reset the ripple counter by using PIC pinB (as output) > 2- pulse PIC pinA (as output) + delay + read back PIC pinA (as input) > 3- repeat 2 until pinA found high. Now the switch position should equal be > to your pulse count. You can do it by decfsz with count preloaded > to 12 when > resetting the internal counter and the ripple counter as in step 1. > > Thanks to James. It really makes me think quick. > > cheers > sam > > > ----- Original Message ----- > From: James Newton > To: > Sent: Thursday, June 24, 1999 1:10 AM > Subject: Re: Best way to interface a 12 pos rotary switch > > > > External clock pulse -> PIC interrupt pin (call it "count") and to > External > > 4-bit counter chip with 4 to 16 decoder -> each decoded output to one of > the > > 12 pins, and one to a pin (call it "reset") on the PIC (3 left over). > Center > > tap of the switch to another pin (call it "hold") configured as > input. In > > the PIC the interrupt routine increases a count when the external clock > > counts, resets the count when the "reset" line is high, and > transfers the > > count to the result when the "hold" line is high. > > > > This is 3 pins + one or two external chips. > > > > Alternatively, the count could originate in the PIC and reset after you > get > > a "hold" line high, but the external chip and switch has to be able to > > handle high speed signal or the routine will take a long time. > This would > be > > 3 pins and 1 external chip. > > > > James Newton, webmaster http://get.to/techref > > jamesnewton@geocities.com > > 1-619-652-0593 phone > > > > > > > > > -----Original Message----- > > > From: pic microcontroller discussion list > > > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Ross Bencina > > > Sent: Wednesday, June 23, 1999 7:39 AM > > > To: PICLIST@MITVMA.MIT.EDU > > > Subject: Best way to interface a 12 pos rotary switch > > > > > > > > > Hi PICsters, > > > > > > I have a 12 position single pole rotary switch that I'd like to > > > interface to > > > a 16F84 and I don't have 12 spare IO pins ;) (Ideally I'd like to > > > use 4 pins > > > or less). I've seen examples of using a resistor lader and an RC timer > > > circuit (uses too much cpu time for my purposes), presumably > > > there's also a > > > logic chip (demux?) that will do the job, I'm just wondering if > > > I've missed > > > any other obvious, minimal, and/or clever solutions to this problem. > > > > > > Thanks in advance. > > > > > > Ross B. > > > ................................. > > > http://www.audiomulch.com/~rossb/ > > > > > >