Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC Reference voltage

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
dongags5

Bascom Member



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

australia.gif
PostPosted: Tue Sep 16, 2014 9:12 am    Post subject: ADC Reference voltage Reply with quote

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 )
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Sep 16, 2014 10:18 am    Post subject: Reply with quote

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
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Tue Sep 16, 2014 3:18 pm    Post subject: Reply with quote

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
 
Back to top
View user's profile
dongags5

Bascom Member



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

australia.gif
PostPosted: Wed Sep 17, 2014 1:07 pm    Post subject: Reply with quote

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
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2165

netherlands.gif
PostPosted: Wed Sep 17, 2014 8:55 pm    Post subject: Reply with quote

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
Back to top
View user's profile Visit poster's website
Arera

Bascom Member



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

germany.gif
PostPosted: Thu Sep 18, 2014 2:19 pm    Post subject: Reply with quote

Hi Don
You must use a word for the adc. A byte would not reduce accuracy, but lead to completely false results.
Back to top
View user's profile
dongags5

Bascom Member



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

australia.gif
PostPosted: Fri Sep 19, 2014 8:25 am    Post subject: Reply with quote

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
Smile
Back to top
View user's profile
Arera

Bascom Member



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

germany.gif
PostPosted: Fri Sep 19, 2014 8:30 am    Post subject: Reply with quote

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....
Back to top
View user's profile
Deanus

Bascom Member



Joined: 26 May 2006
Posts: 188
Location: Adelaide

australia.gif
PostPosted: Sat Sep 20, 2014 7:53 am    Post subject: Reply with quote

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
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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