Bremen, Germany
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« on: March 13, 2006, 04:02:23 pm » |
Hej, i´m trying to figure out how the aref pin can be used. this is what i know so far: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1139161553/3#3massimo says: "switching reference voltage requires adding a few lines of C code to your arduino code." i wonder what these lines of code might be, is the whole aref thing documented in some place?
|
|
|
|
« Last Edit: March 13, 2006, 04:02:47 pm by kr1 »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
|
 |
« Reply #1 on: March 03, 2007, 08:52:51 pm » |
Did you ever figure out how to use the AREF pin? I am trying to change it from 5V to 3V but have not been able to find any reference information on how to do this.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
 |
« Reply #2 on: March 03, 2007, 09:44:01 pm » |
Hi the really technical answer to this is in the Atmega datasheet, pages 205-206. If you look through the associated Arduino C files, you wil probably find the statement that configures the Atemga8 for an internal reference... then you can change it however you like. Look for "ADMUX" in the C code. The software side of things is really not my strong point, but looking in wiring.c I see the following lines, which seem to match what is stated in the manual. // set a2d reference to AVCC (5 volts) cbi(ADMUX, REFS1); sbi(ADMUX, REFS0);
and here is the manual-- look at the last part, table 74. ADC Multiplexer Selection Register – ADMUX ADC Multiplexer Selection
Bit 7 6 5 4 3 2 1 0 REFS1 REFS0 ADLAR – MUX3 MUX2 MUX1 MUX0 ADMUX Read/Write R/W R/W R/W R R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0
Bit 7:6 – REFS1:0: Reference Selection Bits These bits select the voltage reference for the ADC, as shown in Table 74. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSRA is set). The internal voltage reference options may not be used if an external reference voltage is being applied to the AREF pin.
Table 74. Voltage Reference Selections for ADC REFS1 REFS0 Voltage Reference Selection 0 0 AREF, Internal Vref turned off 0 1 AVCC with external capacitor at AREF pin 1 0 Reserved 1 1 Internal 2.56V Voltage Reference with external capacitor at AREF pin
|
|
|
|
« Last Edit: March 03, 2007, 09:49:05 pm by Daniel »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
|
 |
« Reply #3 on: March 03, 2007, 10:21:20 pm » |
Thank you Daniel. It looks like in order to connect 3V to the AREF pin I should change the code to: cbi(ADMUX, REFS1); //clear REFS1 bit (0) cbi(ADMUX, REFS0); //clear REFS0 bit (0)
Edit: I just changed lines 607 & 608 to the code above in arduino-0007\lib\targets\arduino\wiring.c and it worked! Now I can set the ADC reference voltage from my external supply of 3V instead of using 5V. Thanks again Daniel!
|
|
|
|
« Last Edit: March 04, 2007, 01:47:50 am by vorb »
|
Logged
|
|
|
|
|
|
|
 |
« Reply #4 on: March 04, 2007, 03:52:55 am » |
no sweat!
if you have time it is always good to put what you figured out into a small wiki page in the 'playground'. This means that later down the line people will be able to benefit form your discoveries.
D
|
|
|
|
« Last Edit: March 04, 2007, 03:53:06 am by Daniel »
|
Logged
|
|
|
|
|
Forum Administrator
Cambridge, MA
Offline
Faraday Member
Karma: 7
Posts: 3532
|
 |
« Reply #5 on: March 04, 2007, 04:09:57 am » |
vorb: in case you'd rather not mess your wiring.c file, you should be able to put those lines in your setup() function and get the same effect. It might make it easier to share your code or upgrade to future Arduino versions.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
|
 |
« Reply #6 on: March 04, 2007, 05:53:08 am » |
vorb: in case you'd rather not mess your wiring.c file, you should be able to put those lines in your setup() function and get the same effect. It might make it easier to share your code or upgrade to future Arduino versions. I just tried that and I got the following error: 'cbi' was not declared in this scope In function 'void loop()'. So I guess I need to add the definitions for cbi and sbi from the beginning of wiring.c to my code? -Edit- I added the following definitions and it WORKS! 8-) : #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif #ifndef sbi #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif Thanks Mellis! I will take pictures and put my code in the playground once I figure out how to convert my adc values into "g" values. If you guys could take a look at my thread in the programs forum I would appreciate it. I'm stuck trying to deal with the fractional calculations I need to do.
|
|
|
|
« Last Edit: March 04, 2007, 06:07:29 am by vorb »
|
Logged
|
|
|
|
|
Netherlands
Offline
Sr. Member
Karma: 0
Posts: 414
|
 |
« Reply #7 on: November 05, 2007, 03:57:42 am » |
Sorry for digging up a rather old thread, but if I add the code mentioned above in my Sketch, AREF can be used as a 3V supply, instead of the normal 5V? It's not completely clear to me :  And if I burn a different Sketch, without the code above, it will automatically be back to 5V? Edit: Don't have a multi-meter here, so that is why I ask...
|
|
|
|
« Last Edit: November 05, 2007, 08:10:53 am by jds »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 37
Arduino rocks
|
 |
« Reply #8 on: December 08, 2007, 03:02:39 pm » |
is it possible to use a aref, that is higher than 5V? for example 7V?
|
|
|
|
|
Logged
|
|
|
|
|
Greenwood, Indiana
Offline
God Member
Karma: 0
Posts: 508
Arduino rocks
|
 |
« Reply #9 on: December 20, 2007, 04:46:56 am » |
No, max is VCC http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdfIf you want higher use an opamp. is it possible to use a aref, that is higher than 5V? for example 7V?
|
|
|
|
|
Logged
|
If it was designed by man it can be repaired by man.
|
|
|
|
0
Offline
Faraday Member
Karma: 6
Posts: 2504
|
 |
« Reply #10 on: December 20, 2007, 12:23:33 pm » |
If you want higher use an opamp. or a voltage divider (two resistors). -j
|
|
|
|
|
Logged
|
|
|
|
|
pittsburgh, pa
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #11 on: January 16, 2008, 02:36:32 pm » |
Looking at the schematic for the MINI 03, it appears that the AREF pin is unavailable. Is this correct? (Should I be asking in the MINI section?)
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 21
Mr. Watson. Come Here. I need you.
|
 |
« Reply #12 on: January 23, 2008, 07:21:56 am » |
If you want higher use an opamp. or a voltage divider (two resistors). -j According to Wikipedia : Any ratio between 0 and 1 is possible. That is, using resistors alone it is not possible to either reverse the voltage or increase Vout above Vin http://en.wikipedia.org/wiki/Voltage_dividerSo how would a two resistor voltage divider increase the output voltage above the voltage at AREF? I don't get it.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Faraday Member
Karma: 6
Posts: 2504
|
 |
« Reply #13 on: January 23, 2008, 08:14:14 am » |
The voltage divider circuit isn't to increase anything at AREF, it is to reduce the voltage.
For example, I hook up two resistors GND - 5k - 5k - +5V, and connect AREF to the point between the two resistors - presto, a 2.5V voltage reference.
If you are going the other direction, e.g. measuring the voltage of your car's electrical system (which is about 14.4V while the engine is running) you can put the voltage divider on the input side. GND - 5k - 15k - Vin, and connect the analog input pin between the two resistors, and you'll be measuring 1/4 of Vin. Don't forget to scale values accordingly when doing calculations based on the analog input.
-j
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 21
Mr. Watson. Come Here. I need you.
|
 |
« Reply #14 on: January 23, 2008, 08:24:54 am » |
Aha! thank you. I got lost in the Wikipedia description!
Your explanation is clear and precise.
Phil
|
|
|
|
|
Logged
|
|
|
|
|
|