Hi, I'm using Attiny45 and learning how to use the ADC from the forum tutorial.
I'm just trying to light a LED if the ADC value is less than 1/2 and turn the LEd off if its more than1/2.
I'm using a 10k pot. It is connected in this manner:
Vcc - 510ohm - 10k pot- 510ohm - Gnd
The issue here is that 1st time I use ADC2(PB4 it works, but when I switch to ADC3 (PB3)it wont work, and changing back to ADC2 and still not working. However it will work at ADC 1 (PB2).
Here's the code
DDRB |= 0b00001; // set PB0, output PORTB |= 0b00000; ADCSRA |=(1<<ADEN); //enable ADC ADCSRA |=(1<<ADPS1)|(1<<ADPS0);// select prescale timer = 8, 125kHz @1Mhz ADMUX &= 0xF8; //clear 1st 3 bits ADMUX |=(1<<MUX0); //select channel= ADC1(pb2) & differential gain= N/A ADMUX |=(1<<ADLAR); //select left adjust; 8bit ADC; register in ADCH //voltage ref VCC **NO ADMUX BIT SELECTED** ADCSRA |=(1<<ADATE); //enable auto trigger & mode selection in ADCSRB //select mode = free running **NO ADCSRB BIT SELECTED** ADCSRA |= (1<<ADSC);//start ADC for(;;) { if(ADCH<128) {PORTB = 0b00001;}//PB0 high else {PORTB = 0b00000;} } }
for selecting ADC2, I use:
ADMUX |=(1<<MUX1); //select channel= ADC2(pb4) & differential gain= N/A
And for selecting ADC3:
ADMUX |=(1<<MUX1)|(1<<MUX0); //select channel= ADC3(pb3) & differential gain= N/A
I think there might be something wrong with the hardware and I use this code to test the IO pins.
#includeint main(void) { DDRB |= 0b11111; PORTB|= 0b11111; }
When I have a LED connected to PB4, it wont light up!!
So how can this happen? something wrong in the programming/ hardware?
Can it be possible for me to damage the PB4 pin after using it for ADC??
Thanks in advance.