I'm trying to get an ATtiny84a to read an analog voltage using the external reference, but it doesn't work: I only get readings of 1023, while I expect a reading of about 500.
Measuring with my multimeter I see 0.5V at the PA3 pin (which I'm trying to read), and 1.0V at the PA0 pin (AREF). Doing the same with INTERNAL or default reference works fine, I get the readings I expect. As my reference voltage is slightly less than the internal reference I could of course use the internal reference but that doesn't negate the problem that the external reference should work, and at the very least I'd like to know why not.
Vcc is a about 5.3V; external 20 MHz crystal.
const uint32_t transmitInterval = 1000;
void setup() {
Serial.begin(9600); // ATtiny84 built-in Serial implementation uses TX = AIN0/PA1, RX = AIN1/PA2.
analogReference(INTERNAL); // Use the internal reference. Works as expected.
// analogReference(EXTERNAL); // Use the generated reference voltage (of about 1000 mV). Gives readings of 1023.
}
void loop() {
static int32_t lastTransmitData;
if (millis() - lastTransmitData > transmitInterval) {
lastTransmitData += transmitInterval;
Serial.println(analogRead(3));
}
}
I couldn't find any error, neither in your code, in your schematics nor in the core.
But what I found is that you must not set analogReference() to INTERNAL while you apply a voltage directly to the AREF pin. If you want to be able to switch to INTERNAL, the external voltage should be applied through a 5k resistor. But this is not for free, the 5k resistor changes the ADC result as it builds a voltage divider with an internal 32k resistor. Unfortunately there is no description of the potential damage if you don't follow this rule.
pylon:
But what I found is that you must not set analogReference() to INTERNAL while you apply a voltage directly to the AREF pin.
That applies to the ATmega series, which have a dedicated AREF pin. In case of the ATtiny the AREF pin is also a regular I/O pin, that even has an ADC channel.
That applies to the ATmega series, which have a dedicated AREF pin. In case of the ATtiny the AREF pin is also a regular I/O pin, that even has an ADC channel.
I know but nevertheless the datasheet says (section 16.13.1):
Internal voltage reference options may not be used if an external voltage is being applied to the
AREF pin.
Mmm... I still don't get it. Especially as when I set it to use the internal reference I actually get sensible readings!
I have a second board assembled, haven't tried that one yet. Maybe there's something wrong with the processor itself... unlikely but it's pretty much the last option left. That, or a bug in ATtinyCore.
I tried my second board - exactly the same behaviour. No proper readings with the external reference (all at 1024), expected readings with the internal reference.
Just to be safe I have unsoldered pin 13 (the AREF), so nothing gets damaged. Doesn't make a difference in the behaviour (as expected).
Well, the final solution is to use the internal 1.1V reference, instead of the self-generated 960 mV reference. I've given up on the AREF, at least for now. Maybe later on breadboard I'm going to experiment more but the main problem is that I still have no clue on what could possibly be wrong here.
pylon:
I couldn't find any error, neither in your code, in your schematics nor in the core.
You don't see anything; no-one else contributing so I may assume no-one else seen anything wrong. I'm convinced everything is done according to the book, still it doesn't work...
Giving up. Not going to have this stop the progress of the project.