View previous topic :: View next topic |
Author |
Message |
doncarlos
Joined: 28 Feb 2008 Posts: 29 Location: Szfv.
|
Posted: Fri Feb 27, 2015 6:38 pm Post subject: xMega bandgap voltage |
|
|
Hi!
I'd like to measure the battery voltage (using the bandgap voltage) powering my xMega128A1. I tried to search here, I also gone trough the help, but I can't understand how to config my ADC to achieve this . :S
Could somebody write the adc config and the actual command to read the battery voltage? For now I just like to print to the terminal.
Thanks for any help in advance!
Regards,
DC
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Feb 27, 2015 10:10 pm Post subject: |
|
|
according to the datasheet, you need to use : Ch0_inp = Internal
MUXPOS[3:0] Group Configuration Description
0000 TEMP Temperature Reference
0001 BANDGAP Bandgap voltage
0010 SCALEDVCC 1/10 scaled Vcc
0011 DAC DAC output
and :
MUXNEG[2:0]
111 INTGND Internal ground
thus :
var=getadc(adca,0,&B1111)
would get the bandgap voltage.
so put/merge this in the getadc sample from the help and it should work. _________________ Mark |
|
Back to top |
|
|
doncarlos
Joined: 28 Feb 2008 Posts: 29 Location: Szfv.
|
Posted: Fri Feb 27, 2015 10:51 pm Post subject: |
|
|
Hi Mark,
Thanks for the clarification, I was completely on the wrong side.
Now I can measure something with this code:
Code: |
$regfile = "xm128a1def.dat"
$crystal = 32000000 '32MHz
$hwstack = 512
$swstack = 512
$framesize = 512
$lib "xmega.lib"
$external _xmegafix_clear
$external _xmegafix_rol_r1014
Config Osc = Disabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
Config Priority = Static , Vector = Application , Lo = Enabled
Config Com1 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config Adca = Single , Resolution = 12bit , Ch0_gain = 1 , Ch0_inp = Internal , Mux0 = &B1111
Print "Start"
Dim Voltage As word
Voltage = Getadc(adca , 0 , &B1111)
Print Voltage
|
I read this thread:
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10082&highlight=battery+voltage
and there MAK3 describes how to calculate the VCC from the ADC reading.
If I'm not wrong, using the 12bit ADC resolution, my formula would be 1,1*4096/voltage.
I got the following values when I ran the code:
Code: |
1857
1857
1857
2081
1857
2048
|
And if I do the math with these readings, the battery voltage should be around 2.2 - 2.4 but if I measure with my DMM it says 3.9 volts. It is a single Li-Po cell.
What am I missing? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Feb 27, 2015 11:30 pm Post subject: |
|
|
you asked for measuring the internal bandgap voltage. But what you want is to read SCALEDVCC. So use &B10_111 instead of &B1111
You then read vcc/10. _________________ Mark |
|
Back to top |
|
|
|
|
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
|
|