Forum - MCS Electronics
 FAQ Search Register Log in

Author Message
dongags5

Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

 Posted: Tue Sep 16, 2014 9:12 am    Post subject: ADC Reference voltage I am unsure about the Reference voltage on the ATMEGA8535. I use an inductor and capacitor from the VCC to supply the AVCC ADC pin and just use a bypass cap on the AREF pin and of course the ADC ground pin is grounded. I use the following command Config Adc = Single , Prescaler = Auto , Reference = Avcc When I measure the voltage at the AREF pin I get the same voltage as I measure at the AVCC pin which is 5V which surprises me as I was expecting a reference voltage of 2.56V. Maybe what is measured at that pin is not the actual reference voltage? I have an LCD display and look at the output from Getadc(2) i.e. the channel I use to apply an external voltage to the ADC. Why is it that 255 (the maximum byte) is displayed when the DC input voltage is about 1.25V? I thought it would require an input voltage of twice that i.e. the same as the reference voltage (2.56V) or if the reference is 5V would be nearly twice that. I hope that someone can throw some clarity on this - thanks. Don (BASCOM-AVR version : 2.0.7.5. , Latest : 2.0.7.7 )
Paulvk

Joined: 28 Jul 2006
Posts: 1198
Location: SYDNEY

 Posted: Tue Sep 16, 2014 10:18 am    Post subject: Hello Don Config Adc = Single , Prescaler = Auto , Reference = Avcc <<<<<<< its working as expected you told it to use AVCC Try Config Adc = Single , Prescaler = Auto , Reference =INTERNAL_2.56 I do not have a 8535 to try Regards Paul
Visovian

Joined: 31 Oct 2007
Posts: 584
Location: Czech

Posted: Tue Sep 16, 2014 3:18 pm    Post subject:

 Quote: Why is it that 255 (the maximum byte) is displayed when the DC input voltage is about 1.25V?

It seems like you are reading adc into a byte variable.
Maximum adc value = 1023. You need word variable.

Try
 Code: dim adc_val as word adc_val = getadc(2) Lcd adc_val
dongags5

Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

 Posted: Wed Sep 17, 2014 1:07 pm    Post subject: Thanks Paul, I don't understand why there needs to be a s/w directive to have the AVcc reference when simply connecting the hardware AVcc to the reference pin would do the same thing if the chip only has the AVcc reference option. I tried the internal_2.56 directive and the compiler doesn't come up with an error. I got the impression that the ATMEGA8535 only accepts the Reference= AVcc command. I didn't measure the voltage at the reference pin when the _2.56 was specified but I suppose it would not be brought out and may not even be 2.56V - will check when I have time. Thanks Visovian, you are quite right but I don't need high accuracy so a byte variable is fine. cheers Don
Evert :-)

Joined: 18 Feb 2005
Posts: 2116

Posted: Wed Sep 17, 2014 8:55 pm    Post subject:

 Code: Config Adc = Single , Prescaler = Auto , Reference =INTERNAL_2.56

Is the correct way to 2.56V internally, the correct bits (REFS1 and REFS0) are set by Bascom. Tested in the simulator.

Are you using the correct regfile?
8535def.dat = for the AT90S8535
M8535.dat = for the Mega8535

_________________
www.evertdekker.com Bascom code vault
Arera

Joined: 23 Sep 2007
Posts: 375
Location: Wuppertal, Germany

 Posted: Thu Sep 18, 2014 2:19 pm    Post subject: Hi Don You must use a word for the adc. A byte would not reduce accuracy, but lead to completely false results.
dongags5

Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

 Posted: Fri Sep 19, 2014 8:25 am    Post subject: Thanks Evert, I am using the correct regfile M8535.dat In the Bascom help file, for the 8535 chip there seems to be only 2 modes: OFF and AVCC but as Paul suggested earlier I can use the internal reference of 2.56V. I measured 2.56V at the AREF pin confirming it to be correct. Thanks Arera, I restrict my maximum input level so that I can use the byte variable rather than word as the high byte is zero. (ADC Result Registers ADCL is only used). Results are as expected and with sufficient accuracy for the requirement. cheers Don
Arera

Joined: 23 Sep 2007
Posts: 375
Location: Wuppertal, Germany

 Posted: Fri Sep 19, 2014 8:30 am    Post subject: OK, you know what you are doing! I thought you expectet to decrease the ADC's resolution from 10 to 8 bit by using a Byte....
Deanus

Joined: 26 May 2006
Posts: 188
Location: Adelaide

Posted: Sat Sep 20, 2014 7:53 am    Post subject:

Hi dongags5,

With regards to the reference voltage, according to the data sheet,
You can choose the internal reference (2.56V) , OR the External reference VCC (Chip supply voltage) ,
But you CANNOT or should I say SHOULD NOT apply an external reference voltage and choose the internal reference via the switches.

This will have the effect of applying VCC chip supply voltage to the output of an opamp and will possibly destroy the internal reference opamp.
It explains it all in the Analogue reference section of the data sheet. Page 213 on my datasheet.

IF you supply an external Aref, then you MUST choose
 Quote: Reference = Avcc

If you choose the internal 2.56V reference, then
 Quote: Reference =INTERNAL_2.56
and Nothing connected to Vref PIN except maybe a capacitor .[/quote]

See attached is a snippet from the sheet.

As far as reading the data, the number you read is NOT a voltage, it is the number which represents the input voltage divided by the the maximum number of digital bits that the ADC is set up for.

EG: 10bit is 1024 steps
Reading the number from the ADC will result in 1024 for 5V (or what ever you micro supply voltage is) down to 0 ( Zero )with NO input voltage.
512 for 2.5 Volts input etc.

Read page 218 ADC Conversion Result, this gives you the formula for reading the voltage correctly.

It's up to to convert it to the correct voltage.

Also remember, DO NOT apply a voltage greater than you micro supply voltage to the analog input. Even though it's analogue input, it is still only 0 to 5V ( or what ever you micro supply voltage is.)

Regards

Dean
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum