0
\$\begingroup\$

I was reading through the document tips and tricks using 8 bit controllers by microchip and found this diagram.I have seen this in application in some electronic circuits over internet but never found a satisfactory explanation on how the four switches were differentiated from one another.

The three switches were connected to a single I/O pin of micro controller.

Multiple switch sense through a single input The document says:

A timer is used with a comparator or changing digital input to measure the capacitor charge time. The charge time is used to determine which button is pressed.

Software sequence:
1. Configure GP2 to output a low voltage to
discharge capacitor through I/O resistor.
2. Configure GP2 as one comparator input and
CVref as the other.
3. Use a timer to measure when the comparator
trips. If the time measured is greater than the
maximum allowed time, then repeat;
otherwise determine which button is pressed.
When a key is pressed, the voltage divider
network changes the RC ramp rate. 

can anybody help me to understand this method in a lucid manner.I'm not sure about how to do away with this and differentiate the switches.I'm sure this will be of help to some one working to limit the use of GPIO pins.

If any other alternative ways are available all options and suggestions are whole heatedly welcomed.

Thank you With Regards,

Rookie

asked Oct 8, 2015 at 12:02
\$\endgroup\$
4
  • \$\begingroup\$ Er... I count 4 switches. You are aware that pressing more than one switch simultaneously is an illegal combination that cannot be rationalized. \$\endgroup\$ Commented Oct 8, 2015 at 13:21
  • \$\begingroup\$ @Andyaka Thank you andy for pointing the glitch and i have corrected it in my post.So this is a bad design Andy?.Thanks for enlightening me :).I did not think about the extremes here. \$\endgroup\$ Commented Oct 8, 2015 at 14:38
  • 1
    \$\begingroup\$ If you want to encode a few switches where each can be detected in the presence of multiple presses of other switches use an R-2R method and an ADC input. Don't go more than 4 switches though unless you have particularly clean power supplies. \$\endgroup\$ Commented Oct 8, 2015 at 14:41
  • \$\begingroup\$ @Andyaka Thank you very much Andy.I'll definitely change the design and try that aspect using ADC input.Is that a common design that you mentioned about.It will be great to have some example reference design to have and work up on it. \$\endgroup\$ Commented Oct 8, 2015 at 14:46

2 Answers 2

1
\$\begingroup\$

The principle in this technique is not so exact and reliable.

In this technique the mcu estimate how large is the discharging time. A timer is clocked, capacitor began to discharge, comparator is in the match voltage interrupt. That means when the voltage of input pin is equal or bigger than a specific voltage(that is defined in program, e.g. internal 2.56V) an interrupt will arise. Now in interrupt routine you can measure timer/counter value.

It's time is proportional to RC value that for equal C it means proportional to R. we can estimate the value of resistance. then you can guess which key is down.

A better and more reliable way is to use an ADC pin to attach multiple Buttons. A good explanation is formed here : http://www.edn.com/design/analog/4439796/Read-multiple-switches-using-ADC

Basic Rule of this technique is described in below picture :

enter image description here

Different switches, will produce different voltage on pins.

Main Advantage of this technique is that your buttons can pushed together simultaneously so the overall voltage is the equivalent voltage of overall resistance. You should select good resistor values to have different voltages for different switches pushed.

And at last another easy way to connect multiple switches is to use a decoder IC like 74148. for example connecting 16 button to 4 pins.

answered Oct 8, 2015 at 15:21
\$\endgroup\$
0
0
\$\begingroup\$

Depending on which switch is pushed, the total resistance between the capacitor and VCC changes. A higher resistance means the capacitor will charge more slowly.

answered Oct 8, 2015 at 12:58
\$\endgroup\$
1
  • \$\begingroup\$ Yes that's the theory behind it.But i'm looking at how the controller senses the difference using comparator and timers. \$\endgroup\$ Commented Oct 8, 2015 at 13:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.