Using FVR on a adc channel

For general Flowcode discussion that does not belong in the other sections.
siliconchip
Posts: 23
http://meble-kuchenne.info.pl
Joined: Wed Dec 16, 2020 10:38 am
Has thanked: 8 times
Been thanked: 1 time

Using FVR on a adc channel

Post 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
Attachments
FVRtrial.fcfx
(18.78 KiB) Downloaded 81 times

BenR
Matrix Staff
Posts: 2228
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 615 times
Been thanked: 807 times

Re: Using FVR on a adc channel

Post 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

siliconchip
Posts: 23
Joined: Wed Dec 16, 2020 10:38 am
Has thanked: 8 times
Been thanked: 1 time

Re: Using FVR on a adc channel

Post 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
Attachments
FVRtrial.fcfx
(18.86 KiB) Downloaded 21 times

BenR
Matrix Staff
Posts: 2228
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 615 times
Been thanked: 807 times

Re: Using FVR on a adc channel

Post by BenR »

How's this. I've just reworked your formula a bit and assumed the potential divider is driven from 5V.

FVRtrial.fcfx
(17.03 KiB) Downloaded 20 times
You could potentially drive the potential divider from the DAC which can also work with the FVR if that would help.

BenR
Matrix Staff
Posts: 2228
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 615 times
Been thanked: 807 times

Re: Using FVR on a adc channel

Post by BenR »

This one is maybe slightly more accurate as the FVR voltage is defined more precisely.

FVRtrial.fcfx
(17.4 KiB) Downloaded 20 times

BenR
Matrix Staff
Posts: 2228
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 615 times
Been thanked: 807 times

Re: Using FVR on a adc channel

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

BenR
Matrix Staff
Posts: 2228
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 615 times
Been thanked: 807 times

Re: Using FVR on a adc channel

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

FVRtrial_autoscale.fcfx
(21.92 KiB) Downloaded 22 times

siliconchip
Posts: 23
Joined: Wed Dec 16, 2020 10:38 am
Has thanked: 8 times
Been thanked: 1 time

Re: Using FVR on a adc channel

Post 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

mnfisher
Valued Contributor
Posts: 2041
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 160 times
Been thanked: 950 times

Re: Using FVR on a adc channel

Post 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

siliconchip
Posts: 23
Joined: Wed Dec 16, 2020 10:38 am
Has thanked: 8 times
Been thanked: 1 time

Re: Using FVR on a adc channel

Post by siliconchip »

Hi martin
Cheers i look forward to your results

Bob

Post Reply