What is the simplest way to sense/measure source battery voltage?

chipwich

Member
I like my projects to be aware of the battery voltage that is driving the PICAXE. In the past, I've hooked a 2.5v regulator up to one of the ADC pins and, then measured the ADC value. Since the PICAXE ADC changes with source voltage, but the pin voltage is constant because of the regulator, I have a way to sense the source voltage.

But I'm now running my projects at 2.5v or less, so the regulator trick isn't ideal. I can look for a lower voltage regulator, but I'm wondering if there's an even easier way to do this, possibly with a single component such as a zener diode. Or, even better, perhaps there's some trick of the new 08M2 devices such as a twisted use of the READINTERNALTEMP command. I'd be surprised if this function wasn't already available at the PIC level.

Any ideas on the simplest way to sense the PS voltage that will work down to 1.8v? As always, thanks in advance for any ideas.
 

erco

Senior Member
Check out the fixed voltage reference command FVR for the M2 series. You can select:

FVR1024=1.024V

FVR2048=2.048V

FVR4096=4.096V

I use a voltage divider trimpot across the battery to adjust input to the ADC.
 

Pauldesign

Senior Member
Use brown-out protection either in hardware or software; when the voltage drops beyond the limit, the circuit powers off.
 

Jeremy Harris

Senior Member
Use a forward biased diode. 0.6V constant. Nice and easy :)
The trouble with using a diode is that Vf is somewhat sensitive to temperature and Vf can vary by as much as 0.1V from batch to batch for the same diode type. For example, at 25 deg C the common 1N4148 small signal diode can be anything from 0.62V to 0.72V at 5mA, it's the luck of the draw as to what you'll actually get. The temperature sensitivity is such that you can use the Vf of a diode as a temperature sensor, as it not only varies with temperature but does so in a fairly predictable way (typically around 2.2mV per deg C temperature change for most small diodes).

Far better to use the internal reference in the M2 parts as already suggested, as that uses a much more accurate and stable reference source.
 

MartinM57

Moderator
The trouble with using a diode is that Vf is somewhat sensitive to temperature
..and of course with Iforward. So what value of If would you recommend so that Vf is 0.6v - noting that that current will be consistently drawn just to provide the measurable Vf, which may not be consistent with battery powered application.

Not very "nice and easy" IMHO....
 

Jeremy Harris

Senior Member
..and of course with Iforward. So what value of If would you recommend so that Vf is 0.6v - noting that that current will be consistently drawn just to provide the measurable Vf, which may not be consistent with battery powered application.

Not very "nice and easy" IMHO....
0.6V is lower than the minimum Vf for pretty much any ordinary small signal diode, and the variation of Vf with If is large and non-linear at small currents (less than around 20mA). Take a look at the data sheet for the 1N4148 for example: http://www.nxp.com/documents/data_sheet/1N4148_1N4448.pdf at an If of 5mA Vf can be anywhere from 0.62V to 0.72V at 25 deg C. Increasing If by just a few mA will significantly change Vf, see Fig 3 on the data sheet linked above for an illustration of the steep curve at low values of If.
 

chipwich

Member
Thanks for the helpful responses. I think the FVRSETUP and CALIBADC commands can provide exactly what I was looking for. I must've missed these in my read of the literature describing the M2 parts. But I'm glad they're added. It's extremely handy to provide battery powered circuits with the ability to sense PS voltage.
 

g6ejd

Senior Member
Code:
PSU_Volts:	
  calibadc10 temp_word
  'Vpsu = Vref * 1023 / Nref or Vpsu = 1048 / Nref
  Htemp = 1049 / temp_word 'Htemp is a temporary byte
  Ltemp = 1049 * 10 / temp_word % 10 'Ltemp is a temporary byte
  SerOut LCD,BAUD,(254,Line4,#Htemp,".",#Ltemp,"V Supply voltage")
  Return
FOr the 18M2 part I find 1049 is more accurate
 

AllyCat

Senior Member
Hi,

Yes, as hippy suggested, using the FVR and the supply rail as "reference" is almost a no-brainer, because it requires NO dedicated pins.

However, care is needed (particularly with 10-bit adc conversions) to avoid 16-bit overflows, or general loss of resolution. For high resolution measurements (NOT the same as "accuracy"), I posted a "31/15-bit division" routine in the code snippets section.

Cheers, Alan.
 
Top