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

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

Connection...
Members : 75

Member online :
Anonymous online : 3

Total visits: 1633217

Most ever online
Total : 170

The 01/01/2021 @ 17:50

Webmaster - Infos

Ip: 3.92.91.54

Search

Friends News
Where are you from?

Sentence to think about :  Slow and methodical testing like this will eventually get you to a point where you will either be able to spot the bug, or go quietly insane. Maybe both.
Top