Page 1 of 1

18F46K22 FVR ADC Issue

Posted: Wed Dec 14, 2011 4:51 pm
by jbaldi
I have been trying to turn on and use FVR (@ 4.096V) on a 18F46K22 using some suggestions for other devices in other posts on this forum but not having any luck. I have code compiled with the CCS compiler that is getting a value of 1023 on AN0 and I'm trying to get the same results in Flowcode but the value is 768. I tried customizing the SampleADC component macro using the following code but the results did not change.

Code: Select all

	//Assign FVR functionality
	st_bit(adcon1, VCFG1);
	clear_bit(adcon1, VCFG0);

	//turn on FVR and set to 4.096V
	vrefcon0 = 0xF0;

Re: 18F46K22 FVR ADC Issue

Posted: Wed Dec 14, 2011 6:31 pm
by Benj
Hello,

Maybe try taking the vrefcon0 line of C code out of the ADC sample macro and instead insert it using a C code icon at the start of your program.

Code: Select all

//turn on FVR and set to 4.096V
vrefcon0 = 0xB0;
while ((vrefcon0 & 0x40) == 0);
The other two lines of C code can remain in the sample function but maybe just make sure that they are after any code that might overwrite the setting but before the start of the charge and sample process.

Re: 18F46K22 FVR ADC Issue

Posted: Tue Dec 20, 2011 11:23 pm
by jbaldi
I'm still getting the same result = 768 = 1100000000b. Could it be that ASRESL or ADRESH isn't getting set properly depending on what the ADFM bit is set to?