Simple explanation of FVR ?

newplumber

Senior Member
Hi
I have read a lot of Allycats posts of reading power rail voltage from a M2 chip
and I guess I don't understand correctly the purpose of Fixed Voltage Ref from
1024...2048...4096

so if I have on my power supply rail close to the chip 5.00 volts then I use
FVR 4096 is that because of more accuracy? to the closest highest voltage?

thanks
mark
 

hippy

Technical Support
Staff member
READADC10 will return a number (Nadc) which reflects the input voltage applied (Vin), but it is affected by the voltage of the power supply (Vpsu) -

Nadc = Vin * 1023 / Vpsu

By reading a fixed voltage reference (Vref) one gets -

Nadc = Vref * 1023 / Vpsu

And by rearranging that one can determine what the Vpsu must be from knowing what Nadc you read and what Vref is -

Vpsu = Vref * 1023 / Nadc

By using a higher Vref the more accurate the result will be.

CALIBADC10 is effectively a READADC10 of the internal FVR.
 

AllyCat

Senior Member
Hi,

if I have on my power supply rail close to the chip 5.00 volts then I use FVR 4096
It depends on what you are trying to do. ;)

If you already have a regulated 5 volt supply rail, then in most cases it's best to use that, because it's probably more accurate than any of the FVRs. Or if you're using three AA cells (nominally 4.5 volts) then generally you shouldn't use FVR4096 because the batteries might droop below 4 volts.

The FVRs are primarily intended to use with the ADC and DAC modules in the chip, with generally FVR2048 the most useful. For example it gives 2 mV resolution with READADC10 instead of the normal 5 mV (with a 5 volt supply rail). FVR1024 can give 1 mV resolution but is "not recommended" by Microchip. Similarly, choose the FVR to suit the range/resolution of the DAC output required.

To measure the (unregulated) PICaxe supply rail, the "easy" method is to use CALIBADC10, which automatically measures FVR1024 relative to the supply rail. But it's a "back to front" method which "measures" the FVR1024 voltage (which is already known) relative to the (unknown) supply rail. Unfortunately, the back-to-front calculation requires mathematical division, which restricts its accuracy. The "best" resolution that a PICaxe can do is to divide a Word value of "nearly 65535" by a value "close to 255", to give a result "close to 255". Thus the "optimum" is with a 4.1 volt supply rail, with CALIBADC10 measuring a value of around 255.

I have posted a number of more "advanced" methods for measuring the supply rail, in the Code Snippets section, but these are mainly concerned with achieving higher resolution rather than absolute accuracy. Post a link to any of those "tricks", if they look relevant to a particular application.

Cheers, Alan.

PS: Strictly there is only one Fixed Voltage Reference (1.024 volts nominally). FVR2048 and FVR4096 are the outputs from an internal Op-Amp with gains of x2 and x4. But these introduce a small additional calibration error, so FVR1024 is the most "accurate".
 

newplumber

Senior Member
Well thanks alot hippy,Alan

I used your code Alan and it works awesome
Code:
; "ReadVdd" routine to measure the PICaxe suply rail to (almost) "1mV" resolution
; AllyCat February 2016

#picaxe 20m2                     ; Or any other M2
#no_data
#terminal 4800
DIRSC = %10111111
symbol CALVDD7 = 59919           ; "Fractional" multiplier to calibrate Vdd/FVR value,nominally 59919

DO

ReadVdd:
   fvrsetup fvr2048              ; Select the 2 volt reference (or can use FVR1024) 
   dacsetup $80                  ; Enable the DAC referenced to Vdd
   daclevel 10                   ; = Vdd * 10 / 32 so always should be less than FVR2048 if Vdd < 6v
   adcconfig 3                   ; Use the FVR as reference voltage for ADC and READDAC
   w2 = 0                        ; Initialise an accumulator 
   for b1 = 1 to 7               ; Read DAC 7 times
      readdac10 w1               ; NB: DAC (not ADC),but uses the ADC reference (FVR)  
      w2 = w2 + w1               ; Accumulate 7 values
   next b1
   w1 = w2 ** CALVDD7            ; Calibrate the value to mV units
   binTOASCII W1,b6,b7,b8,b9,b10
   IF b6 = "0" then : b6 = " " : endif


   sertxd(cr,lf,"POWER SUPPLY VOLTAGE = ",B6,B7,".",b8,b9,b10," VOLTS DC")
   pause 4000
LOOP
I was using a 1 farad super cap hooked to the supply rail and its cool to see the super capacitor gain voltage and
after it was maxed out I disconnected the power supply just using the S cap and calculated each time the
sertxd was read it would drop 3.7 mV
oh and I just changed the sertxd message a little but works awesome
 

AllyCat

Senior Member
Hi,

Ah yes, one of the Snippets from (post #3) of this thread. ;)

Yes, by using FVR4096 combined with multiple reads and "stepping" the DAC (to add some "noise" to the pot divider) it might be possible to get down to 0.1 mV resolution! :) But I'm not sure that would be very useful in practice and it can of course only work down to a supply of about 4.2 volts, when the reference voltage must drop out of regulation.

Cheers, Alan.
 

newplumber

Senior Member
well it is a awesome snippet and thanks for building it
I started out of full cap/with power supply reading 4.906
and it would quit sertxding at 2.084 volts so it was still above 2048
and sertxd 934 times X 4 = 3736 .../ 60 = 62.26
so I got 62 "FREE" minutes out of the super cap :)
with a average use per sertxd = 3.02 mv if my calculations are within reason
now I am going to change
fvrsetup fvr2048 ; Select the 2 volt reference (or can use FVR1024)
to
fvrsetup fvr1024 ; Select the 2 volt reference (or can use FVR1024)
and see if any difference is made

EDIT: sertxd is showing 6.547 volts ... I have to change something else probably or
it sure is one awesome super cap :)

EDIT #2: I switched
Code:
   fvrsetup fvr2048              ; Select the 2 volt reference (or can use FVR1024) 
   dacsetup $80                  ; Enable the DAC referenced to Vdd
   daclevel 10                   ; = Vdd * 10 / 32 so always should be less than FVR2048 if Vdd < 6v
   adcconfig 3                   ; Use the FVR as reference voltage for ADC and READDAC
to this

Code:
   fvrsetup fvr1024              ; Select the 2 volt reference (or can use FVR1024) 
   dacsetup $80                  ; Enable the DAC referenced to Vdd
   daclevel 5                   ; = Vdd * 10 / 32 so always should be less than FVR2048 if Vdd < 6v
   adcconfig 3                   ; Use the FVR as reference voltage for ADC and READDAC
and it is showing right on the money(almost exactly) next to my volt meter as the cap is ran down
 
Last edited:

AllyCat

Senior Member
Hi,

... it would quit sertxding at 2.084 volts ...
Your PICaxe probably continues to transmit down below 2 volts, but the serial interface voltage level is too low for the terminal to detect it. Therefore, I devised a simple buffer/amplifier which is documented here .

However, it appears that the DAC and FVR1024 don't work well together at these low voltages, but I don't recall the exact details now. So you might find that the only code that gives reliable results below the FVR2048 dropout level is the traditional CALIBADC10 method. :(

Cheers, Alan.
 

newplumber

Senior Member
However, it appears that the DAC and FVR1024 don't work well together at these low voltages
Yes it looks that way in my tests ...my meter was showing exactly the same as sertxd from cap being full charged till about 2.500 vdc
I was impressed at how accurate the voltage was reading down to 2.5 and also how long the little super cap can last (5.5v 1F)
Your PICaxe probably continues to transmit down below 2 volts
I never did experiment on how the picaxe handles low voltages but after my tests ..I'm sure it was still transmitting
seems like the picaxe chip is just as stubborn as the late payment credit card call reminder dept.
 
Top