• AVR Freaks

Hot!Measuring / Calculating battery power supply with FVR

Author
tubos
Starting Member
  • Total Posts : 77
  • Reward points : 0
  • Joined: 2007/08/22 08:44:04
  • Location: 0
  • Status: offline
2012/06/08 08:26:15 (permalink)
0

Measuring / Calculating battery power supply with FVR

I would like to use the internal voltage reference
to calculate / measure the vdd = battery (LI ION 3.6v charged = 4.2v near empty ~3.0v)
Is it possible to do it internally without using an ADC pin ?
 
Is there any reference or tutorial about this?
 
#1

12 Replies Related Threads

    vl
    Super Member
    • Total Posts : 222
    • Reward points : 0
    • Joined: 2012/05/15 22:29:27
    • Location: 0
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2012/06/08 15:15:06 (permalink)
    0
    If you only want to compare the voltage level to a predefined threshold, you can use the FVR and the internal (or an external) comparator. You set the FVR to 1.024V, and use an external voltage divider (a pair of resistors) to translate your Vdd threshold into 1.024V.
    If you want to measure the voltage level, you'll need an ADC. Again, you'll have to use a voltage divider, as the internal ADC cannot use any reference voltage higher than Vdd, but comparing Vdd to a reference voltage of Vdd will not give you any useful information.
    #2
    WB
    Super Member
    • Total Posts : 230
    • Reward points : 0
    • Joined: 2012/06/25 15:58:55
    • Location: Chandler, AZ
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2012/06/26 13:30:11 (permalink)
    0
    The general formula for ADC conversion is:
    Voltage-to-be-measured/ADC Reference = ADC Result/ADC Maximum Result
     
    In your case:
    Voltage-to-be-measured = FVR (ADC channel set to read FVR)
    ADC Reference = Vdd (ADC reference set to Vdd)
    ADC Maximum Result = 0xFF (for 8-bit converters) or 0x3FF (for 10-bit converters)
     
    FVR is known and Vdd is unknown. Solve the equation for Vdd:
    Vdd = (FVR * ADC Maximum) / ADC Result
     
    For example, if FVR = 1.024 and you are using an 8-bit converter, then when the ADC result is 0x4E:
    Vdd = (1.024 * 255)/78
    Vdd = 3.35 V
    #3
    David
    Pic User
    • Total Posts : 1288
    • Reward points : 0
    • Joined: 2007/12/17 23:19:53
    • Location: uk sussex
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 04:39:06 (permalink)
    0
    I know this is an old post....
     
    I am trying to measure the supply voltage of a pic18f26k22.
    my meter reads about 4.95v the calcs with the FVR say the supply voltage is about 4.85v is this as close as I am going to get ?
     
    ps using all 10 bits 1024 for the calculation done on a calculator not is software yet !

    David
    I support http://picforum.ric323.com because this forum is often too broken to use!
    #4
    RISC
    Super Member
    • Total Posts : 5376
    • Reward points : 0
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 05:15:22 (permalink)
    +2 (2)
    David,
    Did you check the datasheet electrical parameters from the FVR for your PIC ?
    This will explain to you that probably several percent of error must be expected and therefore you can only use 6 or 7 bits from ADC result...
    Regards
     
    #5
    Jim Nickerson
    User 452
    • Total Posts : 6124
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 06:41:30 (permalink)
    +2 (2)
    Good find RISC,
    That is quite a range
     

    Attached Image(s)

    #6
    Mysil
    Super Member
    • Total Posts : 3326
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 08:30:14 (permalink)
    +3 (3)
    Hi,
    The FVR peripherals in PIC microcontrollers are not calibrated by the factory.
    If you have 4.95 Volt from your multimeter, and 4.85 Volt from calculations using FVR,
    then you have One observation to build a Calibration table or formula.
     
    Specifications in the datasheet is for the extreme range of temperatures and supply voltages.
    With a known temperature and supply voltage, each device is likely to be stable within a smaller range.
     
    You may make similar calibration measurements with different supply voltages, and at high and low temperatures, to make a calibration table or formula, and program that in the microcontroller.
     
    It also depend on how much you thrust your multimeter as a voltage reference.
     
    Regards,
       Mysil
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 17611
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 09:09:04 (permalink)
    +2 (2)
    Or you can get a real reference, if you needed it.
    #8
    David
    Pic User
    • Total Posts : 1288
    • Reward points : 0
    • Joined: 2007/12/17 23:19:53
    • Location: uk sussex
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 10:29:18 (permalink)
    +2 (2)
    Gents  thanks for all the replies , I fixed it LOL
    not showing it I just fudged the output but I needed to get on, it seems the real answer is a real reference.

    David
    I support http://picforum.ric323.com because this forum is often too broken to use!
    #9
    Mysil
    Super Member
    • Total Posts : 3326
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 11:19:11 (permalink)
    +2 (2)
     
    Even a 'real reference' require calibration in order to confirm quality of results.
     
       Mysil
    #10
    NKurzman
    A Guy on the Net
    • Total Posts : 17611
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:Measuring / Calculating battery power supply with FVR 2017/06/27 14:45:20 (permalink)
    +2 (2)
    The Microchip reference is not a substitute for a real reference.
    Calibration needs depend on the desired accuracy  and stability vs the components chosen.
    #11
    tedwu
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/05/17 03:21:28
    • Location: 0
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2019/05/21 03:50:00 (permalink)
    0
    Hello,
    I use PIC16F18346 to measure VDD. I use 10-bit AD convert.
    I set Vref+ to VDD and Vref- to VSS. And to measure FVR. FVR set 1.024V.
    But I always get the ADC value = 0x3ff. Does anyone know why? 
    post edited by tedwu - 2019/05/21 03:51:04
    #12
    davekw7x
    Entropy++
    • Total Posts : 1791
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re:Measuring / Calculating battery power supply with FVR 2019/05/21 15:01:52 (permalink)
    +3 (3)
    tedwu
    ...I always get ...
    Does anyone know why?

    Since I can't look over your shoulder and see your code or your test setup, I can only offer an opinion.  (See Footnote.)

    [/Begin Opinion]
    Guesses (In decreasing order of probability):
    • Bad Code
    • Bad Test methodology
    • Bad Connections or components (Power/Gnd/Decoupling)
    • Bad Chip
    • Something Else
    [/End Opinion]
     
    Now some reality:
    I took a previous '18346 MCC project that I had used on my Curiosity board to test the ADC input from the on-board Pot and changed it to read the FVR:

        // In main(): initialize everything here, then...
        //
        printf("\r\nCompiled on %s at %s by XC8 version %u\r\n",
                __DATE__, __TIME__, __XC8_VERSION);

        uint16_t adc_value;
        while (1) { // Main loop
            LED1_Toggle();
            //adc_value = ADC_GetConversion(ADC_POT);
            //printf("adc_value = %u\\r\n", adc_value);
            adc_value = ADC_GetConversion(channel_FVR);
            printf("ADC value from FVR  = %u = 0x%03X\r\n", adc_value, adc_value);
            {
                // If the rest of your project is too big, comment out this block
                double flt_value;
                flt_value = adc_value*3.3 / 1024.0;
                printf("value = %.5e Volts\r\n\r\n", flt_value);
            }
            __delay_ms(1000);
        } // End of Main loop


    Output for the first few seconds...
    Compiled on May 21 2019 at 14:45:24 by XC8 version 2050
    ADC value from FVR  = 318 = 0x13E
    value = 1.02480e+00 Volts

    ADC value from FVR  = 318 = 0x13E
    value = 1.02480e+00 Volts

    ADC value from FVR  = 320 = 0x140
    value = 1.03125e+00 Volts

    ADC value from FVR  = 319 = 0x13F
    .
    .
    .

     
    I have never used floating point in one of these chips in a "real" project, but for test purposes I shot the whole wad.  (Just for kicks)
     
    This entire little toy project, including floating point calculation and printout took a little less than 50% of the Program Memory
     
    MPLABX version 5.15, MCC Plug-in version 3.75, XC8 version 2.05, C99 mode  (Free version.)

    Regards,

    Dave

    Footnote:
    The opinions expressed here are not necessarily my own...
    It's those dang voices in my head!


    post edited by davekw7x - 2019/05/21 15:18:05

    Sometimes I just can't help myself...
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5