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

Using 0.6V and 1.2V internal Vref on PIC12F615

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



Joined: 19 Jan 2010
Posts: 7

View user's profile Send private message

Using 0.6V and 1.2V internal Vref on PIC12F615
PostPosted: Tue Jan 19, 2010 8:53 am     Reply with quote

I am using PCM 4.093.

I want to enable and then sample the internal reference on the 12F615 before sampling a pin with a sensor connected to it.

The H file only gives an option to enable the 0.6V reference:

#define VREF_6th 0x10 // Turn on .6V ref

The 1.2V reference stated in the datasheet is not mentioned anywhere in the H file.

It is also not clear how I can point the ADC to read an internal VREF as there is no sAN channel number associated with either in the H file.

I have tried setting the CHS bits in the ADCON directly as follows but still get no value for the VREF chosen (ADC reads 0):
Code:

#byte O_SIX_VREF = 0x14   //0.6V ref
byte data;

void ADCONVREF(){
   setup_vref(VREF_6th);            //Enable internal 0.6V VREF   
   setup_ADC(ADC_CLOCK_INTERNAL);   //Use internal ADC clock   
   SETUP_ADC_PORTS( sAN3 | VSS_VDD);//Set AN3 (GP4) to analogue and use VDD as reference
   data = ADCON && !O_SIX_VREF;      //clear CHS bits in #byte variable data
   ADCON = data || O_SIX_VREF;      //set CHS bits ADCON for required VREF to select VREF channel
   delay_us(10);
   }

Any ideas?
Ttelmah
Guest







PostPosted: Tue Jan 19, 2010 3:22 pm     Reply with quote

First, setup_vref, controls the Vref setting to the comparator. The comparator doesn't support the 1.2v reference, hence no constant for this.
Don't use this.

On the ADC, the Vref is available as another input. The channel configuration constants supplied, don't offer this, and are completely wrong (SAN0, for example, actually requires '0' put into the CS bits, the supplied constants, put in '1'.....).
Simply use the following constants and setup:
Code:

#define sAN0                   0         //| GP0
#define sAN1                   1         //| GP1
#define sAN2                   2         //| GP2
#define sAN3                   3         //| GP4
#define CVREF                 4
#define VREF06                5
#define VREF12                6

    setup_ADC(ADC_CLOCK_INTERNAL); 
    SETUP_ADC_PORTS(VSS_VDD);

    set_adc_channel(VREF06);


This chip doesn't have separate 'selection', and 'setup', you just set the channel you want to read, and provided it is set as an input, it is connected to the multiplexer.

Best Wishes
Beenabout



Joined: 19 Jan 2010
Posts: 7

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 4:05 am     Reply with quote

Many thanks for that reply - its all a little clearer now. It makes sense when read looking at the ADC diagram in the datasheet depicting the CHS channels as a block.

Only problem is that although selecting channel 6 as indicated I do get a value corresponding to 1.19V (1.2Vref), selecting channel 5 results in a value of zero returned. But I can make do with just the 1.2V reference.

I take it that both references (the 0.6V ref is presumably the 1.2V ref divided by two mosfet resistors) are always on and that there is no way of turning them off to save power? My application is low power.
Ttelmah
Guest







PostPosted: Wed Jan 20, 2010 6:23 am     Reply with quote

Look for the FVREN enable bit. Figure 9.6.
I don't know which CCS code controls this, I'd suggest just defining it as a #bit, and turning it on/off as needed.
Note also the oscillator selection effect on the ADC Vref connection. hence when you select the low speed oscillator, or sleep, the VREF always goes off... Smile

Best Wishes
Beenabout



Joined: 19 Jan 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 4:32 am     Reply with quote

Thanks again!
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