charlieplex buttons caveat

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

charlieplex buttons caveat

Post by L. Daniel Rosa »

I finally got a six button array to read correctly (problems with my code), and came to realize something that wasn't immediately apparent on paper.

When two or more buttons are pressed that put the anode of one diode to the cathode of another, then a phantom third is read as well. The way around this is to be sure that the forward bias voltage of the diodes is more than 1/4 of Vdd. It still needs to be less than 1/2 Vdd, so for a supply of 4 volts or higher a plain jane LED will work perfectly.

For lower voltage supplies (2*AA Ni-MH or alkaline, and single cell Li-ion) it gets tricky. I don't know if I prefer to run two Si diodes in series and hope for the right drop or go for an IRED, which may be hard to get in small quantities for 0805 packages.

What blindingly obvious option did I overlook this time?

added:

Image



The com pin is connected to Vdd if weak pull-ups are not used or available, elsewise left open. I used 10k for the resistors.

added: tried to repair link

added: again
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi there,

Have a schematic we can take a look at? This might help a lot
with trying to help or suggest other options.
LEDs vs Bulbs, LEDs are winning.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

Have a schematic we can take a look at?
Oops! I should have included that in my original post, sorry. I'm at the library right now. I'll modify my original post and null this one when I get that appended- or maybe attach it to this one.

added: I have it now, but no idea how to upload it to the forum- sorry.
User avatar
jollyrgr
Posts: 1289
Joined: Thu Jan 03, 2002 1:01 am
Location: Northern Illinois
Contact:

Post by jollyrgr »

To post images in the forums is quite easy. If you don't have a web server that is somewhat permanent, find a web host that is. One such host is the one I use located at:

http://www.imageshack.us

This is a free service provider. Once you create your account, you upload images. The site will list several ways of posting an image; such as HTML for a web page, for forums, for direct links, etc.

I prefer to use the editor built into the Nuts and Volts system for posting my images. You can use the buttons for Img to start and stop the coding for the image. You can type it directly as well. It would be [ img ] to start the URL and [ /img ] to end the url. Note that I put spaces inside the square brackets to prevent the embedding of the code. You would not type the spaces when composing your posting.

You would put the URL to the image in between the start and stop commands. A URL might look similar to:
http : //img927.imageshack.us/927/schematic.jpg (Again, spaces being used to prevent automatic encoding of a URL. This is a BOGUS URL I made up.)

I will replace the first and last square brakets with { and } so you can see the way the text would look as you are composing the message. Again you would NOT use the { } but would use the square brackets located on the same key.

{img]http://img927.imageshack.us/927/schematic.jpg[/img}

When you post the message, the above would be encoded such that you don't see the text string but you would see the image at the URL, namely schematic.jpg.



I hope this helps.
No trees were harmed in the creation of this message. But billions of electrons, photons, and electromagnetic waves were terribly inconvenienced!
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

Thank you jollyrgr. I patched the image into the first post.
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi there L. Daniel Rosa,

It looks like your picture should have been a bit bigger, as it is coming
up very very small in my browser and very hard to see what parts
are what and how they are connected. Perhaps a larger pic?

From what i can tell, you have the switches wired in series with diodes
so that you can connect two across two port pins. Not a bad idea,
until as you say someone presses two switches at the same time.

Since there are only six switches, another idea might be to use one
resistor for each switch, where the resistor sizes are chosen to
provide an analog signal into the 'sense' port and this 'sense' port
is read with the AD converter rather than a digital input. If you use
a device with a 10 bit ADC it should work ok since 6 switches would
only take 6 bits.
For example, if you run 1k to +5 for the first switch, then the second
switch gets 2k, then the third switch 4k, then 8k, then 16k, then 32k.
The analog signal at the sense input would then represent what
switches were pressed. The advantage here is that you can sense
any one switch closure as well as multiple switch closures.
I havent looked at how practical this would be for 6 switches however.
Another way might be to form an R/2R ladder and connect the switches
that way, but you might need SPDT switches for that so that might not
be a very good option.
I guess we'd have to work out the details first too.

LATER:
I looked at the complexities of using a binary current to develop a
voltage to be sensed by the ADC (one resistor per switch) and it
looks a little more complicated without using a controllable current
source. Might need to program in a lookup table to convert the
switch pattern to the binary code which represents which switches
are closed. The advantage, if we could get this to work in the
practical circuit, is that it only requires one single input port for
6 switches, and that multiple switch closures can be detected.
LEDs vs Bulbs, LEDs are winning.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

Thanks for the feedback, MrAl. I actually tried to minimize the file size. I didn't think anyone had a screen smaller than mine (11 inches), sorry.

It's kinda funny that you mention using an analog line. My first idea was to use one except that I saw how much of a headache it would to figure the resistors. I also saw that to monitor for the "abort" button I could leave the I/O pins configured for one of the three scanning slices and break on a single btfsc. It also makes the code portable to chips without ADC and can be upscaled to almost any size (why I'd want to is another matter- beyond a certain point it'd be better to use a keyboard). Not to mention the ADC sample time (not that it would be an issue with human I/O, but if one of the buttons were replaced with a phototransistor... well that's another dream).

IREDs should work well enough except that... what I make to run off of two AA cells or a Li-ion cell is gonna be small so I'll be using SMT- and good luck finding IREDs in 0805 packages for lots less than 3000.

I've painted myself into a corner here. I'll probably have to give up on finding the miracle component that will take care of the 2.2-4.1 volt range (1.05-1.10 is a bit tight). If I limit myself to only one battery type, 2.2-3.2 volt (2*AA) then 0.8-1.1 is a bigger target. Then the Li-ion goes 2.9-4.1 for 1.05-1.45 for that one.

The first looks like a standard diode in series with a schottky will do it, and the second one looks like two ordinary diodes. On the downside, that's more real estate and parts. I'm still hoping...
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi again,


Well, after my last post i realized that the simple solution to
using 6 inputs and sense using the ADC would be to just divide
them up into two groups, switches 1,2,3, and switches 4,5,6.
In this way it would be possibly to make a simple look up table
that would convert the analog voltage readings into what
switches were closed.
BTW, the ADC on PIC's can be about 50us, which isnt long
at all compared to the 30ms or so response of a human finger.
Also BTW, the resistor values are quite simple:
2k, 4k, and 8k, with a 40 ohm 'low' resistor. Not too bad huh?

Using two groups of three means there are only 8 different combinations
of switch closures per group, which should be easy to detect.
This only required two input pins also.

Of course it's up to you to decide what way to go. The digital charlieplex
technique is a little simpler.
LEDs vs Bulbs, LEDs are winning.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

Ya' know, the R2R will work for this too. The power budget will be higher because of the ADC alone, and the resistors will have to be lower value too. But spare myself the lookup table, and about the same space either way...

Now the time of 32uS isn't an issue from the human standpoint, but a single instruction conditional to abort process versus calling the ADC and waiting to digest it could be a resource issue.
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi again LDR,


How do you intend to get R2R to work with SPST push button
switches? Or do you intend to use SPDT?

Well, what i was thinking was that we would call the ADC routine
once every 30ms, which would mean we would have some 30,000
instruction cycles in between every call. If we need two calls for
two groups of three switches, that would be 15ms between calls
which is still roughly 15,000 instruction cycles between each call.
I didnt think this would be too much of a problem because that's
still a lot of instructions between calls, and this is only at 4MHz
oscillator frequency. At 8MHz which is also common, double
all the in between instructions so we are back up to 30,000
between each ADC call.
LEDs vs Bulbs, LEDs are winning.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

...an excellent and thoughtful response that the forum timed out on and lost...
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi LD Rosa,

Oh, sorry to hear that. Well, if you feel up to it perhaps you can
summarize and post again. I'd like to hear what you had to say.

What i do sometimes when i might type a long post is i type it
into a text editor like Notepad and i save it every now and then
just in case. When i am done, i copy and paste the whole text
into the box here in the forum. As you probably guessed, i have
lost many a post too in the past so i started to think of ways to
avoid this in the future.
LEDs vs Bulbs, LEDs are winning.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

It occured to me sometime yesterday after I mentioned using an R2R ladder that SPSTNO switches can't quite do the job, so I'm stuck with binary weighting. I'm not sure I follow the exact values you gave for the switches, I think I should aim for something that will put all the activity in the middle of the range so it isn't too crowded. Better still if the separation is good enough that I can grab bits 4-6 or 5-7 directly (out of an 8 bit adc) and save the space that a lookup table would occupy.

I plan to poll the buttons on a timed interrupt anyway. My first idea was to scan each pair on the first, second and third millisecond interrupt respectively. On the fourth the array would be decoded and debounced. Four would be processed as a vector (north, south, east, west) and would have to be stable for a sequence of reads before it is acknowledged. The other two (x, y) would be treated independantly, and would also be set up to detected in a single instruction cycle (btfsc) when a routine is entered for which the timed interrupt is turned off (abort). This becomes critical when I am trying to run a tight loop (27 cycles) continuously until the user wants it to stop, reading the ADC and using a lookup table would be unforgivable- but that's not every application.

You're not kidding about the simplicity. Another bonus is that I can mix in some LEDs- six of them with just one more I/O. Then again, most of my projects will probably have an LCD.

This takes me down another lane... When I first discovered the charpliplex method I looked at Dallas/Maxim's product line, but they didn't seem to get the possible implications of their own creation. They have multisegment drivers that take serial input, but insist on decoding for a certain type of display instead of being general purpose. I'd be happier with something a bit more independant. I think nine and seventeen line charlieplex drivers would be particularly useful.
L. Daniel Rosa
Posts: 400
Joined: Tue Dec 25, 2001 1:01 am
Location: Bellingham, WA
Contact:

Post by L. Daniel Rosa »

Bigglez PMed me with:
What are you trying to do?

Do you have a human-readable schematic?
So I took a look at the image as displayed and found that it will not reconstitute. I don't know what the deal is with imageshack, but what I uploaded is definitely human-readable (over four inches on a twelve inch screen). I apologize for this. I do not know if uploading another image will help, as they will probably destroy that as well and only show a thumbnail.

added:

At imageshack I can view it properly, but here it is reduced.

added: link repaired
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi again,

The following tables show some results using different
resistors for the upper and lower resistors. The lowest
value resistor is the lower one.

Note that as the lower resistor value gets lower the linearity
gets better although the actual voltage goes lower.

Using three current sources would result in very good
almost perfect linearity (0 percent nonlinearity) , but would
require more circuitry.

Code: Select all



Resistors:
Three upper resistors and one lower resistor.
Table:
Binary count, actual voltage, ideal voltage.


Resistors: 1k,2k,4k, 40.404 ohms
0     0.00mv     0.00mv
1   100.00mv   100.00mv
2   198.02mv   200.00mv
3   294.12mv   300.00mv
4   388.35mv   400.00mv
5   480.77mv   500.00mv
6   571.43mv   600.00mv
7   660.38mv   700.00mv
(worst case 6 percent nonlinearity)

Resistors:  2k,4k,8k, 80.808 ohms
0     0.00mv     0.00mv
1   100.00mv   100.00mv
2   198.02mv   200.00mv
3   294.12mv   300.00mv
4   388.35mv   400.00mv
5   480.77mv   500.00mv
6   571.43mv   600.00mv
7   660.38mv   700.00mv
(worst case 6 percent nonlinearity)

Resistors:  2k,4k,8k, 40.201 ohms
0     0.00mv     0.00mv
1    50.00mv    50.00mv
2    99.50mv   100.00mv
3   148.51mv   150.00mv
4   197.04mv   200.00mv
5   245.10mv   250.00mv
6   292.68mv   300.00mv
7   339.81mv   350.00mv
(worst case 3 percent nonlinearity) (best yet)
The formula for the calculation of the voltage is not difficult either...

Vo=Vin*RL/(RP+RL)
where
Vin is the input voltage (10v used for above tables)
RL is the lower resistor, typically around 40 ohms or so
RP is the parallel combo of all the upper resistors switched
in at the time. If we label the upper resistors R1,R2, and R3,
this comes out to:
RP=1/(1/R1+1/R2) with only R1 and R2 switched in for example,
or
RP=1/(1/R1+1/R2+1/R3) with all three switched in for example,
or
RP=R1 with only R1 switched in (for a single switch closure RP equals
that resistor).

Note also that i used pretty exact resistor values like 40.201 for the
above calculations so the nonlinearity would be more obvious with
the ideal output voltage increment being exactly 100mv or 50mv,
but a value of 40 ohms would work just as well. Simply recalculate
the 7 different possibilities.
LEDs vs Bulbs, LEDs are winning.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 33 guests