Pages: [1]   Go Down
Author Topic: Small bug in wiring_analog.c concerning ATTiny and analog references  (Read 1369 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you search, you find a lot of folks suggesting the 2.56 volt analog reference using an analogReference value of 6.

That ostensibly works if you look at the ATTiny data sheet... until you look up a bit and notice that the three bits of that value are not next to each other.

The original wiring_analog.c says:

#if defined(ADMUX)
        ADMUX = (analog_reference << 6) | (pin & 0x07);
#endif

But that shifts the top bit of the analogReference() value out of the byte. The correct thing to do - at least on the ATTiny platform - is

#if defined(ADMUX)
        ADMUX = (analog_reference << 6) | (pin & 0x07) | ((analog_reference & 0x4)?0x10:0);
#endif

That is, REFS0 is bit 6 in the ADMUX word, REFS1 is bit 7, and REFS2 is bit FOUR.

See 17.13.1 in the ATTiny85 data sheet.
Logged

Pages: [1]   Go Up
Jump to: