Battery monitoring

ZOR

Senior Member
I am trying to monitor my supply rail (battery) I tried a potential divider and used an ADC input, but maybe because my two resistors were not correct values, my results were not very good (eratic low/high value.

Now trying this code
Code:
Main:
CalibAdc10 b0
B0 = 10476 / b0
SerTxd( "circuit's voltage ", #b0, CR, LF )
PAUSE 2000
Goto main
At 4.5 volts I get a figure of 44
At 4 volts, it alternates between 29 and 216?
 

hippy

Technical Support
Staff member
CalibAdc10 b0

You are getting a 10-bit ADC reading and putting that in a byte variable which can only store 8-bits. Try with a word variable instead.
 

ZOR

Senior Member
Many thanks hippy, that fixed it.

EDIT Am I wrong hippy, but in manual 2, readadc10 there is an example, it shows the line

Section 2 readadc10

readadc10 C.1,w1 ; read value into b1

How does b1 get it's value from w1? When I debugged, b1 was 0
 

hippy

Technical Support
Staff member
readadc10 C.1,w1 ; read value into b1

That appears to be a typo in the comment; the command will have read the value into the variable specified in the command which is 'w1'.
 

SAborn

Senior Member
readadc10 C.1,w1 ; read value into b1
Yes it is an error in the manual, but one would expect someone who has been around picaxe as long as you, should realize if you write data to a word variable, than you would read data from that word variable.

The manual should quote........

readadc10 C.1,w1 ; read value into W1
 

westaust55

Moderator
The values received from READADC is proportional to the supply voltage so as the supply voltage drops the resistor divider will also drop proportionally and your READADC value would not change.
You need to use either an internal or external reference voltage to compare against for checking the PICAXE supply voltage.


Edit: ignore the above - you are using the Calibadc command at post 1.
Only later posts discuss READADC from manual error perspective.
 
Top