attiny 45 using internal 2.56v VREF, need help with code.

so i want to use a attiny45 but use the internal 2.56v VREF for analog read.

how do i do that in code?

i knew how to do it using AVR ASM, but im not sure how to do this using arduino code.

please help.

You should be able to write AVR ASM on the arduino compiler.

C definitively works. I don't use the arduino function analogueread() myself, rather set the ADC with an interrupt to update a variable than having to wait for the conversion to be complete wasting time. During initialization you can also set the VREF to the internal VREF rather than VCC and what clock speed you wish to use.

It surprised me that the 45 has a 2V56 reference voltage, did not know that, but just checked the data sheet.
It says: "The device requries a supply voltage of 3V in order to generate 2.56V reference voltage." in a footnote.
Do you have this?
The Arduino header files do not seem to support this, the reference voltage cannot be set to 2.56 by analogReference(). I think you have to resort to writing to the registers directly

olf2012:
It surprised me that the 45 has a 2V56 reference voltage, did not know that, but just checked the data sheet.
It says: "The device requries a supply voltage of 3V in order to generate 2.56V reference voltage." in a footnote.

Same as the ATMEGA8. The Atmega358 has a 1.1V and an internal temperature sensor too :slight_smile:

The greatest advantage is that they stay stable, so an ADC reading will reflect the same input voltage at 3V or at 5V, unlike the arduino that reads with reference to its own supply.

olf2012:
The Arduino header files do not seem to support this, the reference voltage cannot be set to 2.56 by analogReference(). I think you have to resort to writing to the registers directly

Yes you do.

I would write your own version of analogReference extended to include handling
for the 2.56V reference - but note if you do this in-place in wiring_analog.c you'll
lose it when you upgrade the Arduino environment so save a copy in a sketch or
whatever.

Use this core...
https://code.google.com/p/arduino-tiny/

Put this at the top of your sketch...

void setup( void )
{
  analogReference( INTERNAL2V56 );

Bear in mind INTERNAL2V56 requires a bypass capacitor on AREF. If you do not want to include the capacitor pass a six instead...

#define INTERNAL2V56_NO_CAP (6)

void setup( void )
{
  analogReference( INTERNAL2V56_NO_CAP );