CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to use Vbg (bandgap) - SOLVED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

How to use Vbg (bandgap) - SOLVED
PostPosted: Tue Jan 19, 2016 2:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 19, 2016 3:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 19, 2016 4:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 20, 2016 2:02 am     Reply with quote

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. Smile
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Wed Jan 20, 2016 3:26 am     Reply with quote

Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group