Battery voltage monitoring for use on 16F1825


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Battery voltage monitoring for use on 16F1825

    Any feed back on why the ACD is not working , how to workout the calculation for the what result i should see ?

  2. #2
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: Battery voltage monitoring for use on 16F1825

    I notice a couple of oddities in your code that may (or may not!) be part of the problem. You are using the PBP ADCIN command but not any of the PBP defines. I don't know if PBP needs the defines beyond setting some register bits which you do directly. Below is a gentle re-arrangement of your code, trying to follow the exact order recommended in the manual. Also, it explicitly waits until the FVR is ready and, instead of using ADCIN, manually starts the conversion, waits for it to finish, and then reads the result.

    Code:
    ' ---------- Gets a Voltage reading on Port1.0 --------- 
     
     ' Note:  - Application circuit has a 3.3v voltage reg fitted so could use VDD as Vref in ASCON1 register
     '        - have used the ADC Fixed Voltage Ref Modual in 16F1825.
     '        - PortA.0 ia also used as Digital Output of Power LED active low via Pch - Mosfet
     '        - Supply Voltage input range is 8.1V - 3.5V to Voltage divider ( Vsupply --> 27k -|- 15K -- GND)  giving ADC input on PORTA.0 = 2.8 - 1.4V
     '                                                                       (                PortA.0        )
     
     Get_volts :
      TRISA.0 = 1           ' setup Port A.0 input=1,output=0 for I/O pins ( Note RA3 - is input only (digital)- refer spec)
      ANSELA =  %00000001           ' Set Port A.0 - Analoge I/O  , 0 = Digital  1 = Analog
      
      FVRCON  = %10000010           ' Bit 7 =1 enable Fixed Voltage Ref Modual, Bit 6 = VRef ready bit =1 always ok on 16F1825, Bit 5 - Temp indicator 1= enable/0 = disable
                                    ' Bit 4 = Temp Indicator Range Sel 0=Vout -Low range / 1= Vout -High range , Bit 3-2 = 00( DAC Fixed volt sel )
                                    ' Bit 1-0 = 10 - ADC Fixed Vref of 2.048v
      
    while FVRCON.6 = 0 : wend  'wait for FVR to be ready
                                        
      ADCON0 =  %00000001           ' bit 7 -N/A , Bit 6-2 = ADC chan Sel /Tempature output /FVR output = AN0 sel = 00000 ,
                                    ' Bit 1 - Go/_done status flag - 1 = Go do ADC / 0 = Done ADC , Bit 0 = Enable ADC = 1  / 0 = Disable ADC
      
      ADCON1 =  %10100011           ' bit 7 = 1 ADFM ( ADRESH, ADRESL - right justify ).Bit 6-4 ADCS = 010 - Fosc/32 conversion clock 
                                    ' Bit3 - N/A , Bit2 = 0 (Vref- is connected to Vss) , Bit1-0 = 11 - Vref+ connected to FVR Modual 
      
      
      pauseus 10                    ' allow Vref to stablise - ??? - not required for the 16F1825/29 ?? 
      
      
    '  adcin  0, ADval               ' Read PortA.0 value into variable , this applies the fixed voltage ref (via ADCON0,ADCON1,FVRCON)
    '                                ' to comparitor and ADC pin selected and gives result   ???
      ADCON0.0 = 1    'start the conversion
      while ADCON0.0 = 1 : wend   'wait for it to finish
      ADVal.byte0 = ADRESL
      ADVal.byte1 = ADRESH
      
       write $01 ,ADval.byte0       ' debug of voltage measurement - lower byte 
       write $02 ,ADval.byte1       ' debug of voltage measurement - upper byte 
       
         If ADval <= 1024 then      ' Have no idea of the value its going to get ??  , but if below value of 1.6V ( 4.5v Vsupply) then set Power low values
               Pulse_off  = 500     ' Set Pulse_off duration to 500us to signal power low to IR_RX 
               Flash_rate =  10     ' Set Power Led toggle to fast rate to show low power  
            Else 
               Pulse_off  = 276     ' Set Pulse_off duration to 300us( adj) to signal NOT power low to IR_RX 
               Flash_rate = 100     ' Set Power Led toggle to Normal rate to show NOT low power   
         endif   
          
                                    ' Restore PortA.0 to digital . ACD OFF etc 
       ADCON0 =  %00000000          ' Set ADC to Disable  - Bit 0 = Enable ADC = 1  / 0 = Disable ADC
       ANSELA =  %00000000          ' Set Port A.0 = 0 Digital, 0 = Digital  1 = Analog
       TRISA.0 = 0          ' setup Port A.0 input=1,output=0 for I/O pins ( Note RA3 - is input only (digital)- refer spec) 
     
     return
    Hope this helps...

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Battery voltage monitoring for use on 16F1825

    A while back I added a battery voltage tester to an existing circuit board. I didn't have a choice - the PIC was operating from the battery directly without a regulator at 5.4V (6V battery through series protection diode). Using a jumper wire I connected the ADC to an on-board regulator in another part of the circuit. Now it measured voltage in reverse; the lower the battery voltage, the higher the ADC reading. With trial and error I found 167 to be my alert number for low battery.

    ADCIN 1, BATTERYCONDITION
    IF BATTERYCONDITION >= 167 THEN HIGH PORTB.0.

    Portb.0 connected to Nch FET. For low voltages I always use a logic-level FET with a very low gate threshold voltage. I prefer IRLZ44N. It's a power transistor that I use to supply 2A without needing a heatsink. Just barely gets warm at that current.

Similar Threads

  1. Voltage Monitoring
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 11th July 2011, 23:51
  2. ADCIN car battery monitoring
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th June 2008, 08:04
  3. pwm with voltage monitoring
    By jetpr in forum General
    Replies: 3
    Last Post: - 29th January 2008, 08:49
  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