battery monitor project

rob nash

Senior Member
project : battery monitor
picaxe 20x2
my exp, beginner in both electronics and picaxe

hello,
i,ve gone about moniting the voltage of two battery pack the picaxe pack is 3AA bat box, second 4AA both packs are alkaline for now intend to test ni-mh and cad.
so am reading fom the multi m reads picaxe batt. = 3.80V with a 2.15v on adc pin though a potential divider consisting 1K on V+ and 22K 0v.

reading from the multi m reads second bat, =5.72V.with a 1.02 ADC1 agian potentail divider consisting 22k on 0- and 100k V+
with this programme which i came across and altered (can,t remember the forum member so thank u forum)

Q. is the voltage on the adc pins safe

a plea. could someone elabrate more on the maths used. i feel stupid for asking but i still reading the second manaul and firstand third thankyou,,

i hope others may find this useful start,,
 

Attachments

rob nash

Senior Member
click sub early

symbol CellVoltage = w0 ;w0=Corrected Cell Voltage
symbol RefADC = w1 ;w1=Raw Adc input data variable 0-1024 10bit
symbol RefVADC = 2210 ;RefVADC = Fixed Reference voltage * 1023 (1.25 * 1279)
symbol CellVoltage1 = w2 ;w0=Corrected Cell Voltage
symbol RefADC1 = w3 ;w1=Raw Adc input data variable 0-1024 10bit
symbol RefVADC1 = 1576 ;RefVADC = Fixed Reference voltage * 1023 (1.25 * 1279)

symbol lcd =b.7


main:
readadc10 0, RefADC
pause 30
readadc10 1, RefADC1
CellVoltage = RefVADC *25 /RefADC * 100 /25 `*25/25 to improve integer math accuracy +- 0.02 RESULT is * 1000
CellVoltage1 = RefVADC1 *25 /RefADC1 * 100 /25

'To display on Picaxe Lcd display AXE033
b10= w0 / 100 'Integer Math drops all values in the decimal portion of the result.
b11= w0 // 100 'Note:- Modulus command does not display leading zeros.
If b11 < 10 Then: let b11 = "0" :EndIf
b12= w2 / 100
b13= w2 // 100
If b13 < 10 Then: let b13 = "0" :EndIf
serout Lcd,N2400,(254,128,"Supply V ",#b10,".",#b11," ")
pause 1000
serout Lcd,N2400,(254,192,"Raw ",#w0," ")
pause 1000
serout Lcd,N2400,(254,128,"s/batt V ",#b12,".",#b13," ")
pause 1000
serout Lcd,N2400,(254,192,"Raw ",#w2," ")
pause 1000
goto main

sorry about that this is code am workin with with the second bat pack powering lcd axe 33, the returning values are close to the multi m reading,
BY altering RefVADC to set current voltage in batt i get readable and useable ,,,
 

SAborn

Senior Member
Hi Rob,

What is it you are trying to do with monitoring the battery voltage.

As i have just finished designing a data logger for use with wind generators or it can be used as a consumption meter for household power.

It logs Voltage , current and line frequency (Hz) to a computer and the data is recorded to the harddrive.
This allows you to go back and look at the data in graph form for any 24 hour period or part of.

If you would like i can give you the computer software that was written for the logger and you can record your voltage direct to the computer via a picaxe reading the ADC pin. (an 08m is all that is needed)

It only requires about 6 lines of picaxe code, and the raw picaxe data is sent to the computer.
All calibration is the done on the computer as it allows for integers to be used and is only a matter of entering the division factor into a box provided.

The computer also calculates the Watts and Watt/hours from the voltage and Current values.
Wind speed can also be recorded.

These other functions are optional and you can just record voltage only.

The logging interval can be from 1 second to 600 seconds.

I have used it to monitor allsorts of battery systems and find it a greater advantage to have a recorded log rather than just a number on a display.

This greatly depends on what it is you are intending to to with your voltage readings.

It dose require for the computer to be running and the logging program to be running in the back ground or you can view the information in real time on the screen in digital form.

Let me know if it is of interest to you.
 

rob nash

Senior Member
hi SAborn,
am attempting a diagnostic programme for my bot. and the batttries voltage and current (still seaching around for reading current).
also my plan is to place the bot into safe mode as such when the voltage getting low i.e flashing eyes for now.
it sounds as you have completed a very handy project.and i would be intested as seeing your programme as a later project am making is small solar array. and am thinking your programme would be useful. which language is it written in as i would'nt know which one to start learning,
anyway thanks for the reply
 

inglewoodpete

Senior Member
ADC1 agian potentail divider consisting 22k on 0- and 100k V+
with this programme which i came across and altered (can,t remember the forum member so thank u forum)
Values of 100k and 22k for a voltage divider are a bit high for the PIC's ADC ports. From memory, input impedances over 10k begin to distort the readings.
 

SAborn

Senior Member
Hi

There is no program lanuage learning required as it is a compleet software package written in visual basic that self installs to the pc.

All that is needed is to select the com port you have connected to.

There is just 1 sertxt line in the pixaxe program that sends the data to the pc.
Although the sertxt line must be in the right code format or the pc will ignore it.

It dont get any easier than that to use.

PM. me sometime if you would like the software.

Inglewoodpete,

The high side resistor Rob used was a 1K and not a 100K as you commented above, so impedances should be ok.
 

westaust55

Moderator
@SAborn,

IWP is correct in that rob nash does mention 100k over 22k

as well as 1 k over 22k

so am reading fom the multi m reads picaxe batt. = 3.80V with a 2.15v on adc pin though a potential divider consisting 1K on V+ and 22K 0v.

reading from the multi m reads second bat, =5.72V.with a 1.02 ADC1 agian potentail divider consisting 22k on 0- and 100k V+

If this is not what rob nash meant then it is a case of vague descrioption.
In the first he menitons ADC but no digit/pin number.

In the second case he mentions clearly ADC1.


The program code
main:
readadc10 0, RefADC
pause 30
readadc10 1, RefADC1
suggests that two ADC inputs, 0 and 1, are being utilised.

Use of schematic diagram would make the intention much clearer for all
 
Last edited:

rob nash

Senior Member
thanks for the input all i,ll add a pic later today apology for a vague desciption(we southern mancs excel at vague). i think i have alot more reading to do on the subject.am unsure as wht is a safe voltage from the potentail divider to have on the adc pins. also notice that the reading are drifting away from wht the multi meter reads after a night.
thanks SAborn will pm you when i,ve got the hardware sorted
 

hippy

Technical Support
Staff member
The voltage on any ADC pin should not exceed the power supply voltage to the PICAXE. It may be worth providing a block diagram showing how the project is powered and what is providing the sources for analogue input.
 

rob nash

Senior Member
hi
i,ve addded some pic not brilliant maybe helpful.. also changed the picaxe to a 20M.only working with supply voltage the resistors in the potentail divivders are 22k 0 low and a 10k v+high.

after more reading on the forum this sparkled in me' head,
that the current setup is reading battery supply, which is supplying directly to picaxe power. hence the code is reading both battries and picaxe. am thinking for the drifting reading between m/m and picaxe.

O now am thinking, this is because their one of the same reading/
and the code has a set state being Refavdc which am thinking is the picaxe power that changes as battery deplicts.to Refadc which is reading adc1, pin which is also changing even under noloads with both variable values into the code a and bang goes the maths in the code.. i think am little of the mark.

so "whats next" isolate power supply anyone ideas please. a little walk though be nice.
Use a small resistor and cap maybe,which values thanks..

thanks rob N
 

Attachments

BeanieBots

Moderator
I've not read your first post properly and didn't quite follow at a quick glance so I might be completely wrong here:-

I assume you are trying to read the voltage of your PICAXE power supply by using the PICAXE itself.
You cannot do that simply because the reference for the ADC IS the supply.
You will some other form of reference to compare with.
This has to be something which is NOT a direct function of voltage so a potential divider will NOT work.
Ideally (for accuracy) it would be a voltage reference which be a simple 3v3 regulator. Slightly more crude would be a the forward volt drop of an LED, a little cruder still and prone to temperature drift would be a diode drop.

Some PICAXE variants have a built in function CALIBADC(10) which points the ADC to an internal diode. It's not particularly accurate but it does work.

Is this what you are looking for?
 

rob nash

Senior Member
thanks beanie bot, it is wht am after,
would the forward volt drop of an LED, go
like this "v+ resistor-led-adc".

thanks again rob
 

BeanieBots

Moderator
There are several ways you can do it but that's not one of them.
LEDs have quite large leakage current which is VERY temperature dependant and at low values is also affected by ambient light.

The simplest way is to hook up an LED as if it were a simple "power on" indicator with the LED connected to 0v and a resistor to V+.
Then connect the LED/resistor junction to ADC input.
It doesn't need to be bright but it must at least glow so a few k for the R will be fine.

Then it's a question of experimenting for the particular LED you have used.
If the LED voltage was a precision reference then you could use some maths to determine voltage but as it's quite non-linear, you will need to build a lookup table to determine voltage. This will need to be done by experiment.
Wind up the PICAXE voltage and note down the ADC readings.
(higher reading = LOWER voltage)

This has been covered before and I think someone even posted code (probably Hippy) for using the CALIBADC function.

I know Hippy wrote some code for the LED method but it was quite a while ago. Have a search.
 

BeanieBots

Moderator
Because this is the PICAXE forum and 20p does seem to break most of the banks.

Besides, there are references and there are references.
The last one I bought (a few weeks ago) set me back the best part of £6.
 

Dippy

Moderator
Ah the creaking wallets and Mum's credit cards... ;)

Well, the 20p ones are 100ppm jobiies from St Micro , TI and Fairchild.
I think I've heard of those manufacturers somewhere.
Surely better than a £50 LED? :)

I don't the task warrants mega-precision.
 

rob nash

Senior Member
hello guys
i,ve been looking in my bit box and found a mcp1702 3v reg. brilliant i thought then realised how am going to wire it up for this project?
do i connect the v out to the adc pin..help please.

thanks rob
 

hippy

Technical Support
Staff member
If you have a voltage regulator, then why not just run the PICAXE from it and then the voltage determination becomes greatly simplified and doesn't need a second ADC channel..
 

BeanieBots

Moderator
Hippy's suggestion is the obvious one but, purely as an accademic answer.
You would simply connect the regulated 3v to an ADC input. (via a 2k2 resistor for safety reasons).

Then, you can work out the PICAXE supply voltage from the ADC reading as follows:-
3 = (Vcc*ADCvalue)/255

I'll leave you to do the algebra and convert for PICAXE integer maths.
 

SAborn

Senior Member
Whats wrong with supplying the picaxe with the 3 volts from the reg and using a voltage divider (2 resistors) to read the battery voltage via a ADC input.

I do this for up to 50 volt supply (but i use a 5 volt reg normally)

It gives a good linear scale

( I take it we are still talking about monitoring the battery voltage )
 

BeanieBots

Moderator
You mean as suggested in post #19, seconded in post #20 and acknowleded in post #21.
Nothing wrong, very good idea IMHO. (re-itterated in post #23:rolleyes:)
 

Dippy

Moderator
I think it was also suggested in 2004, 2005, 2006, 2007,2008,2009 and 2010.
If longer ago than that we'll have to ask Stan.

Excellent idea, no-one has thought of it before ;)
 

rob nash

Senior Member
well the 3 volts reg was a bit no starter. could'nt get a controlled 3 volts out
just got a reading of wht was the input volt 0f 4.5v and on the v out of reg. so am ordering a few today. still reading on the subject, did,nt realise how big a topic this is like ratio metric ref "wht" i say.

just to clarify when the volts reg come.
supply the pic with 3 volts reg- use an resister +led which then goes to the adc 1. yes/no

also if i put the reg 3.3 volt on the adc won,t it read the same until the reg can no longer supply power ?

ideas for a shopping list be helpful for this project
 

Attachments

Dippy

Moderator
Do you mean other beginners ;)

I think you are getting in a right muddle here, though, as I am old, I find it hard to read your posts.

The PICAXE typically uses the supply voltage as the reference for the ADC.

So, you need either:-
1. A fixed (regulated) voltage supply to PICAXE and a connection from ADC-in to your battery.
Therefore a drooping battery is seen as a drooping ReadADC value.
(you will need a bit of pot div resistance for safe ADC input.)

2. PICAXE connected to suitable battery and a fixed low voltage reference connected to ADC-in.
The ReadADC value will increase as the battery supply droops.

This should have been obvious by arranging BB's equation in Post#21.

The fixed low voltage reference has been suggested as an LED+R.
This is OK for testing and rough stuff, but a 20p voltage reference would be much better.

If using a regulator to POWER the PICAXE then put a LDO type on your shopping list.
And READ the device data sheet re: wiring and capacitor - something else that needs to go on your shopping lit.

I'd get the basics going first before messing about with uP Supervisory circuits as this will give you even more grief at these early stages.
Run before walking.

I haven't time, but I'm sure some kind soul can post a clear example circuit.
 

BeanieBots

Moderator
@Rob,
In reply to your post #25, you missed the point of my post #21.
Explained by Dippy's post above.

If you plan to use a 3v regulator from a 4.5v supply, make sure it's an LDO type or you won't get 3v out of it.
 

SAborn

Senior Member
Hi Dippy,

I think it was also suggested in 2004, 2005, 2006, 2007,2008,2009 and 2010.
If longer ago than that we'll have to ask Stan.

Excellent idea, no-one has thought of it before
If that was directed at me i think is a bit sarcastic!

I asked a question in reply to the last answer given being
You would simply connect the regulated 3v to an ADC input. (via a 2k2 resistor for safety reasons).
Perhaps i should have asked why connect the regulated 3 volt to the adc input.
It will only show the constant value of the v reg.

What am i missing???
 

BeanieBots

Moderator
Perhaps i should have asked why connect the regulated 3 volt to the adc input.
It will only show the constant value of the v reg.

What am i missing???
You're missing the other posts which clearly explain why that is not the case.
A PICAXE ADC is NOT a voltmeter. It provides a ratiometric value relative to it's power rail voltage. Anyway, this is all explained ealier in this thread so no point going over it again.
 
Top