Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Reading a dip switch using one pin ?

Status
Not open for further replies.

henninggs

Member level 2
Joined
Nov 10, 2011
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Denmark
Activity points
1,688
Hi.

I am trying to design a simple rs485 slave. The slave will get its address from a 5 position Dip switch. It will only need to read the switch once: When it is powered on. (Storing the address in a register for later use)

I could dedicate 5 pins on the microcontroller to this purpose, but those 5 pins would be nice to have for other things once the PIC is done reading the address.

There is 2 solutions as I see it:
1. Use 5 pins for the read, then disconnect the dip switch from the pins. (How is that done ?)
2. Connect the switch to some resistors and dedicate a single analog-to-digital pin for the read. Convert the voltage drop to an address. Something like this:
analog_read_dipswitch.jpg

What would be the best solution to my "problem" and how could it be done ?
Thanks for any replies.
 

Both solutions can work. For the 5 pin "digital" variant, you need a means to isolate the switches in normal operation, at least serious resistors, diodes or a multiplexer ic. The feasibility depends much on the regular function of the respective pins. It's probably more easy for pins that are used as outputs later.

The "analog" solution needs a sixth pull-down resistor, forming a voltage divider. The threshold voltages for the 5 bit decoder need to be calculated and e.g. placed in a ROM table.
 

Hi,

You need to use a Shift Register like the 74ls165, though it recieves the data on one line you do need one or two more to control the chip.

You can also connect two or more 165s together to read in several bytes of data at once.
 

Hi, If the PIC has an ADC , choose appropriate resistor values and use one input to read the dip switch.
 

Thanks.

The "analog" solution needs a sixth pull-down resistor, forming a voltage divider.
Why ? Could you put a few more words on this concept ?

Hi, If the PIC has an ADC , choose appropriate resistor values and use one input to read the dip switch.
Any idea of what appropriate resistor values would be ? (Im running 5volts on the slave)

Regards
 

Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top