So, this is peculiar. I am using an ATTINY84 chip as an i2c ADC converter (there are reasons why I'm using this rather than a dedicated chip, but that's not really relevant), and I've noticed that I get odd results unless I power the chip from 5v (it's normally at 3.3v since the other chips I'm using are 3.3v*).

If the chip is powered at 3.3V, analogRead provides a seemingly random value between 0 and 40 or so (which changes on each read over that whole range). At a 5v supply, it suddenly stabilizes to a change of no more than 10 and the range goes to the proper 0-1023. If I supply VCC to the pin in 3.3v mode, I get arbitrary garbage as described, but at 5v VCC and 5v to the ADC pin, I get 1023.

The datasheet says these work as low as 2.7v or 1.8v (depending on version), so why would the ADC only respond properly when it's powered from 5v?

I have the efuses set with:

avrdude -cusbasp -pt84 -v -B 100 -U lfuse:w:0xe2:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m

My setup code is:

// Setup fast ADC for sampling audio
ADCSRA &= ~(bit(ADPS0) | bit(ADPS1) | bit(ADPS2)); // clear prescaler bits
//  uncomment as required (Credit: http://www.gammon.com.au/adc)
ADCSRA |= bit(ADPS2); //  16

I'm not doing anything else that should be messing with the ADC modes. Perhaps this clock is too fast for 3.3v? I'm using the internal 8mhz clock source, and the ADC reference is whatever is selected as the default if I don't specify. (I could add analogReference(DEFAULT); -- but that should already BE the default?)

*The host controller for this is an ESP8266, which is a 3.3v chip. It's supposed to be 5v tolerant, but I'd prefer not to risk that. It seems that the Wire library for the Tiny is adding internal pullups on the '84, so is there any way to disable those when running it at 5V to prevent the i2c bus voltage creeping up? My other solution is to get the ADC to work properly even at the lower voltage supply...

  • "I get odd results" which are what exactly? Also internal 8MHz should be good, "0 - 8MHz at 2.7 - 5.5V, 0 - 16MHz at 4.5 - 5.5V" from the datasheet. I think your problem is just that the analog reference is by default "VCC used as analog reference", meaning you are measuring stuff relative to your 3.3V VCC supply. You might want external Ref or internal 1.1V ref? Or voltage dividers on your inputs? (see ww1.microchip.com/downloads/en/devicedoc/… page 129) – Maximilian Gerhardt Aug 4 at 19:41
  • I am getting results -- no matter what the input voltage is -- of about 0-40 as output from AnalogRead(), and the value does not stay steady. If I change VCC to 5v, I get the 0-1023 range and it's stable. In both cases, I am using a testing voltage that is between GND and (the current) VCC, but it doesn't work properly unless powered at 5v. – RDragonrydr Aug 4 at 19:46
  • Very weird. How do you output the ADC result? Via UART? Also, does changing the ADC clock rate have an effect( e.g., ADPS2:0 to "000" for div by 2 or "111" for div by 128) – Maximilian Gerhardt Aug 4 at 19:56
  • I have been using I2C to send the values. If it's out of sync or just not working, I get 32760 or whatever max of Int16 is, but instead I get this weird result. I'll try the clock div adjustment now... Edit: Nope, it's still the same regardless of the ADC clock setting. – RDragonrydr Aug 4 at 20:16
  • Can you share your circuit with us? – Majenko Aug 4 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.