Page 1 of 2
Using FVR on a adc channel
Posted: Fri Jun 12, 2026 12:23 pm
by siliconchip
hi all
i recently made a device to read resistance ( with help from the forums) which worked really well, however ive tried to adapt part of that software to use the chips fixed voltage reference on the input channel hoping to improve accuracy, although accuracy was pretty good but to also get to understand using the FVR as well, with my original project i had a voltage divider with a 0.1% resistor (267 ohms as i wanted to read small resistances) tied to vcc and the adc input and the resistor under test tied to ground, using the settings on the input for the adc i wanted 4.096v therefore i used vref voltage as 409, vref option as FVR and conversion frc but when trying in hardware to measure a 150R resistor i get 208.8R if i change vref voltage to 500 vref option to VDD i get 150R ive set fvrcon as per data sheet so could anyone poit me in the right direction if need to set any other register or connect my divider differently, thanks in advance
bob
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 11:00 am
by BenR
Hi Bob,
The FVR is fairly simple on the PIC1829 device.
Using a C icon you can set it up with a C icon and block of code like this.
Code: Select all
FVRCONbits.FVREN = 0; //Disable FVR to set it up
FVRCONbits.ADFVR = 3; //Set FVR voltage
FVRCONbits.FVREN = 1; //Enable FVR
while (FVRCONbits.FVRRDY == 0); //Wait for FVR to be ready
For the voltage values you can use 1-3 where 1=1.024V, 2=2.048V, 3=4.096V
If you wantesd to put the code into a macro with a byte parameter named Voltage to set the voltage then the code would look like this.
Code: Select all
FVRCONbits.FVREN = 0; //Disable FVR to set it up
FVRCONbits.ADFVR = FCL_VOLTAGE; //Set FVR voltage
FVRCONbits.FVREN = 1; //Enable FVR
while (FVRCONbits.FVRRDY == 0); //Wait for FVR to be ready
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 1:50 pm
by siliconchip
Hi ben
Thanks for the reply what settings would i need to put for the pot in my program when you click properties also how would i connect my voltage divider on the adc input would i tie this to 5v supply as usual ?
UPDATE
i have entered the 1st c code box but my readings are still out measuring a 150R resistor im still getting 208.8R surely this is down to my hardware connection ( ie voltage divider ) or is my original calulations the issue i have attched my code
Cheers bob
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 4:59 pm
by BenR
How's this. I've just reworked your formula a bit and assumed the potential divider is driven from 5V.
You could potentially drive the potential divider from the DAC which can also work with the FVR if that would help.
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 5:03 pm
by BenR
This one is maybe slightly more accurate as the FVR voltage is defined more precisely.
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 5:10 pm
by BenR
Ideally you want to drive the potential divider from 5V and then adjust the ADC settings and FVR based on the resistance.
For low values of resistor you want to use VCC as the reference. Then as the resistance gets higher and higher the voltage across R2 will drop and so switching to FVR and if need be lowering FVR will give you much better precision on high resistances.
If you like I can try and help with this so it auto calibrates the range.
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 5:18 pm
by BenR
This might do it
I have two ADC components, one using VCC and another using FVR.
I read the VCC ADC and use that to get the ball park voltage. If it's more suited to an FVR range then I switch to the best option.
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 5:56 pm
by siliconchip
hi ben
mega thanks for the reply, i have tried all 3 programs but again when measuring the 150R resistor the value is 475R, im using 267R from vcc to the input adc and 150R from the adc input to ground
cheers bob
Re: Using FVR on a adc channel
Posted: Mon Jun 15, 2026 11:02 pm
by mnfisher
Hi Bob,
Silly question - but have you just tried reading a voltage using the FVR settings? Would be a good test that things are actually working - and then handle the voltage divider resistors when the ADC is working correctly?
I've wired up a 16f18877 which seems to support this using identical code - so will try a few readings and see if I can get any sense
Martin
Re: Using FVR on a adc channel
Posted: Tue Jun 16, 2026 12:49 am
by siliconchip
Hi martin
Cheers i look forward to your results
Bob