Battery monitoring - ever tried AN1072?


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    I'll need to download the latest DS, mine is from 2007

    George, would you have a little piece of PICBASIC code about how to use the 0,6V reference please?

    As a matter of fact, my AN1072 is from 2006 and there is no code example in there. And even if there would be some, it wouldn't be in PICBASIC anyway.
    Roger

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


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    Thanks Ioannis. I just replied while you were sending your reply.

    The first lines of the AN1072 say:

    INTRODUCTION
    This application note describes how to measure the voltage supplied to a PIC ® microcontroller, VDD . The device used in preparation of this application note was the PIC16F690. The ability to measure VDD lends itself to battery applications where VDD is likely to fall over time. In this application note, an example program is provided with routines to measure VDD.

    THEORY OF OPERATION
    Select Microchip PIC microcontrollers contain a 0.6V or 1.2V internal reference that is selectable as an input to
    the ADC module
    . This provides a fixed reference to allow measurement of VDD . The PIC16F690 was chosen for this feature.



    A:- I can't still find a code example in this AN.
    B:- Can this AN be wrong?

    Right; on MICROCHIP's website, I could find two ASM code examples....but I don't know machine language or I wouldn't probably be on this forum

    But here they are (ZIPfile) so if somebody want's to have a look and "translate" the essential stuff in PICBASIC, it would be great.

    In case I can't really use the 0,6 reference voltage, I plan to make my circuit looking like this:
    Name:  2015-09-27 18_38_05-1 .png
Views: 1093
Size:  37.0 KB



    Attachment 8058
    Last edited by flotulopex; - 27th September 2015 at 17:42. Reason: added stuff
    Roger

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,166


    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 17:42.

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    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

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


    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

  6. #6


    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

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    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

  8. #8
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    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

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, 14:57
  2. Replies: 13
    Last Post: - 22nd January 2012, 04:48
  3. ADCIN car battery monitoring
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th June 2008, 08:04
  4. 12v car battery monitoring
    By oldcarguy85 in forum Schematics
    Replies: 2
    Last Post: - 10th December 2007, 00: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, 19: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