Menu

VDD Monitoring

Help
2021-04-08
2022-03-03
  • Andrew Jameson

    Andrew Jameson - 2021-04-08

    VDD monitoring must be such a common requirement - battery powered or even solar ... obvious question - is there enough power to run ?
    PIC people seem to advocate / suggest measuring using ADC and a voltage reference, even going as far as using an FET to switch on local VRef sources to minimize power drain ... and then there's an analogue comparator.
    In my case, the PIC is running some low power house keeping stuff and if there's enough accumulated power then do some other things - WiFi for example.
    What is the "best / easiest" way to keep an eye on power status - say accumulated voltage in a solar charged super capacitor ?
    There seems to be little comment / suggestion around on the internet so I was working along a solution when I found Microchip's TC54 application notes.
    I'm confused, a most fundamental parameter is that of operating voltage and all PICs seem to make measuring VDD complicated yet it seems the most logical thing to do - get the PIC to work it out ... and then, here's Microchip advocating the use of a dedicated power monitoring chip.
    Practical / constructive comment would be great and much appreciated - what's best practice ?

    Thanks

    Andrew

     

    Last edit: Andrew Jameson 2021-04-08
  • kent_twt4

    kent_twt4 - 2021-04-08

    I have used the internal FVR for ADC measurements with good success. Using it for decision making on my solar charged LIFEPO4 powered flashlight, as seen in my icon for years.

        If FVR1024 < 71 Then  '73 by inspection, OVLO(1.024V/3.65V)*255 = 72
      'Battery voltage high Burn some ma's and check again
        OverVolt = True
        savebat = False
      End If
    
      If FVR1024 > 99 Then  'UVLO(1.024/2.7V)*255 = 97
      'Battery voltage low so wait for charge from PV
        OverVolt = False
        savebat = true
      End If
    
      If FVR1024 <= 99 AND FVR1024 >= 71 Then
      'Battery voltage good so continue
        OverVolt = False
        savebat = False
      End If
    
     
  • stan cartwright

    stan cartwright - 2021-04-08

    Coild a zener diode be output high if battery ok?

     
    • mkstevo

      mkstevo - 2021-04-08

      I have actually used something similar to that to show when a 12V lead acid battery was losing charge. I had a 10V zener in series with an LED and low value current limiting resistor. The 10V dropped by the zener and the 1.8V (or so) dropped by the LED meant that if the battery voltage fell much below 12V the LED faded. For a battery with a full charge voltage of just under 14V this worked very well. Once the LED faded it was time to charge the battery.

      This was one of the very first "things" I designed from scratch, a satellite dish alignment meter. I was so proud of it! It worked well, we'd bought an expensive one at work that was impossible to use. Not only did it need constant adjustment while setting up the dish but it was so wideband in it's frequency range that on one very memorable occasion we kept pointing the satellite dish at the sun as it was in close position with the satellite. We had to wait for over an hour for the sun to move before we managed to align the dish. The second problem with the bought unit was that it relied on the cable and receiver to be in place as this provided power to the alignment meter. One major downside being that if the position of the dish/house/wall/satellite was marginal to allow a clear view of the satellite, you didn't find out if the dish would actually see the satellite, until the wire had been installed and dish screwed to the wall. If it didn't work, you would have to start again, and the customer left with holes in the wall.

      The meter I designed had a sound decoder built in so it was definite when alignment was {almost} correct as you would be able to hear Sky News, point it at the sun and you'd only hear hiss! Being battery powered allowed you to hold the dish in hand in the garden and aim it at the satellite allowing the angles to be judged before putting the dish on the wall or running any wires. We used that meter daily from the day I finished soldering it. Never used the bought one again. It was used right up until Sky started installing dishes below cost. We even used it for installing digital dishes, the sound didn't work on the digital channels, but the rest of the meter still worked for aligning the dish.

      The design earned me almost £200 as it was printed in Television Magazine. In true Lincolnshire dialect, "I were reet pleased wi' me'sen!" A slap up meal at Mrs Miggins followed!

       
  • David Stephenson

    I had this problem some time ago. I was using a LCD that needed the contrast adjusting according to the battery level. The way to do it is to use Vdd and Vss as the references and the fixed voltage reference as the input to the ADC. At the time this was not possible in GCB so I wrote it in assembly and why not also do the ADC conversion in ASM as well. This is using a 16F18326. The voltage level is stored in BAT2 as a 16 bit word.

    'intialize stuff
    fvrcon=b'10000010'
    set adcon1.1 on
    set adcon1.0 on
    set fvrcon.7 off 'off til needed
    'end initializing stuff
    
    SUB BATLEVEL
    'FVRCON=b'00000001' '1.024 V
    FVRCON=b'00000010' '2.048 V
    ADCON1=b'11000000' 'SET REFS AND Fadc WITH Fosc=4MHz
    BAT2=0
    BAT1=0
    BSF FVRCON,FVREN 'ENABLE FVR
    NOP
    BTFSS FVRCON,FVRRDY 'wait for FVR to stabilise
    GOTO $-1
    ADCON0=b'11111100' 'SET adc to read FVR
    REPEAT 64
    BSF ADCON0,ADON 'adc on
    WAIT 10 us 'AQUISITION DELAY
    BSF ADCON0,ADGO 'start conversion
    NOP
    BTFSC ADCON0,ADGO 'check for coversion complete
    GOTO $-1
    BCF ADCON0,ADON 'turn off adc
    BAT1=ADRESL
    BAT1_H=ADRESH
    BAT2=BAT2+BAT1
    END REPEAT
    BCF FVRCON,FVREN 'DISABLE FVR
    END SUB
    
     
  • mkstevo

    mkstevo - 2021-04-08

    I took the code supplied by @kent_twt4 in this thread: https://sourceforge.net/p/gcbasic/discussion/579126/thread/810b24c927/#5d2d

    I modified it only to reference the 16F1829. I'm using the complete code in a Li-Ion clock, it shows the battery status on the LCD and once the battery goes below a measured 3.3 volts puts the processor into a deep sleep to try to prevent severe discharge of the battery.

    So far this has worked well enough to alert me to the battery level as I'd hoped.

    Sub GetBattery
    
        '1) Enable and set the FVR (fixed voltage reference) register for 2.048V setting.
        '2) Enable and read the A-D FVR ;This is an internal register
        '3) You now know what the battery voltage is at that time according to:
        '
        '2.048V / BatVolts = A-D FVR / 255 ;(8 bits is close enough)
        ';Promote values by 100
        'BatVolts = 52224 / A-D FVR ;A-D FVR reading should be around 175 at 3V
    
        Let RefVolts = AD16F1829(FVR)   'internal a-d of FVR
        Let BatVolts = 52224 / RefVolts
    
    
    End Sub
    
    Function AD16F1829(IN adport)
        '  If adport < 5 Then ANSELA = adport + 1       'turn off digital input ANSA2
        '  If adport >= 5 & adport < 12 Then ANSELB = adport + 1
        '  If adport > 11 Then
        '     ANSELA = 0  'internal FVR, DAC, or Temp Indicator conversion
        '     ANSELB = 0
        '  end if
        rotate adport left simple
        rotate adport left simple
        ADCON0 = adport   'adport
        ADON = 1        'ENABLE ADC AND START CONVERSION
        Wait 10 us
        ADGO = 1        'need 200us min for temp module
        ADCPOLL:
        BTFSC ADCON0,ADGO
        Goto ADCPOLL
        ADCON0 = 0
        ANSELA = 0        'Shut down adc module
        AD16f1829 = ADRESH
    End Function
    

    The code looks very similar in principle to David's above.

    The full code showing the battery monitoring in action is in my beeping clock thread:
    https://sourceforge.net/p/gcbasic/discussion/projects&guides/thread/02b26cce7f/#cc1a

     
    • mkstevo

      mkstevo - 2022-03-03

      A quick update.
      I was testing a project that I'd used this on with a 18F15Q40. Of course it didn't work.

      As it took me a while to get this to work I thought I would make a note. It may help others and it will certainly help me.

      'The FVR register or location must be changed.
      #Define FVR = 62 'was 31 for 16F1829
      
      Sub Get_Battery
      
          '1) Enable and set the FVR (fixed voltage reference) register for 2.048V setting.
          '2) Enable and read the A-D FVR ;This is an internal register
          '3) You now know what the battery voltage is at that time according to:
          '
          '2.048V / BatVolts = A-D FVR / 255 ;(8 bits is close enough)
          ';Promote values by 100
          'BatVolts = 52224 / A-D FVR ;A-D FVR reading should be around 175 at 3V
      
          Do
              RefVolts = ADFetch(FVR)   'internal a-d of FVR
              BatVolts = 52224 / RefVolts
      End Sub
      
      Function ADFetch(IN adport)
          '  If adport < 5 Then ANSELA = adport + 1       'turn off digital input ANSA2
          '  If adport >= 5 & adport < 12 Then ANSELB = adport + 1
          '  If adport > 11 Then
          '     ANSELA = 0  'internal FVR, DAC, or Temp Indicator conversion
          '     ANSELB = 0
          '  end if
      
      'no rotate needed...
          FVREN = 1
          ADPCH = ADPort 'adport
          ADON = 1 'ENABLE ADC AND START CONVERSION
          Wait   10 uS
          ADGO = 1 'Start conversion
          ADCPOLL:
          BTFSC ADCON0,ADGO
          Goto ADCPOLL
      
          'name of function has been changed so the
          'return reflects the new function name
          ADFetch = ADRESH 'Read result
      End Function
      
       

      Last edit: mkstevo 2022-03-03
  • Andrew Jameson

    Andrew Jameson - 2021-04-09

    Thank you for your comments - they've been very helpful. It's much as I thought and it's very strange to realize how such a fundamental requirement has not been addressed and featured within the operation of a PIC. Microchip advocate the use of dedicated power monitoring chip whilst not considering how a PIC might embody that function.

    I like the Zener / LED solution - my initial idea was to use the ADC ... for me it's an early learning adventure and it's clear that, even today, there is much to explore anew.

    I'll probably order a range of TC54s too.

    Again thank you for your input.

     
  • mkstevo

    mkstevo - 2021-04-09

    I guess that using a dedicated power monitor has the advantage of accuracy. As the supply to the PIC drifts, so must the accuracy of the reference that is used to measure the supply could be their thought process?

    For roughly obtaining an indication of the state of charge, using the internal ADC is probably "good enough" for most non critical applications.

    An external monitor might have the capability to isolate the supply to the processor once the supply reaches the minimum level, with minimal drain on the supply once this has been done to prevent total discharge and potential permanent damage to the battery.

    And I don't doubt MicroChip have some lovely supply monitoring chips that they would love to sell to you...

     
  • David Stephenson

    Zenner diodes are a rough and ready solution to getting a voltage reference. I would imagine that the FVR in PICs is a little more sophisticated (like a LT1009 or equivalent) so is much less susceptible to changes in voltage with load and supply voltage (as zenners are). So I would use the FVR and the ADC rather than buy an extra chip as it may be equally as good.

     
  • stan cartwright

    stan cartwright - 2021-04-10

    you could use the millis function to take adc reading and then periodically and check battery for rapid going low voltage.

    like if you measured the battery and stored its volts then periodically then if the last measurement drop was beyond a value then the battery is going dead soon...not an expert.

     

    Last edit: stan cartwright 2021-04-10
  • William Roth

    William Roth - 2021-05-20

    Many PIC 18F chips have a programmable HLVD peripheral module. When enabled, it can set a flag or trigger an interrupt when Vdd falls below a programmed threshold voltage. Not available on 16F Chips but is included on the new 14 and 20 pin 18F Q40 and Q41 chips as well as many, many other 18F Microcontrollers. Like most if not all K40, K42, Q10, Q41, Q43 and so on

    Should make Vdd Monitoring very simple unless you are committed to PIC 16F/12F chips.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.