Battery monitoring - ever tried AN1072?


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    Roger, for this to work you need to get rid of the LDO and feed a 4,5Volt battery pack to the PIC. That way you will measure the Vdd voltage in respect with the VP6 input to the ADC. There is no other way to do it.

    Your configuration would be:

    Code:
    ADCON0=%10110101   ' Here we drive the 0,6 volts to the ADC
    ADCON1=%00110000   ' I prefer to be sure to have FRC for the beginning at least
    VRCON= %00010000   ' Enable the VP6 reference
    Now if you want to measure the Vdd, just do this:

    Code:
    ADCON0.1=1
    while ADCON0.1: wend
    Bat_Value.Byte1=ADRESH:Bat_Value.Byte0=ADRESL
    But remember, you have to drop the LDO and supply your circuit from the battery directly.

    Ioannis
    Last edited by Ioannis; - 27th September 2015 at 18:42.

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    946


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    Quote Originally Posted by Ioannis View Post
    ...you need to get rid of the LDO and feed a 4,5Volt battery pack to the PIC. That way you will measure the Vdd voltage in respect with the VP6 input to the ADC.
    Thanks Ioannis; I now understand what you mean.

    This morning, I tried to manually setup the ADC but it was always "failing" (= giving same value all time); you just explained why it didn't work

    I found an example on which I based my test code here.

    I'll give your example a try
    Roger

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    946


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    ...and here are the two code example files I was talking about in my post#43 ;-)

    AN1072src.zip
    Roger

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    There is a post by Darrel re this but I can't find it. I don't have any PICBasic code to hand but this in Proton might help -

    Code:
      ADCON1 = %00100000                  ' ADCS=010 Fosc/32 4usec
      Symbol Go_Done = ADCON0.1
      Symbol ADON = ADCON0.0
      Symbol VP6EN = VRCON.4              ' 0.6V Reference Enable Bit
    
      Dim Ad_Result As ADRESL.Word        ' Convert the ADRESL register into a WORD variable
      Dim VDD       As Word
    
    
      VP6EN = 1                           ' Turn 0.6V reference ON
      ADCON0 = %10110101                  ' right justify, Vdd, select 0.6v ref, ADC on   
      DelayUS 100                         ' Wait for sample/hold capacitors to charge and VP6 to settle
      Go_Done = 1                         ' Start conversion
      While Go_Done = 1 : Wend            ' Poll the GO_DONE flag for completion of conversion
      ADCON0 = %10110100                  ' right justify, Vdd, Select 0.6v ref, ADC off   
      VP6EN = 0                           ' Turn 0.6V reference OFF
      VDD = 6144/Ad_Result                ' convert input reading to VDD voltage *VDD must be a Word
                                          ' 0.6 * 1024 = 614.4 - 6144 To get 1/10th
    George

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    946


    Did you find this post helpful? Yes | No

    Thumbs up It works!!!!

    Finally YOU made it!!!

    I just changed my circuit to power it directly from my variable power-supply and simulate the batterie's weakening.

    @5VDC, my display shows a value of 135 and @4,2VDC (can't go lower or my display won't work anymore) I read 147.

    So, except the particular init sequence for the LCD I use, the code example here under is working fine and should be quite standard.

    Code:
    ' PIC 16F690 Fuses
    @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
    
    '-------------------------------------------------------------------------------
    ' Registers   76543210
    OPTION_REG = %10000000 'OPTION register
    ANSEL      = %00000000 'Select analog inputs Channels 0 to 7
    ANSELH     = %00000000 'Select analog inputs Channels 8 to 11
    WPUA       = %00000000 'Select weak pull-ups
    WPUB       = %00000000 'Select weak pull-ups
    ADCON0     = %00000000 'AD Module
    ADCON1     = %00000000 'AD control register
    CM1CON0    = %00000000 'Comparator1 Module
    CM2CON0    = %00000000 'Comparator2 Module
    INTCON     = %00000000 'INTerrupts CONtrol
    TRISA      = %00000000 'Select Input/Output (0 to 5)
    PORTA      = %00000000 'Set High/Low (0 to 5)
    TRISB      = %00000000 'Select Input/Output (4 to 7)
    PORTB      = %00000000 'Set High/Low (4 to 7)
    TRISC      = %00000000 'Select Input/Output (0 to 7)
    PORTC      = %00000000 'Set High/Low (0 to 7)
    
    '-------------------------------------------------------------------------------
    ' Defines
    DEFINE OSC 8
    
    DEFINE LCD_DREG PORTC  'LCD data port 
    DEFINE LCD_DBIT 4      'LCD data starting PORT.bit (0 or 4)
    DEFINE LCD_RSREG PORTC 'LCD register select port 
    DEFINE LCD_RSBIT 3     'LCD register select bit 
    DEFINE LCD_EREG PORTC  'LCD enable port 
    DEFINE LCD_EBIT 2      'LCD enable bit 
    DEFINE LCD_BITS 4      'LCD bus size 4 or 8
    
    DEFINE ADC_BITS 10     'Number of bits in ADCIN result
    
    '-------------------------------------------------------------------------------
    ' Init display
    
    ' ELECTRONIC ASSEMBLY DOGM081 LCD display Mandatory settings
    '  See datasheet for circuitry changes by 5V or 3,3V operation
    PAUSE 1000      'Time to settle Vdd (THIS IS CRUCIAL FOR THIS DISPLAY!!!)
    LCDOUT $FE, $29 'Function Set: 4 bits bus mode
    LCDOUT $FE, $1C 'Bias set
    LCDOUT $FE, $52 'Power control + Contrast (HiByte)(for 5V=$52 or 3,3V=55)
    LCDOUT $FE, $69 'Follower control (5V=$69/3,3V=6D)
    LCDOUT $FE, $78 'Contrast (LowByte)
    
    '-------------------------------------------------------------------------------
    ' Variables
    Bat_Value   var word 'holds ADC value
    Bat_Value   = 0
    
    '-------------------------------------------------------------------------------
    ' Start program
    
    MAIN:
        ADCON0=%10110101   ' Here we drive the 0,6 volts to the ADC
        'ADCON1=%00110000   ' I prefer to be sure to have FRC for the beginning at least
        VRCON= %00010000   ' Enable the VP6 reference
        ADCON0.1=1
        WHILE ADCON0.1 : WEND
        Bat_Value.HIGHBYTE = ADRESH : Bat_Value.LOWBYTE = ADRESL
        LCDOUT $FE,2,DEC4 Bat_Value
        PAUSE 1000
    GOTO MAIN
    
    END
    Using the internal 0,6V reference:
    - 0,8Vbatt difference = 12 value change
    + no external components

    Using an external voltage divider:
    + 0,8Vbatt difference = 84 value change
    - external components


    Thanks a lot for all your help
    Roger

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    946


    Did you find this post helpful? Yes | No

    Default Adcin 13

    ...and while testing things, here is something I just tried based on the code in my previous post using the ADCIN command:
    Code:
    ' Start program
    
    MAIN:
        ADCON1 = %00110000   ' I prefer to be sure to have FRC for the beginning at least
        VRCON  = %00010000   ' Enable the VP6 reference
        ADCIN 13, Bat_Value  ' ADCON0 = %10110100 where bits 5:2 are the 0,6V reference's channel address (1101 = 13)
        LCDOUT $FE,2,DEC5 Bat_Value
        PAUSE 1000
    GOTO MAIN
    
    END
    The results are @5VDC I read 8640 and 9790 @4,2VDC (?!) but it looks to work somehow.
    Roger

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Adcin 13

    The ADC is 10 bit, the largest value you can read is 1023 (10 1's). BTW check to table in the ADC section re. recommended ADC clock source, at 8 Mhz use Fosc/16 or Fosc/32. See note re using FRC as a clock source above 1Mhz.

    You seem to have missed out the conversion to 0v1.

    George

Similar Threads

  1. Battery voltage monitoring for use on 16F1825
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 23rd April 2013, 15:57
  2. Replies: 13
    Last Post: - 22nd January 2012, 05:48
  3. ADCIN car battery monitoring
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th June 2008, 09:04
  4. 12v car battery monitoring
    By oldcarguy85 in forum Schematics
    Replies: 2
    Last Post: - 10th December 2007, 01:26
  5. Using the A/D for Monitoring a Solor Cell and Battery
    By chuck.sieveking in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th July 2004, 20:27

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts