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.
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
Posted: Mon Feb 17, 2025 3:17 am
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.
All times are GMT - 6 Hours Goto page Previous1, 2
Page 2 of 2
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