Welcome!
Welcome PIC fans!
(to Pascal language fans too!)
Technical

General documentation

How to support PMP

Manuals

Tips

Other stuff

Documentation

How to support PMP

Off Topic

Today's favourites

Search

Diaporama

Documentation

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 }
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 }

Low_Bat := V >= Low_Bat_Trigger;
end;

Creation date : 2009.06.12 0:07 PM
Last update : 2013.08.05 11:23 AM
Category : Tips

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

Connection...
Members : 151
Visits of the day: (1)

funlw65

Member online :
Anonymous online : 7

Total visits: 548819

Most ever online
Total : 75

The 06/09/2013 @ 08:37

Webmaster - Infos

Ip: 107.21.144.35

Search

Friends News
Where are you from?

Sentence to think about :  The enterprise's computing [...] is just like of an archaeological site. [...] Deep inside, you find real fossils, calcified: the punched card is no longer physically there,
but one can find
its "footprint" on the latest hard drives, up to traces of organization in eighty "columns".

Top