1

I was modifying this ADC Touch implementation, namely switching analogRead and pinMode to what I thought would be port manipulation equivalents.

I get very different readings (better and more stable in my case).

So, what I think is equivalent is actually quite different. Can someone point the differences to me?

Original:

 pinMode(ADCChannel, INPUT_PULLUP);
 ADMUX |= 0b11111;
 ADCSRA |= (1<<ADSC); //start conversion
 while(!(ADCSRA & (1<<ADIF))); //wait for conversion to finish
 ADCSRA |= (1<<ADIF); //reset the flag
 pinMode(ADCChannel, INPUT);
 _value += analogRead(ADCChannel);

Modified:

 DDRC &= ~(1 << ADCChannel);
 PORTC |= (1 << ADCChannel);
 ADMUX |= 0b11111;
 ADCSRA |= (1<<ADSC); //start conversion
 while(!(ADCSRA & (1<<ADIF))); //wait for conversion to finish
 ADCSRA |= (1<<ADIF); //reset the flag
 DDRC &= ~(1 << ADCChannel);
 _value += analogRead(ADCChannel);
asked Oct 22, 2016 at 0:21

1 Answer 1

2

Your modified code doesn't disable the pullup on the pin.

PORTC &= ~_BV(ADCChannel);
answered Oct 22, 2016 at 0:49

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.