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
    952


    Did you find this post helpful? Yes | No

    Default ADCIN - how do I select the 0,6V Reference channel?

    I still would like to know how to "read" the 0,6V (VP6) channel. This voltage reference is provided by the PIC itself.

    If I set the ADSCON0 register to (i.e.) %10110100 (right just., VDD, 0,6V Reference, ADC is ON), what is the PICBASIC command to read that channel? If it is ADCIN, then ADCIN what?

    Name:  2015-09-26 18_34_25-Clipboard.png
Views: 4020
Size:  49.7 KB

    I tried with:
    Code:
    ADCIN 13, myvar
    because I see channels from 0 to 11 in the DS, maybe "0,6 V ref" would be the 13th...and PBP accepts the compilation but the ADCIN result shows always 0
    Roger

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: ADCIN - how do I select the 0,6V Reference channel?

    ADCIN x, myvar

    where x is the AD channel where you connected the voltage divider we were talking before.

    If it is on pin 18, channel 1 then x=1 and so on.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    I'm sorry, but I still don't understand

    Looking at the ADC bloc diagram I've attached in post#1, I understand there is a "0,6V Reference" channel that I have to select to get an ADCIN result of 122 @ 5VDC or 186 @ 3,3VDC.

    This channel doesn't seem to be linked to any pin of the PIC - this is confusing me at most.

    Does this "0,6V Reference" channel really exist?

    ----

    Hum...just found I have to ENABLE the 0,6Voltage Reference in VRCON register, bit 4 "VP6EN". I'll have a try in a moment...
    Last edited by flotulopex; - 26th September 2015 at 21:38.
    Roger

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


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    ...no, still getting 0.
    Roger

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    Please post the program.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    This is the code of which I removed the "cooking timer" specific code placed after the DEBUG part. If you think it can help, I'll post the full code.
    Code:
    '-------------------------------------------------------------------------------
    ' PIC 16F690 Fuses (MPASM)
    @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
    '_INTRC_OSC_NOCLKOUT
    
    '-------------------------------------------------------------------------------
    ' Registers   76543210
    OPTION_REG = %10000110 'Pull-Ups OFF, Prescaler TMR0 1:128
    ANSEL      = %00010000 '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     = %10000001 'AD Module is ON, Channel 1
    ADCON1     = %00000000 'AD control register
    CM1CON0    = %00000000 'Comparator1 Module is OFF
    CM2CON0    = %00000000 'Comparator2 Module is OFF
    INTCON     = %10100000 'INTerrupts CONtrol; GIE=1, T0IE=1
    TRISA      = %00000000 'Select Input/Output (0 to 5)
    PORTA      = %00000000 'Set High/Low (0 to 5)
    TRISB      = %00110000 'Select Input/Output (4 to 7)
    PORTB      = %00000000 'Set High/Low (4 to 7)
    TRISC      = %00000001 '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!!!)
    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)
    
    ' Custom Characters
    lcdout $FE,$28 'Function Set change - ONLY valid for ST7036 controller based LCDs
    LCDOUT $FE,$40,$02,$06,$1A,$1A,$1A,$06,$02,$00 'Char 0 = Speaker
    LCDOUT $FE,$48,$00,$0A,$0A,$00,$00,$11,$0E,$00 'Char 1 = Smile
    LCDOUT $FE,$50,00,00,00,00,00,00,00,00 'Char 2
    LCDOUT $FE,$58,14,27,17,17,17,17,31,00 'Char 3 = Battery 1/5 full
    LCDOUT $FE,$60,14,27,17,17,17,31,31,00 'Char 4 = Battery 2/5 full
    LCDOUT $FE,$68,14,27,17,17,31,31,31,00 'Char 5 = Battery 3/5 full
    LCDOUT $FE,$70,14,27,17,31,31,31,31,00 'Char 6 = Battery 4/5 full
    LCDOUT $FE,$78,14,31,31,31,31,31,31,00 'Char 7 = Battery 5/5 full
    lcdout $FE,$29 'Function Set change
    
    '-------------------------------------------------------------------------------
    ' Variables
    
    CLEAR
    
    SoftSwitch  var PORTA.2
    SoftSwitch  = 1
    Btn1xMinute var PORTB.4
    Btn5xMinute var PORTB.5
    
    '******* DEBUG ******
    LED_Alarm   var PORTB.6
    LED_Alarm   = 0
    LED_RUN     var PORTB.7
    LED_RUN     = 0
    '******* DEBUG ******
    
    Bat_Enable  var PORTC.1
    Bat_Enable  = 0
    Bat_Port    var BYTE
    Bat_Port    = 4  'PORTC.0 - AN4
    Bat_Level   var byte 'for LCD character selection (3:7)
    Bat_Level   = 7
    Bat_Value   var word 'holds ADC value
    Bat_Value   = 0
    Minutes     var byte
    minutes     = 0
    Seconds     var byte
    Seconds     = 0
    Ticks       var byte
    Ticks       = 0
    Dsp_Upd     var bit 'Display Update Allowance 
    DSP_Upd     = 1
    Alarm       var bit
    Alarm       = 0
    Cnt_A       var word
    Cnt_a       = 0
    RUN         var bit 'timer is running
    RUN         = 0
    IdleCounter var byte 'counter that increments while timer is 00:00
    IdleCounter = 0
    
    '-------------------------------------------------------------------------------
    ' Start program
    
    
    '******* DEBUG ******
    TEST:
            ADCIN 13, Bat_value
            lcdout $FE,2,"B ",dec4 Bat_Value
    GOTO TEST
    '******* DEBUG ******
    
    END

    My question, in other words, is: how do I route the VP6 (0,6V Reference) to the ADCIN?
    Roger

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Battery monitoring - ever tried AN1072?

    Hi Roger.

    I am looking now the latest Data sheet (version F) of the chip and it seems that this chip supports 0,6 Volt reference only for the comparator. The ADC can be referenced internally byt the VCC or externaly on pin 18.

    Sorry for the late detailed reply. It is my fault I did not check the data sheet earlier.

    So in your case you have to use the internal reference to Vcc (that is 5V in your case), with ADCON0 set as it is now and read the input on your pin, which I suppose is PortC.0 with the

    ADCIN 4,Bat_Value (Not 13 as in your program).

    The other option you may have, is to use the comparator, and when the voltage of the divider trips under the reference, to have an interrupt, or just look for the comparator out if it is set. But you cannot have the exact battery value.

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

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