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

Data Logger
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
djsb



Joined: 29 Jan 2011
Posts: 44

View user's profile Send private message

PostPosted: Sat Feb 15, 2025 4:57 am     Reply with quote

In more detail but not CCS C

FVR setup

Code:

FVRCON=0;
FVRCONbits.ADFVR=2; // ADC FVR=2.048V
FVRCONbits.FVREN=1; // Enable FVR
while (!FVRCONbits.FVRRDY); // wait untio FVR is ready and voltage is stable


ADC setup
Code:

ADCCON1=0;
ADCCON2=0;
ADCCON1bits.ADFM=1; // result is in bits 9...0
/* see the data sheet description:
1 = Right justified. Six Most Significant bits of ADRESH are set to ‘0’ when the conversion result is loaded.
0 = Left justified. Six Least Significant bits of ADRESL are set to ‘0’ when the conversion result is loaded.
*/
ADCCON1bits.AFNREF=0; //VREF- is GND
ADCCON1bits.AFPREF=3; //VREF+ connected to FVR module (2.048V)
//... here further ADC initialisations ...
ADCCON0bits.ADCON=1; //enable ADC


Reading the ADC result in mV

Code:

uint16_t adcres=(ADCRESH<<8)|ADCRESL; // ADC Counts
adcres<<=1; // now you have mV units

int16_t temp=(int16_t)adcres;
temp-=500; // offset 500mV for 0°C
// now you have units of 0.1°C
temp/=10; // now you have °C


Can any of these code fragments be converted to CCS C code? I will study it in more detail and have a go myself in due course. But any assistance would be appreciated. Thanks.
temtronic



Joined: 01 Jul 2010
Posts: 9425
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 15, 2025 8:16 am     Reply with quote

yes,
have a look at the 'header' for your PIC type, to see what options are available for you...
look in the CCS C manual....of course
look at some of the examples in the 'examples' subfolder wherever the OS put it.
look in the 'code library' here for how others do 'stuff'
Ttelmah



Joined: 11 Mar 2010
Posts: 19730

View user's profile Send private message

PostPosted: Mon Feb 17, 2025 3:17 am     Reply with quote

One key thing here is that the settings do depend on the chip involved.

This is why Jay says to refer to the header file for this.

A lot of PIC's can't actually run the ADC off the 2.048v reference. Most
older 5v chips need a minimum of 2.5v for the ADC. The 2.048 is available
for use as an output, but when being used to feed the ADC the 4.096v
setting has to be used. So a big 'caveat', which requires reading the
data sheet for the chip.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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