View previous topic :: View next topic |
Author |
Message |
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
How to use Vbg (bandgap) - SOLVED |
Posted: Tue Jan 19, 2016 2:39 pm |
|
|
Hi, i use 18f47j53
How can i use Vbg as reference voltage?
If i understand well, i should read channel 15 (1111) and use this manualy as reference, knowing that it is 1,2v .
Is that right?
Probably not because when i change power supply voltage, i have different readings(big variations, ).
So how should i use it?
Also how can i write on a register like ADCON1 ?
I need to enable bit 7 of ADCON1 to enable Vbg.
Last edited by nuclear__ on Wed Jan 20, 2016 3:26 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Jan 19, 2016 3:13 pm |
|
|
Quote: |
Probably not because when i change power supply voltage, i have different readings(big variations, ).
|
You will. That is the whole point.
You read the Vbg value, and can then calculate the supply.
So if (say) you used the ADC with Vss-Vdd, and read 318, then you can calculate that the supply voltage is:
(1.024/318)*1024 = 3.29v
Change the supply to 4v, and you will instead read 262.
You can write to a register directly, but the compiler does this for you. Safer to use the compiler functions, especially if you get things wrong (bit 7 of ADCON1 controls whether the result is left or right justified, not Vbg....).
It's ANCON1 that enables the Vbg....
Code: |
#BIT VBGEN=getenv("BIT:VBGEN")
VBGEN=TRUE; //enable the bandgap
|
|
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Tue Jan 19, 2016 4:18 pm |
|
|
Saying big variations i meant after doing your calculations.
Actually i use vcore this way and it works, but i want a lower ref. voltage than 2.5V since its near my power supply's output under some circumstances (low battery).
I hadn't use VBGEN=TRUE; at all so my readings could be random.
Thanks for this. Are these written somewhere? (like vbgen definition) since my half questions are about setting up registers. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Jan 20, 2016 2:02 am |
|
|
In the data sheet!....
Every bit named in the data sheet, can be accessed this way.
However also if you have the IDE. Select 'tools', 'device editor', choose your PIC, and then at the top of the page 'registers'. This then gives a table with all the register names, and bit names shown.
Normally I'd say use the setup_vref option, which can set bits like this for you, but in this case I actually think it is easier just to set the single bit yourself. |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Wed Jan 20, 2016 3:26 am |
|
|
Thanks! |
|
|
|