Using FVR on a adc channel

For general Flowcode discussion that does not belong in the other sections.
medelec35
Valued Contributor
Posts: 2308
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 717 times
Been thanked: 777 times

Re: Using FVR on a adc channel

Post by medelec35 »

Hi Bob.
I have looked into enabling FVR for the 16F1829.
1. Within potentiometer properties make sure VRef option is set set to FVR (which you have)
2. Determine the correct value of FVRCON
For FVR the datasheet states

Code: Select all

01 = ADC Fixed Voltage Reference Peripheral output is 1x (1.024V)
10 = ADC Fixed Voltage Reference Peripheral output is 2x (2.048V
11 = ADC Fixed Voltage Reference Peripheral output is 4x (4.096V)
These are bits 1 and 0 respectively.

Bit 7 needs to be a 1 as that is Fixed Voltage Reference Enable bit, therefore for decimal that is decimal 128 = hex 0x80

If you want FVR of 2.048 then you need

Code: Select all

 128 + 2 = 82
(the 2 is the decimal of 0b10) or in hex

Code: Select all

0x80 + 2 = 0x82
Therefore just above the main loop, add a C code block with

Code: Select all

FVRCON = 0x82;
Martin

medelec35
Valued Contributor
Posts: 2308
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 717 times
Been thanked: 777 times

Re: Using FVR on a adc channel

Post by medelec35 »

Just found my 16F1824, which using the same datasheet as 16F1829.
Set FVR to 2.048V , following my instructions
Applied a 1.024V to ADC pin and the ADC result is 501 which is not far off at all!
Martin

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

Re: Using FVR on a adc channel

Post by siliconchip »

Hi martin (medelec35)
not sure ive wrote the code correctly but with what i have done my 150R resistor now reads 145.2R which was better than the 208R i was getting, could you confirm my code and pot properties are correct please

cheers bob
Attachments
FVRtrial.fcfx
(19 KiB) Downloaded 57 times

medelec35
Valued Contributor
Posts: 2308
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 717 times
Been thanked: 777 times

Re: Using FVR on a adc channel

Post by medelec35 »

Hi Bob.
That is a lot better 3.2% instead of 39.2% that has improved by a factor of 10!
Is the voltage across the supply pins of the microcontroller exactly 5100.0 mV?
I used that in an example but if your chip supply is different you need to replace the 5100.0 with your exact VDD voltage.

To make lower values even more accurate when using a higher pull up value you could do what Ben was suggesting.
You could read the ADC voltage and dynamically set the FVR to one of the values of 1.024V,
2.048V or 4.096V depending on voltage read.
At least you now know the values to use.

Another suggest for increased accuracy is to go back to the ratiometric calculations that use same voltage for VRef as VDD, but use a microcontroller or external ADC that has a higher ADC resolution.
You can get 12bits plus with new devices.
Martin

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

Re: Using FVR on a adc channel

Post by siliconchip »

hi martin
thanks for the reply, ive noticed that by using 4.096 i can measure roughly up to 1150 ohms but after this accuracy is out the window so by lowering the fvr i notice i get better accuracy going down resistor size so my original resistance checker not using fvr was way more accurate in comparison, i understand what you say regards using the ratiometric calcs but id like to use this chip so im wondering if i should stick with my original program and try to factor in the slight inaccuracy with software, i honestly thought using the fvr would be the answer but its proving troublesome, if you get time could you check the program i posted previously just in case ive made a slight mistake with variables etc

cheers bob

medelec35
Valued Contributor
Posts: 2308
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 717 times
Been thanked: 777 times

Re: Using FVR on a adc channel

Post by medelec35 »

Formula looks correct.
For a wider range the first ratiometric formula I gave would be best, but less accurate with a 10bit ADC.
There is not else that can be done.
Using

Code: Select all

 R = PullUpResistor * FLOAT read / (1023.0 - FLOAT read)
can you let me know what the value of read is (sending it to your display) with your 150R test resistor.
Like I said earlier you can test the maths by adding a calculation icon with

Code: Select all

read = 320
just after ADC component
Then the R shown should be

Code: Select all

121.5 
on both simulation and hardware.
Martin

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

Re: Using FVR on a adc channel

Post by siliconchip »

hi martin
as suggested i put a calculation box after the pot icon with read = 320 my display shows 91.97R my supply is a steady 5v

cheers bob

medelec35
Valued Contributor
Posts: 2308
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 717 times
Been thanked: 777 times

Re: Using FVR on a adc channel

Post by medelec35 »

Hi Bob.
Have you changed the PullupResistor value ?
With it being 267, it's working on my hardware and simulation.
This is the embedded UART results:
Hardware results Read 320.png
Hardware results Read 320.png (8.63 KiB) Viewed 543 times
Calculation:
read 320 calculations.png
read 320 calculations.png (10.85 KiB) Viewed 543 times
Simulation results:
read 320 simulation results.png
read 320 simulation results.png (15.68 KiB) Viewed 543 times
As you can see they all match.

They are the results you should be getting.

If not I will take another look at your latest fcfx project file.
Martin

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

Re: Using FVR on a adc channel

Post by siliconchip »

Hi martin
As always thanks for the reply i have been playing with resistor values so possibly i may have the wrong one fitted im away for a week but once back i will check and get back to you sorry for the delay and i appreciate the help i will check in when i get back

Cheers bob

medelec35
Valued Contributor
Posts: 2308
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 717 times
Been thanked: 777 times

Re: Using FVR on a adc channel

Post by medelec35 »

Hi Bob, not a problem.
I just fitted a 270R pullup and 150R Test resistor on my hardware, to try and replicate your setup.
This is the result at 4.5V VDD
R test1.png
R test1.png (4.54 KiB) Viewed 449 times
The actual resistance of the test resistor is 150.6R
The R result is 149.1
Therefore the accuracy is 1.0%
Not bad at all for a 10bit ADC
More accurate than I had thought it would be.

I even varied the VDD value between 3.96 and 5.2V and the test resistance shown on UART remained constant, so the calations are defiantly ratiometric and correct!

I don't recommend using a pull-up with a low value, especially if you have a low value test resistor because of self heating
That needs to be taken into account.
It looks like you have a hardware issue for your % to be out by as much as it is.
Martin

Post Reply