Skip to content

t13 has different ADMUX than tx5 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nerdralph opened this issue Feb 20, 2020 · 3 comments
Open

t13 has different ADMUX than tx5 #7

nerdralph opened this issue Feb 20, 2020 · 3 comments

Comments

@nerdralph
Copy link

The tiny13 only has 2 mux bits, not 4. I'm guessing the code has not been tested on the t13. as it won't work unless ADC1 (PB2) happens to be grounded.
https://github.com/martin2250/ADCTouch/blob/master/src/ADCTouch.cpp#L24

@martin2250
Copy link
Owner

martin2250 commented Feb 29, 2020

Hi Ralph,

thanks for bringing this up. I never had a chance to test this on the various AtTinys, support on the tiny13 is a contribution by @UriShX I'll ask him to investigate this as I currently don't have the time or hardware required.

Martin

@UriShX
Copy link
Contributor

UriShX commented Feb 29, 2020

Hi Ralph, Martin,

I have it currently working on a tiny13a in a circuit with PB2 left floating, since I also use it for SCK, and I am detecting touch on PB3. I found that as long as the power to the circuit is over 3V, detection works quite well for the purposes I used it.

I realize that the intent of line 24 is to ground the pins and discharge the s&h cap. I simply did not understand at the time the importance of that. I will investigate further, perhaps give the t13 its own definition, like:
#if defined(__ATtiny13__)
// charge s&h cap
pinMode(digitalPin, INPUT_PULLUP);
// set ADMUX
ADMUX = (ADMUX & 0xF0);
// set pin as output, then set value to high, then low. acc. to TDS section 10.2.3 Switching Between Input and Output
pinMode(digitalPin, OUTPUT);
digitalWrite(digitalPin, HIGH);
digitalWrite(digitalPin, LOW);
// set pin as input without charging s&h cap again
pinMode(digitalPin, INPUT);
#endif

Uri

@nerdralph
Copy link
Author

I did some experimentation with the technique, and got the best results by:

  1. ground the touch pin with ADC enabled to discharge the ~10pf S/H cap.
  2. disable ADC & charge touchpad
  3. enable ADC and take a reading after the charge is equalized

Here's the prototype code:
https://github.com/nerdralph/nerdralph/blob/master/avr/adctouch.c

Since the t13's ADMUX setttings are a subset of the tx5, it should work the same on the tiny 25/44/85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants