How to read two remote open/closed switches

I need to develop a MCU-based board that must read 10 "lines".

Each "line" is associated to 2 open/closed switches connected to the central board through only 2 wires.

For each "line" the MCU should detect the following states:

- short circuit

- switch A open (switch B doesn't care)

- switch A closed, switch B open

- switch A closed, switch B closed

One simple solution is to measure the resistor of the "line" and change the resistor when switches toggle.

Rb |--/\/\/\/---SWB--| | | MCU ------------SWA------+-----/\/\/\/-----+ Ra | GND ---------------------------------------|

- short circuit: R=0

- SWA open: R=infinite

- SWA closed, SWB open: R=Ra

- SWA closed, SWB closed: R=Ra // Rb

The switches are "remote", they could be connected through 10-50m cabling. It's a home environment, not industrial. Some noise could be present casued by some household appliance.

A simple solution is to use a pull-up on the MCU board and measure the voltage of the "line" through an ADC. However in this case I have the MCU 3.3V supply on the cables and it could be too low and susceptible to some electrical noisce.

There is 12V power rail too on the central board, so I can use a pull-up to 12V. However in this case I have to decrease the voltage in order to measure it through the ADC integrated in the MCU. An op-amp is sufficient, but I have 10 lines, so I need 10 op-amp!

I'd like to keep the circuit simple but robust enough. Any suggestion?

Reply to
pozz
Loading thread data ...

If your MCU I/O is configurable at run time - in other words if you can switch between using a pin as an input or an output while the program is running - there's a fairly simple way of doing this with a little code.

Connect a small capacitor between the I/O pin and ground. Set pin as output, set output Hi. Set pin as input, measure Hi or Lo. Set pin as output, set output Lo. Set pin as input, measure Hi or Lo. If there's an open circuit - Switch A open - the capacitor will hold the pin voltage long enough to measure. If after several Hi/Lo cycles the input is always the same as the output was set, then Switch A is open.

Connect Switch B between Switch A and ground with a pull-up resistor at the junction to supply. If after several cycles as above, the input is always Lo, then Switch A is closed and Switch B is closed, if it's always Hi, then Switch A is closed and Switch B is open.

You'll also need a series resistor to prevent the I/O driving into a short circuit. Timing is fairly important - you need to poll quick enough so that the capacitor holds the charge, but slow enough so the C has time to charge through the pull-up if A closed and B open.

Cheers

--
Syd
Reply to
Syd Rumpo

You really need to detect six states: interconnecting wire open or short an d the four combinations of A /B open/closed. You don't need a whole bunch o f op amps if you have the I/O to address 1 of 10 channels of an analog mux. Then you need to consider your wire. You go a long way toward reducing int erference with shielded twisted pair. The shield helps shunt electric field noise to GND and the twisted pair attenuates voltages induced by magnetic field interference.

Reply to
bloggs.fredbloggs.fred

This would work:

formatting link

Use R1 if you want to sense all four states of the switches; otherwise short it. Use Reol if you want to fully supervise the circuit, similar to what's done in fire alarm systems. The uP analog input might deserve a little more protection.

--
John Larkin         Highland Technology, Inc 

lunatic fringe electronics
 Click to see the full signature
Reply to
John Larkin

Another general scheme would require three wires: +12, GND, and 'Sense', and use an R-2R ladder

to convert the (digital) switch state to analog.

Reply to
whit3rd

One could in theory encode any number of switches at the end of two wires, using only resistors. Three or even four might be practical.

It helps if the ADC reference is ratiometric on the excitation voltage.

Reminds me of multi-level flash memory, which is a kind of scary concept.

--
John Larkin         Highland Technology, Inc 
picosecond timing   precision measurement  
 Click to see the full signature
Reply to
John Larkin

Just drive the wire pair with an AC current and have the switches connect diodes across the wire pair... then observe the voltage... no rectification, half positive or negative, or full. ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
 Click to see the full signature
Reply to
Jim Thompson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.