18F46K22 FVR ADC Issue

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
jbaldi
Posts: 4
Joined: Tue Aug 16, 2011 9:28 pm

18F46K22 FVR ADC Issue

Post 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;

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 18F46K22 FVR ADC Issue

Post 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.

jbaldi
Posts: 4
Joined: Tue Aug 16, 2011 9:28 pm

Re: 18F46K22 FVR ADC Issue

Post 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?

Post Reply