Go Down

Topic: Help on momentary push switches in series. (Read 1 time) previous topic - next topic

Thot


Why did you start a whole new thread on this keyboard?



To pose appropriate questions in appropriate forum.

Sensor question in sensor, multiplexing in multiplexing, audio in audio etc.
It is the same project which has different aspects to it.
It is is moreappropriate I can ask All the questions in a single thread, but then we will have audio, multiplexing, programming, sensor etc. In a single thread in which most of the questions will not be pertinent.

It's kind of like when a patient comes to see me for an eye problem, a dermatologist for a skin problem and an OBGYN for, well, another problem :) even if it's the same individual.

Also, while we are on the topic (forgive the pun) i found interesting partial answers to my questions in older posts, but they were closed so i could not follow up with questions or comments. Why close old topics? Most of them are relevant with current devices.

There are three kind of people in the world: Those who can count, and those who can't

Thot


Quote
R-2R networks only work with SPDT switches, not SPST push buttons.


Are you sure about that? :)

With a r2r type button, you can read multiple buttons from one pin, and you can detect simultaneous presses as well.



Thank you for pointing me t R/2R networks.
I'm no expert (in fact i learned about it today) but from the wikipedia article it would seem they would work also with momentary pushbuttons.

The problem of the low separation of voltages still remains as the resolution, for 12 pins is:
5/2^12 = 0.00122V
There are three kind of people in the world: Those who can count, and those who can't

dhenry

Yes, the adc keyscan approach isn't very good with many buttons, as it is limited by the adc's capabilities.

In this case, you can break the buttons up into two or even more pins with multiple r2r ladders.

CrossRoads

So you have a 20-IO pin device, you need 13, you need to be able to detect multiple key presses.
How does adding an R2R ladder help here?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

dhenry

I think this is a more generic solution:

Code: [Select]

#define KEY_1 0x01 //key1
#define KEY_2 0x02 //key2
#define KEY_3 0x04 //key3
...

//macro to read 6 keys
#define adcKeyscan6(pin)  ((analogRead(pin) + 2) >> 4)

  key_pressed = adcKeyscan6(BUTTON_PIN1); //read button_pin1
  if (key_pressed & KEY_1) {
    //key_1 pressed, do something
  }

  if (key_pressed & (KEY_2 | KEY_3)) {
    //key_2 or key_3 pressed, do something else
  }

  if ((key_pressed & KEY_4) | (key_pressed & KEY_5)) {
    //key4 and key_5 pressed.
  }
  ...


You can expand it to read more or less pins. It assumes 10-bit adc and buttons are pulled to Vref.

oric_dan

Quote
Quote from: dhenry on Today at 06:00:09 AM
Quote
R-2R networks only work with SPDT switches, not SPST push buttons.

Are you sure about that?

With a r2r type button, you can read multiple buttons from one pin, and you can detect simultaneous presses as well.


The correct answer is you need to use SPDT switches on the side resistors. This way you get the proper voltage
changes for all bits, so every change is an exact multiple of the LSB change.

http://en.wikipedia.org/wiki/Resistor_ladder

The R2R ladder network works properly by virtue of the "summing point impedance [resistance]" always being
exactly 2R when looking back down the network [right to left] at each and every node.

This only happens if you use SPDT switches.


MarkT


Quote
R-2R networks only work with SPDT switches, not SPST push buttons.


Are you sure about that? :)

With a r2r type button, you can read multiple buttons from one pin, and you can detect simultaneous presses as well.



Yes I'm sure.  With only SPST you need an R-2R-4R-8R-16R-32R-64R-... network.
[ I won't respond to messages, use the forum please ]

Go Up