Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:56 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Reading state of SLA battery

Author Message
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 01:25pm 15 Jan 2019
Copy link to clipboard 
Print this post

For the base station mentioned in this thread, I will be using a solar charger on a 12v SLA battery for a micromite setup. I would like to be able to query the state of the battery using a micromites A/D pin. For something this simple, is the use of a simple resistor divider good enough or does this need more than that? Is there any concern with having somekind of "protection" on the A/D pin? I would also assume maybe take 10 readings and average them? This will be my very first analog use on the micromite.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 01:31pm 15 Jan 2019
Copy link to clipboard 
Print this post

  viscomjim said  
I would also assume maybe take 10 readings and average them? This will be my very first analog use on the micromite.


A/D readings are averaged by the firmware - I think it takes 10 readings, discards the first and last then averages the middle 8 (anyone?)
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 02:14pm 15 Jan 2019
Copy link to clipboard 
Print this post

Hi Jim,

I would think this could be useful.

  Quote  For something this simple, is the use of a simple resistor divider good enough or does this need more than that?


IMHO yes!


  Quote  A/D readings are averaged by the firmware - I think it takes 10 readings, discards the first and last then averages the middle 8 (anyone?)


Hmm, not exactly.
From the MM source:
  Quote   // if we got to here it must be an analog input
// for analog we take ANA_AVERAGE readings and sort them into descending order in buffer b[].

// we then discard the top ANA_DISCARD samples and the bottom ANA_DISCARD samples and add up the remainder

// the total is averaged and scaled


This means that the highest and lowest samples are discarded.

Kind regards
Michael




causality ≠ correlation ≠ coincidence
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 03:00pm 15 Jan 2019
Copy link to clipboard 
Print this post

top stuff Michael - thanks for correctingEdited by CaptainBoing 2019-01-17
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 03:29pm 15 Jan 2019
Copy link to clipboard 
Print this post

@CB
You are welcome!

BTW the code for the analog reading is in "External.c"
The TWO highest and lowest samples of ten are discarded
#define ANA_AVERAGE 10
#define ANA_DISCARD 2


causality ≠ correlation ≠ coincidence
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 04:43pm 15 Jan 2019
Copy link to clipboard 
Print this post

Thanks for the link for the schematic. I get the resistor network, but what do the diodes actually do in this case? I apologize for noob question, just want to understand better. BTW, that is an excellent project!

I am glad to see that the code already does a nice average without having to do it in mmbasic. Very cool!
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 05:13pm 15 Jan 2019
Copy link to clipboard 
Print this post

  viscomjim said  I get the resistor network, but what do the diodes actually do in this case?

Somekind of "protection" on the A/D pin! As you wished.
They lead the overcurrent to VCC (When VCC is lower than the voltage at the voltage divider).


(c)disco4now@TBS

  viscomjim said   BTW, that is an excellent project!


Of course! Edited by twofingers 2019-01-17
causality ≠ correlation ≠ coincidence
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 05:29pm 15 Jan 2019
Copy link to clipboard 
Print this post

AHHH! Makes sense. Thanks for the info and this is how I will go about it. I am examining your code now and I have to say that they way you are computing the voltage at the A/D pin is quite a bit more complex than I anticipated. I will study it and try to figure out why you are doing that way. It obviously works well, and I want to learn, so again, thank you for sharing!

Quick question, what does this do?

vpin0=PIN(0)

I don't understand the PIN(0) part.Edited by viscomjim 2019-01-17
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 05:45pm 15 Jan 2019
Copy link to clipboard 
Print this post

@Jim
Ooopps! Sorry - a misunderstanding maybe? -, that is not my code! (But I wish it was. )

pin(0) is AFAIK the reference voltage. (Removed since Micromite MMBasic Ver 4.6c)

Change log for Micromite MMBasic Ver 4.6c
  Quote   Removed the ability to read the internal reference using PIN(0). Due to issues in the PIC32MX170 chip this function would occasionally cause the Micromite to restart without warning.
Edited by twofingers 2019-01-17
causality ≠ correlation ≠ coincidence
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:56am 16 Jan 2019
Copy link to clipboard 
Print this post

Hi.

There are two issues here as I see it.
One is the averaging of the actual reading which is discussed above & the other is averaging readings over a period of time (Say 10 seconds) to even out glitches etc.

Below is some code I use to measure battery volts on a monitoring unit I have. Readings are taken at one second intervals & continuously averaged over a 10 sec period.

I just used a simple resistor network to drop the voltage to the 'mite & compared the actual battery reading to the raw 'mite reading to get the BATT_Cal figure.


'initialisation (part of)

dim as float Batt_avg(10), BATT_Cal = 4.73 '

setpin 25, ain 'Batt volts

for x = 1 to 10
Batt_avg(x) = pin(25) 'fill array with battery volts
next x

' sub called once a second
sub Batt 'averages battery volts over a 10 sec sliding period
Batt_avg(0) = pin(25) 'get current value
for x = 10 to 1 step -1
Batt_avg(x) = Batt_avg(x-1) 'move data up array
next x

for x = 2 to 10 'Batt_avg(0) already = Batt_avg(1)
Batt_avg(0) = (batt_avg(0) + batt_avg(x)) 'total values 1 to 10
next x

Batt_avg(0) = (Batt_avg(0) * BATT_cal / 10) 'add new value to total & get average
lcd 2,1, str$(Batt_avg(0), 2, 2) + "V " 'battery volts 'write value to LCD
end sub


Brian
ChopperP
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 01:35am 16 Jan 2019
Copy link to clipboard 
Print this post

Brian, this is interesting. What resistor values are in your actual divider? Are you calling this with a settick? I will have to give this a try. Thank you for the ideas!!!
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 02:35am 16 Jan 2019
Copy link to clipboard 
Print this post

Hi Jim

I just used a 3k9 & a 1k0 with the higher value going to the battery & the junction going to pin 25. The bottom end of the 1k gets grounded of course. This gives a theoretical division of (3.9 + 1) / 1 = 4.9.

Will read up to about 15V (4.73 * 3.3)

Yes, it gets called from settick.

Glad to help

Brian
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:39am 16 Jan 2019
Copy link to clipboard 
Print this post

I use 12k/2.7k
BatVscale = 5.366 '(12+2.7)/2.7


The conversion value is set by measurement.
These values allow for a nominal 17.9 Volts before we reach 3.3V in the input.

The higher the resistor values, the lower the battery drain but too high and accuracy goes pear-shaped.

Jim
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 09:02am 18 Jan 2019
Copy link to clipboard 
Print this post

I'm monitoring an old laptop battery. It has a BMS on the output of a 14.2V, 0.8A charger.
The battery has never gone above 12.5V so my 15V limit is fine.
If I was charging an SLA, I would probably have a higher upper limit.

Brian
ChopperP
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025