ADC channel problem

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

#include 

int 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.

Last Edited: Wed. Sep 30, 2009 - 04:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ADMUX &= 0xF8; //clear 1st 3 bits

There are 4 MUX bits, not 3. But that shouldn't be your problem since they should be 0 to start with.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oh ya.. mistake!!
thanks =)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After trying to figure out what really happen, checking thru the codes, hardware I still didnt make any progress.
Only Channel ADC1 works, while the rest didn't.

One thing for sure, PB4 of the attiny45 is dead, programmed a simple blinking LED program to drive a LED at PB4 , and it didn't work.

So anyone had a similar case like this? Got a damaged pin after trying to do ADC.