|
Forum Index : Microcontroller and PC projects : Reading state of SLA battery
| Author | Message | ||||
| viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
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 KingdomPosts: 2171 |
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: GermanyPosts: 1772 |
Hi Jim, I would think this could be useful. IMHO yes! Hmm, not exactly. From the MM source: This means that the highest and lowest samples are discarded. Kind regards Michael ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
top stuff Michael - thanks for correcting |
||||
| twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1772 |
@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 ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
||||
| viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
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: GermanyPosts: 1772 |
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 Of course! ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
||||
| viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
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. |
||||
| twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1772 |
@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 ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
||||
Chopperp![]() Guru Joined: 03/01/2018 Location: AustraliaPosts: 1131 |
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 StatesPosts: 925 |
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: AustraliaPosts: 1131 |
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: AustraliaPosts: 6606 |
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: AustraliaPosts: 1131 |
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 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |