Solved: Attiny 85 ADC reads always 1023 irrespective of input

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

I am trying to read a analogue voltage using the ADC in attiny85. But the ADC register always read 1023 irrespective of what input is given. Moreover when the ADC pin is measured with a multimeter it shows nearly 3.1V. I aasumed that it is pulled up but the fact is, when i connect the pin to external analog input , the voltage at the pin disturbs the external input voltage circuit. I dont know why this happens. the same code worked well before 6 months but now it is not. reason unknown. could anyone explain me what I'm actually doing wrong? I am using USBasp as my programmer , attiny85 as my target microcontroller, atmel studio 7 as my build tool with WinAVR. thanks in advance:)

Attachment(s): 

it'sdk

Last Edited: Wed. May 15, 2019 - 01:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define F_CPU 16000000UL
#define myTx PB1 //PB1
#define myRx PB0 //PB0
#define ADC_CH_2 PB4
#define ADC_CH_3 PB3

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
uint8_t temp = 0;
uint16_t u=0, adcValue=0;

ISR(ADC_vect) {
	adcValue = ADCW;
	//adcValue = (ADCH<<8)|ADCL;
	if (adcValue==1023){
		int i=1;
		while(i++<20){
			PORTB|= 1<<PB1;
			_delay_ms(100);
			PORTB&= ~(1<<PB1);
			_delay_ms(100);
		}
		
	}else{
		PORTB|= 1<<PB1;
	}

}

int main(void) {
	DDRB|=1<<PB1;
	PORTB&=~(1<<PB1);

	MCUCR &= ~(1 << PUD); //disabling Pull Up Disable i.e, enabling pullups, otherwise pull up resistors cannot be enabled in pins
	
	// IO configuration
	DDRB &= ~(1 << ADC_CH_2) & ~(1 << ADC_CH_3); //configuring as input
	PORTB |= (1 << ADC_CH_2) | (1 << ADC_CH_3); //  writing 1 to an input pin activates pullup-resistor
	DIDR0 |= (1 << ADC_CH_2) | (1 << ADC_CH_3); // disable digital buffer in analog pins to save power
	

	//ADC configuration
	ADCSRA |= (1 << ADEN); //enable ADC
	ADCSRA |= (1 << ADIE); //enable conversion complete interrupt
	//ADCSRA |= (1 << ADPS0) | (1 << ADPS1); ADCSRA &= ~(1 << ADPS2); // prescaler 8 - 
	ADCSRA |= (1 << ADPS0) | (1 << ADPS1) |(1 << ADPS2); 

	ADMUX &= ~(1 << ADLAR); // right most shift in ADCH and ADCL i.e, ADCH has two MSB bits and ADCL has 8 LSB bits
	// if ADLAR=1, ADCH would have 8 MSB bits and ADCL has 2 LSB bits
	ADMUX &= ~(1 << REFS0) & ~(1 << REFS2); ADMUX |= (1 << REFS1); // Vref as 1.1V
	_delay_ms(10);

	//ADMUX |= (1 << REFS1) | (1 << REFS2); ADMUX &= ~(1 << REFS0); //Vref as 2.56V

	
	//  ADMUX |= (1 << MUX1);ADMUX &= ~(1 << MUX2) & ~(1 << MUX0) & ~(1 << MUX3);//adc2
	ADMUX |= (1 << MUX1) | (1 << MUX0) ;ADMUX &= ~(1 << MUX2) & ~(1 << MUX3);//adc3

	//ADCSRB |= (1 << BIN); //enabling bipolar mode i.e, voltage at the positive pin can be less than negative pin
	//     that is voltage can swing from - vref to +vref and the resolution is 9 bits as the tenth bit is for sign.
	// if same 1- bit resolution is needed refer datasheet for IPR bit in ADCSRB register

	sei(); // enable all interrupts
	//set_sleep_mode(SLEEP_MODE_ADC);
	//sleep_enable();
	while (1) {
		ADCSRA|=1<<ADSC;
		_delay_ms(1000);
		//sleep_cpu();
	}




	return 0;
}

 

Um. Why bother with the interrupt and nobody would do 40 _delay_ms(100) in an isr.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

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

it'sDK wrote:
the voltage at the pin disturbs the external input voltage circuit. I dont know why this happens.

Show a schematic.  That will help with the next basic questions about ground connections and AVcc and start on the reference questions.

 

[yet another poster that appears to be enamored with |= .  Is that taught in AVR primary school?]

Torby wrote:

ADMUX &= ~(1 << REFS0) & ~(1 << REFS2); ADMUX |= (1 << REFS1); // Vref as 1.1V

 

So, with a reference of 1.1V and a signal of 3V, what conversion result would you expect other than 1023?

 

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Torby wrote:

//ADCSRB |= (1 << BIN); //enabling bipolar mode i.e, voltage at the positive pin can be less than negative pin
	//     that is voltage can swing from - vref to +vref and the resolution is 9 bits as the tenth bit is for sign.

On a side note, a Tiny85 does NOT accept negative voltages on any pin.  An AVR might have "differential" mode, but not "bipolar".  [yes, I realize that it is a comment block...have I been missing the BIN bit all these years?]

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Sat. May 11, 2019 - 12:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

have I been missing the BIN bit all these years?

 

Most don't have it.  And on the Arduino, BIN gets

redefined to mean "convert integer to binary string"

so it's hard to use.

 

--Mike

 

EDIT: BIN does not appear in any megas it seems.

It's present on ATtiny24/44/84, ATtiny25/45/85,

ATtiny261/461/861, and ATtiny87/167.

 

Another oddball ADC bit is the IPR (Input Polarity

Reversal) bit which is only found on a few tiny's:

ATtiny25/45/85 and ATtiny261/461/861.

 

Last Edited: Wed. May 15, 2019 - 05:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your reply @ theusch . the 3V i measured is not the input i have applied to the ADC but it is the voltage at the adc pin which is measured separately when it is not connected to any inputs.

i have attached my schematic for reference

Attachment(s): 

it'sdk

Last Edited: Sun. May 12, 2019 - 04:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Torby wrote:

//ADCSRB |= (1 << BIN); //enabling bipolar mode i.e, voltage at the positive pin can be less than negative pin
	//     that is voltage can swing from - vref to +vref and the resolution is 9 bits as the tenth bit is for sign.

On a side note, a Tiny85 does NOT accept negative voltages on any pin.  An AVR might have "differential" mode, but not "bipolar".  [yes, I realize that it is a comment block...have I been missing the BIN bit all these years?]

attiny85 has bipolar mode as stated in datasheet. i have attached the part of the datasheet for reference. And i am still doubtful about the BIN bit in arduino as it changes colour when it was typed. so as u said, in arduino environment there might be some other meaning for the BIN bit.

Attachment(s): 

it'sdk

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

it'sDK wrote:

I am trying to read a analogue voltage using the ADC in attiny85. But the ADC register always read 1023 irrespective of what input is given. Moreover when the ADC pin is measured with a multimeter it shows nearly 3.1V. I aasumed that it is pulled up but the fact is, when i connect the pin to external analog input , the voltage at the pin disturbs the external input voltage circuit. I dont know why this happens. the same code worked well before 6 months but now it is not. reason unknown. could anyone explain me what I'm actually doing wrong? I am using USBasp as my programmer , attiny85 as my target microcontroller, atmel studio 7 as my build tool with WinAVR. thanks in advance:)

 

a short update.......

 the problem is partially solved by disabling the pullup resistors. but the issue still remains is that everyother adc pins except adc3 works fine. i have applied a test input of 0.46 volt and it has been measured as it is in other adc pins except adc3. i attached my output log which is printed using softwareserial library in arduino and the reference as 2.56V internal reference.

Attachment(s): 

it'sdk

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

attiny85 has bipolar mode as stated in datasheet

They may call it bipolar somewhat as a marketing ploy, but it is at most bipolar differential with a complementary result.  At no time can the ADC accept both positive and negative (bipolar) voltages on any input pin.   Only positive pin voltages are ever allowed.

Violators will be visited by the AVR Dragon.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

avrcandies wrote:

attiny85 has bipolar mode as stated in datasheet

They may call it bipolar somewhat as a marketing ploy, but it is at most bipolar differential with a complementary result.  At no time can the ADC accept both positive and negative (bipolar) voltages on any input pin.   Only positive pin voltages are ever allowed.

Violators will be visited by the AVR Dragon.

 

what i am trying to say regarding bipolar is, voltage at the negative terminal of a differential ADC terminal could be greater than the positive terminal. what u said is always correct that when ADC channels are used single ended, it accepts a minimum voltage equal to its GND voltage. And I think we are deviated from actual topic of discussion why the ADC value is 1023.

it'sdk

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

it'sDK you have to listen to what people say:

 

When a ADC is bipolar that means that it's ok with a input level below GND (like -3V) that it NOT legal on a AVR.

 

The differential ADC mode is not "true" bipolar. (but you can fake it by having 1/2 vref as 0 for the analog parts).  

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

i have attached my schematic for reference

Find out what happened to it.  The connectors and wires are all twisted haphazardly around--was there some problem saving the file?  Where are the filter caps on the adc inputs?  In fact, where are the signal sources?    Vcc seem to be missing a cap as well.

 

Did you try connecting the ADC pins to gnd, to see if you read near zero counts?

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

sparrow2 wrote:

it'sDK you have to listen to what people say:

 

When a ADC is bipolar that means that it's ok with a input level below GND (like -3V) that it NOT legal on a AVR.

 

The differential ADC mode is not "true" bipolar. (but you can fake it by having 1/2 vref as 0 for the analog parts).  

 

ok i understood, what true bipolar is. thanks for making it clear

it'sdk

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

avrcandies wrote:

i have attached my schematic for reference

Find out what happened to it.  The connectors and wires are all twisted haphazardly around--was there some problem saving the file?  Where are the filter caps on the adc inputs?  In fact, where are the signal sources?    Vcc seem to be missing a cap as well.

 

Did you try connecting the ADC pins to gnd, to see if you read near zero counts?

 

 

Vcc pin is powered from a stabilized source. so i thought it is not needed for a decoupling capacitor between Vcc and GND. And regarding filter caps at ADC inputs, I am sure that my input signal wont change suddenly or wont change between the period of ADC sampling, so i discarded the filtercaps at ADC inputs. My input to ADC is a gas sensor's output, whose response time extends from few seconds to minutes. hence i thought that a filter at ADC is not neccesarily needed. I have summarized what assumptions I have taken before making this design.  Correct me if I am wrong. thanks in advance

it'sdk

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

What gas sensor? What's the output Range of the gas detector?

I'm glad you disabled the pullups on your adc pins, as i was going to mention that, I'm surprised nobody else did.

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

Kuch wrote:
What gas sensor? What's the output Range of the gas detector? I'm glad you disabled the pullups on your adc pins, as i was going to mention that, I'm surprised nobody else did.

Thanks for your reply @ Kuch,

 The output range of the gas sensor is within my power supply range (say 0 to 5V). And yes, i have disabled pullups not only in my adc pins but all. (PUD=1 in MCUCR register ) 

it'sdk

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

Did you try grounding the pin to see if you get a count near zero?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

avrcandies wrote:

Did you try grounding the pin to see if you get a count near zero?

 

Yes i got 0 as the ADC value when the pin is directly connected to ground. but as soon as i unplug it from the ground, it reads 1023. And one more thing to note is, when the ADC3 is measured with a multimeter (when it is not connected to external analog input) the multimeter reads a value near to Vcc in ADC channel 3 and other channels reads some 200mV but the ADC reads correct value when other channels are connected to an input except ADC3.

it'sdk

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

Are you building for the correct chip?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Brian Fairchild wrote:

Are you building for the correct chip?

 

yes i am building for the correct chip. i tried with arduino and atmelstudio with WinAVR and latest atmel studio avr toolchain. this is cross verified when avrdude uploads the program (device signature check). But whenever I am uploading my code using my usbasp, avrdude always says cannot set sck period ,update firmware. was that might be the root of problem??

it'sdk

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

it'sDK wrote:
avrdude always says cannot set sck period
Red herring. Ignore that.

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

clawson wrote:

 Red herring. Ignore that.

 

yes I ignored that too.

 

it'sdk

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

it'sDK wrote:

avrcandies wrote:

i have attached my schematic for reference

Find out what happened to it.  The connectors and wires are all twisted haphazardly around--was there some problem saving the file?  Where are the filter caps on the adc inputs?  In fact, where are the signal sources?    Vcc seem to be missing a cap as well.

 

Did you try connecting the ADC pins to gnd, to see if you read near zero counts?

 

 

Vcc pin is powered from a stabilized source. so i thought it is not needed for a decoupling capacitor between Vcc and GND. And regarding filter caps at ADC inputs, I am sure that my input signal wont change suddenly or wont change between the period of ADC sampling, so i discarded the filtercaps at ADC inputs. My input to ADC is a gas sensor's output, whose response time extends from few seconds to minutes. hence i thought that a filter at ADC is not neccesarily needed. I have summarized what assumptions I have taken before making this design.  Correct me if I am wrong. thanks in advance

 

Um.. You need those caps.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

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

it'sDK wrote:
Vcc pin is powered from a stabilized source. so i thought it is not needed for a decoupling capacitor between Vcc and GND. And regarding filter caps at ADC inputs, I am sure that my input signal wont change suddenly or wont change between the period of ADC sampling, so i discarded the filtercaps at ADC inputs. My input to ADC is a gas sensor's output, whose response time extends from few seconds to minutes. hence i thought that a filter at ADC is not neccesarily needed. I have summarized what assumptions I have taken before making this design.  Correct me if I am wrong. thanks in advance

 

First you MUST have power bypass caps, mounted as close to the AVR across all power pins vcc/gnd, and avcc/gnd as possible, normally these are 100nf. 

As for the ADC inputs, it's not about if an input will/will not change as it is about input/output impedance matching into the ADC. 

There is a very short time when the internal input sampling cap of the ADC is able to sample the voltage on the pin, an input filter helps to match the impedance of the senor output to the input impedance of the ADC,

having a cap on the input of the ADC is a nice low impedance source for the ADC to sample from. 

So go into your design and add the bypass cap and a low freq low pass filter with the cap mounted close to the ADC pin.

 

Now I thought I saw mentioned that the gas sensor had a 0-5v output range, but the AVR is powered from vcc 3.3v, so you may also need to limit the input to the ADC to a max of 3.3v with a limiter circuit as well.

Assuming your using VCC as the ADC ref voltage, any input over vcc will read 1023, and may damage the AVR chip.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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


I keep coming back to the point that Lee highlighted in #3:

	ADMUX &= ~(1 << REFS0) & ~(1 << REFS2); ADMUX |= (1 << REFS1); // Vref as 1.1V

If the ref is 1.1V then 0V = 0 and 1.1V is 1023. How do you ever expect to read outside this range ? If the voltage applied is anything over 1.1V it's going to read 1023 which is what the thread title seems to be confirming??

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

clawson wrote:

I keep coming back to the point that Lee highlighted in #3:

	ADMUX &= ~(1 << REFS0) & ~(1 << REFS2); ADMUX |= (1 << REFS1); // Vref as 1.1V

If the ref is 1.1V then 0V = 0 and 1.1V is 1023. How do you ever expect to read outside this range ? If the voltage applied is anything over 1.1V it's going to read 1023 which is what the thread title seems to be confirming??

That's why I was asking what the output of the gas sensor was after seeing he is using internal 1.1v reference

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

Ok, good, gnd gives zero!

 

Now take a 1 k or 5k pot and tie it to gnd & VCC & your ADC pin....start turning it up...do the counts begin to rise? You can compare to your multimeter (using scaling, depending upon your Vref)

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

ki0bk wrote:

it'sDK wrote:
Vcc pin is powered from a stabilized source. so i thought it is not needed for a decoupling capacitor between Vcc and GND. And regarding filter caps at ADC inputs, I am sure that my input signal wont change suddenly or wont change between the period of ADC sampling, so i discarded the filtercaps at ADC inputs. My input to ADC is a gas sensor's output, whose response time extends from few seconds to minutes. hence i thought that a filter at ADC is not neccesarily needed. I have summarized what assumptions I have taken before making this design.  Correct me if I am wrong. thanks in advance

 

First you MUST have power bypass caps, mounted as close to the AVR across all power pins vcc/gnd, and avcc/gnd as possible, normally these are 100nf. 

As for the ADC inputs, it's not about if an input will/will not change as it is about input/output impedance matching into the ADC. 

There is a very short time when the internal input sampling cap of the ADC is able to sample the voltage on the pin, an input filter helps to match the impedance of the senor output to the input impedance of the ADC,

having a cap on the input of the ADC is a nice low impedance source for the ADC to sample from. 

So go into your design and add the bypass cap and a low freq low pass filter with the cap mounted close to the ADC pin.

 

Now I thought I saw mentioned that the gas sensor had a 0-5v output range, but the AVR is powered from vcc 3.3v, so you may also need to limit the input to the ADC to a max of 3.3v with a limiter circuit as well.

Assuming your using VCC as the ADC ref voltage, any input over vcc will read 1023, and may damage the AVR chip.

 

Jim

 

Thanks a lot for explaining me in detail with patience. It would be much appreciated if i am provided with a standardized way on how to calculate the cut off frequency of the low pass filter that sits before the ADC sample and hold circuit. in some tutorials i have seen that the cut-off frequency is determined by the sampling rate of the ADC. Is it so??? correct me if I am wrong:)

it'sdk

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

Kuch wrote:
clawson wrote:

I keep coming back to the point that Lee highlighted in #3:

	ADMUX &= ~(1 << REFS0) & ~(1 << REFS2); ADMUX |= (1 << REFS1); // Vref as 1.1V

If the ref is 1.1V then 0V = 0 and 1.1V is 1023. How do you ever expect to read outside this range ? If the voltage applied is anything over 1.1V it's going to read 1023 which is what the thread title seems to be confirming??

That's why I was asking what the output of the gas sensor was after seeing he is using internal 1.1v reference

 

thanks for pointing it out. let me explain it in detail. The gas sensor's output is bounded by the range 0-5V but it wont even cross 1V under normal conditions. the outputs i have posted before are applied from a  resistive potential divider setup and channel 3 is not working properly even for the input from the potential divider. I use potential dividers for testing the working of my ADC here. If this phase succeeds then i would connect my gas sensor. My problem is i could not even pass the testing phase, as channel 3 always reads 1023 whatever the input voltage is applied. I applied a test input of 0.46 Volts. Other ADC channels worked correctly except the channel 3. Hope, I explained in detail. if not, my apologies:)

it'sdk

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

avrcandies wrote:

Ok, good, gnd gives zero!

 

Now take a 1 k or 5k pot and tie it to gnd & VCC & your ADC pin....start turning it up...do the counts begin to rise? You can compare to your multimeter (using scaling, depending upon your Vref)

 

Sure , I would definitely try this out and I will update the forum as soon as possible. Thank you for reminding me this simple trick.

it'sdk

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

it'sDK wrote:
as channel 3 always reads 1023 whatever the input voltage is applied
Did you check the voltage right at the ADC3 pin. Sounds like a pin tied to Vcc perhaps? Either that or the code is not actually reading ADC3.

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

clawson wrote:

it'sDK wrote:
as channel 3 always reads 1023 whatever the input voltage is applied
Did you check the voltage right at the ADC3 pin. Sounds like a pin tied to Vcc perhaps? Either that or the code is not actually reading ADC3.

yes I measured the voltage at the pin. it is near to Vcc or Vcc mostly. I dont know how it is tied to Vcc always. Also i tried enabling(PUD = 1) the global pullup disable bit in MCUCR register and checked the PORT registers too.

it'sdk

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

Is the source code you've posted a full source code? Can't it be that you've accidentally switched PB3 to output in other part of the program? Can it be you've accidentally enabled ~OC1B that overrides PB3 direction? Is there anything connected to PB3 wire apart from attiny85 chip itself and multimeter reading its voltage?

Have both efficient implementation and comprehensive source code for peripherals configuration with my library: https://github.com/ichthuss/opti_init

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

Well, if the voltage is at or close to Vcc why are you surprised by the 1023 reading?

 

If you pull the pin to Vcc/2 does it read 512?

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

ichthuss wrote:

Is the source code you've posted a full source code? Can't it be that you've accidentally switched PB3 to output in other part of the program? Can it be you've accidentally enabled ~OC1B that overrides PB3 direction? Is there anything connected to PB3 wire apart from attiny85 chip itself and multimeter reading its voltage?

 

The code I posted is the complete source code. And the doubt u had is valid and I have checked it before by checking the GTCCR register which has COM1B0 and COM1B1 bits which controls the OC1B is enabled or not . As per datasheet, writing 0 to both of these bits disable the functionality of ~OC1B and OC1B in PB3 and PB4 respectively. And I checked the GTCCR register too. GTCCR = 0x00.

it'sdk

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

Well, if I were you, the first thing I would do is to flash the firmware to the bare attiny85 chip, not wired to anything but power supply. And then checked if PB3 pin floating or tied to the Vcc. (That is, connected it with resistors to both Vcc and GND, and checked it it's near the Vcc/2). This way I would know if it software of hardware problem. If it's a software one, I'd strip the code until it disappeared. If it's a hardware one, I'd checked if my attiny85 chip in the board healthy and if there's anything more wired to the PB3.

Have both efficient implementation and comprehensive source code for peripherals configuration with my library: https://github.com/ichthuss/opti_init

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

when the ADC3 is measured with a multimeter (when it is not connected to external analog input) the multimeter reads a value near to Vcc

Because that's what you have programmed in your code.

PORTB |= (1 << ADC_CH_2) | (1 << ADC_CH_3); //  writing 1 to an input pin activates pullup-resistor

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

yes I measured the voltage at the pin. it is near to Vcc or Vcc mostly. I dont know how it is tied to Vcc always

Hooking it to nothing or "uknown" gives results that are meaningless & unknown in nature.  Hook it to a 1K  or 5K pot so you can vary the voltage & check the corresponding results.  Remove this unknown factor. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Sorry guys, The problem is with the IC (mcu), when I replaced it, everything is working as expected. Thank you so much for this great discussion, as this is my first discussion in AVR freaks. Eventhough the solution is a replacement, I learned a lot about analog circuit design in terms of how a ADC interface should be provided to external environment signals. Thanks a lot once again for such a detailed discussion.

it'sdk

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

Why are you burning out your chips...do you clamp and/or tranzsorb the voltage going to the ADC pin(s)?  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

avrcandies wrote:

Why are you burning out your chips...do you clamp and/or tranzsorb the voltage going to the ADC pin(s)?  

 

Sorry , I dont know what tranzsorb means. could you plz explain me with a little detail.

it'sdk

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

try entering Transzorb into a search engine.  TransZorb is a trademark but this gives some detail https://en.wikipedia.org/wiki/Tr...

 

David