monitor a picaxe's 08m2 circuit's batteries power using code ?

can i monitor a picaxe's 08m2 circuit's batteries power
using code ?


i wonder if there is any way to use code
in order to check the current state of the batteries' power
providing voltage to a 08m2 controlled circuit
within regular intervals (e.g. every hour).


i tried ...


------------- ... to use readadc10
with the power-input pin


readadc10 0, w1
sertxd ("current voltage = ",#w1, 13,10)

' result -----> error - c.0 doesnt have adc capabilities



------------- ... to understand calibadc
... since i was hinted to use this command

I do not understand
if and how i can use
"calibadc" in order to check des Voltage of
my batteries
tried the following though
(which did not help me to find an answer
since i failed to understand the concept of "calibadc")

calibadc b3 'an in-output pin
SerTxd( "try b3 = ", #b3, CR, LF)

' result -----> ctry b3 = 58

... what does the value "58" stand for?
 

hippy

Ex-Staff (retired)
CALIBADC measures an internal voltage reference to give a reading between 0 and 255 where the maximum 255 represents a voltage = Vpsu, the PICAXE power supply.

For READADC the resulting value read Nadc from an input voltage Vadc ...

Nadc = ( Vadc / Vpsu ) * 255

For CALIBADC that Vadc will be the voltage reference Vref ...

Nadc = ( Vref / Vpsu ) * 255

The equation can then be reorganised to calculate Vpsu from the Nadc reading ...

Vpsu = ( Vref * 255 ) / Nadc

For CALIBADC10 ( and READADC10 ) that 255 will be 1023, and in both cases the Vref and Vadc will be in volts.

For CALIBADC10 when Vref = 1.024V ...

Vpsu = ( 1.024 * 1023 ) / Nadc

And we can get the reading in 100mV units rather than volts ( so 3.3V gives a Vpsu value of 33 ) using ...

Vpsu = ( 1.024 * 1023 * 10 ) / Nadc

Vpsu = ( 10475.52 ) / Nadc

Vpsu ~= 10476 / Nadc

Which then allows you to do things like check the voltage is between 2.8V and 3.2V in this case ...

Code:
Do
  CalibAdc10 w7
  w7 = 10476 / w7
  If w7 <= 28 Or w7 >= 32 Then
    SerTxd( "Must be 3V power", CR, LF )
    Pause 100
  End If
Loop Until w7 > 28 And w7 < 32
 

srnet

Senior Member
A resistor divider made up of a 90K and a 10K resistor will with a FVR set to 1.024 give an ADC reading of 20.02mV per count which makes the maths easy. Its is close enough approximation for reading a battery, and well within the variance that you can get with 1% resistors in any case.

(Make a 90K resistor with a 75K and 15K in series)
 
thanks a lot for all of your immediate replies!
i hope i understood your advice ...
please accept my apologies in case
the following is wrong or based
on my lack of knowledge

------>
@ nick12ab
@ srnet:


I understand that the ''adcconfig" command
(using FVR settings)
can assign adc reference voltages
to specific pins (depending on the kind of picaxe chip)-
if so:
i did not to mention that i use all of my 08M2's pins
in my project and can't free C.1 (pin # 6 )
....
but ''adcconfig" definitely is helpful
and a handy workaround
for reading values of the 0V / +V pins!

------>
@ hippy:


--------------------------------------------
CalibAdc10 w7

it works like charm!

trying to understand how it works
-assuming that w7 could be replaced
by any other w = word variable -
i tested different "w" variable names*
and received the value "270"
with anything different then "w7":

whereas w7 results in 39 (3.9V)
which is pretty close
to the remaining 41 (4.1V) battery power
(on a 4.5 V circuit)
measured with a multimeter.

is this because w7 "somehow" refers to the sum of w0 - w6
(w0 - w7 refering to 8 pins of the 8 pinned 08m2 ) ?

.......................................................
*.... tries with several w variables ....

using
w0, w1, w2, w3, w4, w5, w6, , w8 ....
for
wXX
with this code:

CalibAdc10 wXX
w7 = 10476 / wXX
SerTxd( "circuit's voltage ", #wXX, CR, LF )
.......................................................


--------------------------------------------
 
You missed one, after that it should work as expected ...

CalibAdc10 wXX
wXX = 10476 / wXX
SerTxd( "circuit's voltage ", #wXX, CR, LF )

... thanks a lot !!!
truetrue ... my fault ....
i can use any "wXX" combination
(w0, w1, w2 .....) :

the results will be the same
for all "wXX" (e.g. "39" for 3.9V)
if the code refers to the same "wXX" variable
throughout the script
 
Top