Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Collecting and ranking requests on the playground. on: September 19, 2010, 03:28:42 pm
Is there someone I can contact for changes that need to be made to the reference pages?
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: enabling variable internal ref voltage on mega on: September 18, 2010, 02:51:43 pm
neat to see this make it into the last release.

myrdyn: take codingbadly's advice and change the parameter for analogReference(..) -- when compiling for the mega

http://code.google.com/p/arduino/issues/detail?id=194 -- "I got rid of the INTERNAL define on the Mega because it's ambiguous. "

...

or you could just hack "#define INTERNAL 3" into the top of your code
</ugly>
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: enabling variable internal ref voltage on mega on: April 10, 2010, 11:57:18 pm
Quote
Thanks,
i have also use this in the 168 and 328, (the 1.1Volt i mean)
could you add this also in those?
Thanks
Pat Gadget
Montreal

1.1v is the only internal voltage reference on the 168/328. Nothing to add!
(I finally checked the 168 and 328 documentation. Setting bits 6 and 7 of ADMUX register [which is all the analogReference(...) does] to a value of 2 is "Reserved." In short, don't do it.)

The 1280 has either 2v56 or 1v1. The above modification simply makes a define that isn't present for the 1280.
4  Forum 2005-2010 (read only) / Bugs & Suggestions / enabling variable internal ref voltage on mega on: January 28, 2010, 02:32:36 pm
according to the atmega1280 specification, the internal reference voltage can be selected at either 1.1v or 2.56v. (not just 2.56v, as the wiki suggests)

The analogReference(uint8_t mode) function simply sets a variable that is (later) used by analogRead(uint8_t pin) to set bits 6 and 7 (REFS1:0) of the ADMUX register. (These details can be observed in .../arduino/hardware/cores/arduino/wiring_analog.c) The REFS1:0 bits determine the source of the reference voltage as follows:

REFS1REFS0Voltage reference selection
00AREF, internal Vref off
01AVCC
10Internal 1.1v Voltage reference
11Internal 2.56v Voltage reference

.../arduino/hardware/cores/arduino/wiring.h only makes the following defines:
#define INTERNAL 3
#define DEFAULT 1
#define EXTERNAL 0
as you can see - there is no definition for the internal 1.1vref.

Adding the following to wiring.h will allow you to select an internal 1.1v voltage reference:
#if defined(__AVR_ATmega1280__)
      #define INTERNAL_1V1  2
      #define INTERNAL_2V56 3  //added for completeness
#endif

selecting the analog reference is as simple as:
analogReference(INTERNAL_1V1);
or
analogReference(INTERNAL_2V56);

of course, INTERNAL_1V1 is just a macro... to use the internal 1.1v reference without modifying any of the arduino code, simply use the following:
analogReference(2)

I have tested this and can easily switch between an internal reference voltage of 1.1v or 2.56v. I hope this comes in handy!

I do NOT know how this will behave on other hardware - hence the '#if defined(__AVR_ATmega1280__)' - consult your hardware manual!

Happy Hacking!
Pages: [1]