Author Topic: Fun Project: Using only one analog pin for a 5 keys kepad  (Read 12230 times)

0 Members and 1 Guest are viewing this topic.

Offline LabSpokane

  • Super Contributor
  • ***
  • Posts: 1899
  • Country: us
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #25 on: August 10, 2016, 05:31:44 pm »
Model the circuit with a switch and a randomly variable resistor in place of an ideal switch and suddenly, the results are less deterministic.

This pin count reducing method is completely fine for non-critical uses, but not for defibrillators and the like. Horsies for coursies...
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #26 on: August 10, 2016, 05:44:10 pm »
The robustness of reliability of a switch reading is directly proportional and all to do with the quality of debounce code, not the hardware,
A push-button switch is no more like a random resistor in this application that in a mission-critical defilibrator application.

If your choice of push-button MC switches are so poor in operation that they are best modeled by a random valued resistor, then you should consider better quality switches for any use or application you have in mind.
« Last Edit: August 10, 2016, 05:55:29 pm by Paul Price »
 

Offline LabSpokane

  • Super Contributor
  • ***
  • Posts: 1899
  • Country: us
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #27 on: August 10, 2016, 06:42:50 pm »
The robustness of reliability of a switch reading is directly proportional and all to do with the quality of debounce code, not the hardware,
A push-button switch is no more like a random resistor in this application that in a mission-critical defilibrator application.

If your choice of push-button MC switches are so poor in operation that they are best modeled by a random valued resistor, then you should consider better quality switches for any use or application you have in mind.

Not all switches are tactile microswitches and contact resistance can vary considerably  due to age, user pressure, location the user presses, etc.
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3510
  • Country: us
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #28 on: August 10, 2016, 06:44:04 pm »
Easy to debounce and reliable switch selection, fewest parts using common 5% resistor values. Even with 9-switches there is ~.5V between each switch for high noise immunity. Good to go with at least 10 or more switches.

Debounce code simply oversamples analog voltage measured, a sw-press is valid if the voltage for two debounce time separated readings is stable. To qualify as valid the 1st and 2nd readings for a sw. press voltage must be within the calculated voltage +/- error limits for each sw.

This is basically same as my circuit drawn vertically and with 6 switches.  The resistor values are different but the same math applies.  Written in the attached JPG is "10 bit ADC."   That has to be a typo.

With the written resistor values:

No key press:Rf=10; Rs = (56+18+10+5.6+3.9+2.7+1.8+1.5) = 99.5
1.5K pressed:Rf=10; Rs = (56+18+10+5.6+3.9+2.7+1.8) = 98.0

No keypress: 1023*(Rs/(Rs+Rf)) = 1023*(99.5/(99.5+10)) = 1023*(99.5/109.5) = 929.6 counts
1.5K preseds: 1023*(Rs/(Rs+Rf)) = 1023*(98.0/(98.0+10)) = 1023*(98.0/108.0) = 928.3 counts

So, to determine if the 1.5K switch is ON or OFF, the average ADC count difference is 1.3 counts.  This 6-switch one would work with a hell of a good ADC - but if the last LSB is off by 1, you are toasted

This would work nicely with an ADS1115 (15 bit ADC) for sure, but I am very apprehensive that an MCU's 10 bit ADC can do better than +-0.5LSB.
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3510
  • Country: us
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #29 on: August 10, 2016, 07:57:35 pm »
The robustness of reliability of a switch reading is directly proportional and all to do with the quality of debounce code, not the hardware,
A push-button switch is no more like a random resistor in this application that in a mission-critical defilibrator application.

If your choice of push-button MC switches are so poor in operation that they are best modeled by a random valued resistor, then you should consider better quality switches for any use or application you have in mind.

Not all switches are tactile microswitches and contact resistance can vary considerably  due to age, user pressure, location the user presses, etc.

In the context of fun, it may be fun (and enlightening) to use an optical resistor or optical transistor in parallel with the individual Rs'es.  The tact switches will drive the 5 optical transistors or 5 LEDs to flood the 5 optical resistors.

Then again, I am mind-locked now on using a ATTINY.  With the tiny85, I have enough pins to do I2C and 4 pins left to do 5 digital-keys.  Alternatively, I can use analog keys and I have something left over in the tiny85 to do other fun things: a Piezo-buzzer for audio key-clicks, temperature of the room (rather, of the keypad), even meaningless statistics like "time between key presses", so on...

If I can make I2C (slave) works on the USI-less tiny13a,  that would be better.  I have 1/2 dozen of tiny13a's in the drawer and they do a miserable job of being paper-weights.  This could be a good use for them if I can fit the I2C (slave) and the digital pins scanning into its really tiny space.

More options for fun than an amusement park and without the risk of people falling from a roller coaster hitting you on the head.
 

Offline metrologist

  • Super Contributor
  • ***
  • Posts: 2327
  • Country: 00
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #30 on: August 10, 2016, 08:05:15 pm »
Easy to debounce and reliable switch selection, fewest parts using common 5% resistor values. Even with 9-switches there is ~.5V between each switch for high noise immunity. Good to go with at least 10 or more switches.

Debounce code simply oversamples analog voltage measured, a sw-press is valid if the voltage for two debounce time separated readings is stable. To qualify as valid the 1st and 2nd readings for a sw. press voltage must be within the calculated voltage +/- error limits for each sw.

This is basically same as my circuit drawn vertically and with 6 switches.  The resistor values are different but the same math applies.  Written in the attached JPG is "10 bit ADC."   That has to be a typo.

With the written resistor values:

No key press:Rf=10; Rs = (56+18+10+5.6+3.9+2.7+1.8+1.5) = 99.5
1.5K pressed:Rf=10; Rs = (56+18+10+5.6+3.9+2.7+1.8) = 98.0

No keypress: 1023*(Rs/(Rs+Rf)) = 1023*(99.5/(99.5+10)) = 1023*(99.5/109.5) = 929.6 counts
1.5K preseds: 1023*(Rs/(Rs+Rf)) = 1023*(98.0/(98.0+10)) = 1023*(98.0/108.0) = 928.3 counts

So, to determine if the 1.5K switch is ON or OFF, the average ADC count difference is 1.3 counts.  This 6-switch one would work with a hell of a good ADC - but if the last LSB is off by 1, you are toasted

This would work nicely with an ADS1115 (15 bit ADC) for sure, but I am very apprehensive that an MCU's 10 bit ADC can do better than +-0.5LSB.

Rick:

If top button is pressed, he has 930 counts (1023*99.5/109.5).
If bottom button is pressed, he has 1023 counts
If 2nd from bottom is pressed, he has 133 counts (1023*1.5/11.5).

930
832
735
622
509
384
254
133
1023


 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #31 on: August 10, 2016, 08:10:42 pm »
"Then again, I am mind-locked now on using a ATTINY.  "


Somewhere here, I posted a software UART that goes to 38400bps on a 1mips attiny. All it takes is a timer isr plus a pin. It is one of those fire-and-forget types where you point a transmission pointer to your string and the isr does it for the rest while your execution moves on.


You can easily adapt that to pretty much any MCU with minimum changes.
================================
https://dannyelectronics.wordpress.com/
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3510
  • Country: us
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #32 on: August 10, 2016, 08:27:31 pm »
Easy to debounce and reliable switch selection, fewest parts using common 5% resistor values. Even with 9-switches there is ~.5V between each switch for high noise immunity. Good to go with at least 10 or more switches.

Debounce code simply oversamples analog voltage measured, a sw-press is valid if the voltage for two debounce time separated readings is stable. To qualify as valid the 1st and 2nd readings for a sw. press voltage must be within the calculated voltage +/- error limits for each sw.

This is basically same as my circuit drawn vertically and with 6 switches.  The resistor values are different but the same math applies.  Written in the attached JPG is "10 bit ADC."   That has to be a typo.

With the written resistor values:

No key press:Rf=10; Rs = (56+18+10+5.6+3.9+2.7+1.8+1.5) = 99.5
1.5K pressed:Rf=10; Rs = (56+18+10+5.6+3.9+2.7+1.8) = 98.0

No keypress: 1023*(Rs/(Rs+Rf)) = 1023*(99.5/(99.5+10)) = 1023*(99.5/109.5) = 929.6 counts
1.5K preseds: 1023*(Rs/(Rs+Rf)) = 1023*(98.0/(98.0+10)) = 1023*(98.0/108.0) = 928.3 counts

So, to determine if the 1.5K switch is ON or OFF, the average ADC count difference is 1.3 counts.  This 6-switch one would work with a hell of a good ADC - but if the last LSB is off by 1, you are toasted

This would work nicely with an ADS1115 (15 bit ADC) for sure, but I am very apprehensive that an MCU's 10 bit ADC can do better than +-0.5LSB.

Rick:

If top button is pressed, he has 930 counts (1023*99.5/109.5).
If bottom button is pressed, he has 1023 counts
If 2nd from bottom is pressed, he has 133 counts (1023*1.5/11.5).

930
832
735
622
509
384
254
133
1023

You are right, I was very careless.  No ice cream for me today so I learn a lesson.

He is connecting them in parallel!  Not like my serial one at all.  At least his bottom key is not individual - ie: cannot be combined with other keys.

I have to analyze if the other 5 are "combinable".  If individual keys can be combined, may be 5 in parallel is better than 5 in serial.
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3510
  • Country: us
Re: Fun Project: Using only one analog pin for a 5 keys kepad
« Reply #33 on: August 10, 2016, 08:29:08 pm »
"Then again, I am mind-locked now on using a ATTINY.  "


Somewhere here, I posted a software UART that goes to 38400bps on a 1mips attiny. All it takes is a timer isr plus a pin. It is one of those fire-and-forget types where you point a transmission pointer to your string and the isr does it for the rest while your execution moves on.


You can easily adapt that to pretty much any MCU with minimum changes.

Thanks!  I will look into that for sure.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf