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);