geekEE
Electrical
- Feb 14, 2005
- 412
I'm trying to read a few 4-bit rotary DIP switches in a microcontroller in the most economical way possible. I'd like to minimize the number of GPIO pins used so that I don't have to buy a larger chip than absolutely necessary. I thought of two different ways and I wanted to see if anyone had any other tips or tricks to share.
1. I could use shift registers like the 74HC165 to read the switches and shift them in. This could be extended by cascading shift registers.
2. I could use resistors to encode the switches as analog levels and read them in using the 10-bit A/D in the microcontroller. I could extend this by using an analog mux to read in more switches. Does anyone know an arrangement of resistors that would maximize the resolution? The usual DAC R-2R tree doesn't work unless the switches are SPDT.
Anyone have any other tricks or comments?
1. I could use shift registers like the 74HC165 to read the switches and shift them in. This could be extended by cascading shift registers.
2. I could use resistors to encode the switches as analog levels and read them in using the 10-bit A/D in the microcontroller. I could extend this by using an analog mux to read in more switches. Does anyone know an arrangement of resistors that would maximize the resolution? The usual DAC R-2R tree doesn't work unless the switches are SPDT.
Anyone have any other tricks or comments?