Welcome!
cool Welcome PIC fans!
(to Pascal language fans too!)
Documents

Close Documentation

Close How to support PMP

Close Manuals

Close Today's favourites

Technical

Close Tips

Search




Downloads
Google

Tips - How to measure Vdd without any pin!
If we want to know what is the Vdd voltage to say, elaborating a "low battery" condition, the normal way would be to measure it with a resistive divider on an analog input pin. This uses two resistors and a pin.

Fortunately, on most devices, there is the possibility to measure the internal VRef, and if we use Vdd as the analog range, the result is reverse proportional to Vdd:

function Low_Bat : boolean; // Check battery

    { Note: Battery sense uses VP6 reference so we always measure 0.6 V,
            so a/d value is depending to VDD with the law: n = 0.6 * Max / Vdd,
            so the a/d value is reverse proportional to Vdd;
            so we can compute Vdd = 0.6 * Max / n;

            Power is from a 3.6 V lithium battery.
            We fix a low bat value to 3.1 V.
    }

  const
    Max_Ana = 1023;                                        // 10 Bits analog max value
    VP6_Ref = 600;                                         // 0.6 V = 600 mV
    VP6_Ref_Error = - 25;                                  // -25 mV error on vref (manual adjustement for fine tuning)
    Low_Bat_Voltage = 3100;                                // 3.1 V = 3100 mV

   
// Low battery trigger value in analog raw binary value
    Low_Bat_Trigger = (VP6_Ref + VP6_Ref_Error) * Max_Ana div Low_Bat_Voltage;

  var
    V : word;
  begin
    { A/D init: may be done once at program start-up }
    ANSEL := 0;                   { Set selected channels mask }
    ANSELH := 0;                  { Set selected channels mask }
    ADCON1.ADCS := 5;             { Set clock selection to FOsc/16 }
    ADCON0 := [ADFM, ADON];       { Configure for 10 bits right justified, turn on the A2D module }
    VRCON.VP6EN := true;          { Activate A/D VP6 reference for Vdd measurement }

    // Normally we have to wait a while here for settle time...

    ADCON0.CHS := 13;             { Select VP6 channel }
    delay(5);                     { Wait 5 µS for A2D amp to settle and capacitor to charge }

    ADCON0.GO := true;            { Start conversion }
    while ADCON0.GO_DONE do;

    V := (word(ADRESH) shl 8) or ADRESL;
    ADCON0.ADON := false;         { Turn off AD to save power }

    Low_Bat := V >= Low_Bat_Trigger;     
  end;


Creation date : 2009.06.12 0:07 PM
Last update : 2009.06.12 0:10 PM
Category : Tips
Page read 1951 times


Print the article Print the article


react.gifReactions to this article

Nobody gave a comment yet.
Be the first one to do it!


Connection...
 
Members List Members : 90

members Visits of the day: (5) Zele    fmy    brico31    PPA    tomywong   

Your Username:

Password:

[ Password lost ? ]


[ Join us ]


  Members online:
     PPA  
     tomywong  
  Anonymous online: 6

Total visits Total visits: 137344  

Most ever online
Most ever onlineTotal: 43

The 04/11/2009 @ 08:33


Webmaster - Infos

Ip: 38.107.191.102

Search




Friends News
Support PMP

Sentence to think about :     
^ Top ^