Page 1 of 1

Internal VREF in 18F25K22

Posted: Fri Mar 22, 2013 2:51 am
by jethronull
I read a couple of posts where people enquired about using the internal vrefs of various PICs and it seemed that it just needs a register appropriately set to take over from the standard ADC macro which is limited to VDD and the external VREF+. I could not find any reference to my PIC (18F25K22) on these forums, so I dug in the datasheet and decided that two registers were affected. I put in what seems like the correct values for 2.048V ref and internal ref enabling:

Code: Select all

vrefcon0 = 11100000;
adcon1 = 00001000;
. On running though it seems Flowcode is still using the VDD or VREF+ options in the ADC macro config. What am I missing here?

Re: Internal VREF in 18F25K22

Posted: Fri Mar 22, 2013 10:58 am
by Benj
Hello,

That looks like it should work fine as long as you have the VREF option set to VDD in the ADC component properties. One problem is that you are not entering the data in binary mode eg 0b00100110. I have changed the values below to hex so these should also work fine.

Code: Select all

vrefcon0 = 0xE0;
adcon1 = 0x08;
You may have to do code like this to get the Vref to stabilise correctly.

Code: Select all

vrefcon0 = 0xA0;
while ((vrefcon0 & 0x40) == 0);
adcon1 = 0x08;

Re: Internal VREF in 18F25K22

Posted: Sat Mar 23, 2013 12:16 am
by jethronull
Ben,

Perfect, that worked a treat. Duh me. binary without 0b!. But I wouldn't have known to do the while bit for settling.

Thanks a lot.