Notifications
Clear all

Analog to Digital Converters Overload???

57 Posts
4 Users
35 Likes
4,148 Views
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Sketch for real-time graphing voltage depletion test.

#include <InqPortal.h>
#include <Stepper.h>

#define YOUR_SSID "YourSSID"
#define YOUR_PW "YourPW"
#define DEFAULT_HOST_SSID "Step"

const int stepsPerRevolution = 2048;

InqPortal svr;
Stepper s1 = Stepper(stepsPerRevolution, D1, D3, D2, D4);
Stepper s2 = Stepper(stepsPerRevolution, D5, D7, D6, D8);

u32 interval = 10000;
float volts = 0;

void setup()
{  
    svr.publishRO("Volts", &volts, "Voltage (V)");
    svr.publishRW("Interval", &interval, "Interval (us)");
    svr.onInterval(getVoltage, 1000);
    svr.autoSend(1000, true);
    svr.begin(DEFAULT_HOST_SSID, NULL, YOUR_SSID, YOUR_PW);
}

void getVoltage(void*)
{
  volts = (float)analogRead(A0) * 3.3 / 1024.0;  
}

void loop()
{
  static u32 last = 0;
  u32 now = micros();
  if (now - last > interval)
  {  
    s1.step(1);
    s2.step(1);
    last = now;
  }
}

 

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech reacted
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  
Posted by: @inst-tech

You should just use a single resistor between that voltage source and A0.
Value of that resistor should be 100k for every volt more than 3.2volt.
So for 15volt >> 15-3.2 = 11.8 * 100k = ~1200k (1.2Megohm).

  • I set the Sketch to display the readAnalog() value
  • Placed the 100k resistor in series
  • And slowly upped the bench meter 0.01 volt at a time.  The 1024 reading came up at 4.16V!!!!

You ROCK!

Now, would you be so kind as to explain how that 100KΩ/V was calculated?

I'd like to learn that technique!

VBR,

Inq

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

@inq I found this site in my research.. https://randomnerdtutorials.com/esp8266-adc-reading-analog-values-with-nodemcu/

Not sure if this applies to your board or not..but it does appear that an external RVD ( resistive voltage divider) is required as the ADC range is only 0-3.3 volts,  for example: ESP8266 12-E NodeMCU Kit, WeMos D1 Mini, …) which I believe you alluded to in earlier post, which is a 0-3.3 v ADC input..

I wouldn't go beyond that to be on the safe side..just use an external RVD to make the input to the ADC in that range..as you stated.. you really don't care if it's above that anyway, you just want to know if it's <3 volts...right?

LouisR


   
Inq reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

@inq Ya, that would be cool!...lol

You could also do an auto shutdown at that level to keep from damaging the batteries.

LouisR


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  
Posted by: @inst-tech

@inq Ya, that would be cool!...lol

You could also do an auto shutdown at that level to keep from damaging the batteries.

The 18650 Shield seems to do a forced shutdown at 2.5V... so I better have it parked where it needs to be before that happens. 😉 

 

Just finished the results using the 100 KΩ resistor...

@inst-tech, @zander, @will - This is plenty accurate for my project at hand.  I'll save a shunt for another day.

Summary: 100 KΩ Resistor in-line between positive battery terminal of 18650 Battery Shield and the WeMos A0 analog pin.  Allows 10bit A2D converter to monitor 0 to 4.2 Volts (Fully charged 18650 LiIon).

image

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@inq I would like to know why a 100K ohm resistor was used. I think you said you needed 0.9V dropped across it so 4.2 looked like 3.3. In that case the current must be 9 micro amps unless they rescinded ohms law.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  
Posted by: @zander

@inq I would like to know why a 100K ohm resistor was used. I think you said you needed 0.9V dropped across it so 4.2 looked like 3.3. In that case the current must be 9 micro amps unless they rescinded ohms law.

@inst-tech - Said so!  😆 That's my story until a better one comes around.

He also left a reference link a couple posts back that hopefully will educate me better on the subject.  Also a couple posts back, I explained I took his suggestion and tried it out using the bench power supply and incremented it in 0.01 volt increments and sure enough hit 1024 on the analogRead() method when the power supply showed 4.16V.

Slapped it in place, changed the Math in the Sketch and wa-la... nice smooth curve from 4.1V down to the battery shield shutting down.  

  1. When this thread started all I wanted was to have a way to keep from over discharging the battery, but turns out the Shield takes care of that at 2.5V
  2. I then wanted a near end warning (3.3V was good enough) so I could head "home" in time.
  3. But adding the 100 KΩ gives me the Full Monty.

Now, I can put a gas gauge dial on the UI remote control and know exactly where I am in the "fuel" tank. 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@inq Sorry to be a pest, but this is what a typical Lithium discharge curve looks like. You are only showing the last little bit. There should be a little more than 10x to at least 5x time elapsed prior to your curve. 

Screen Shot 2022 04 30 at 17.39.37

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Inst-Tech reacted
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  
Posted by: @zander

@inq Sorry to be a pest, but this is what a typical Lithium discharge curve looks like. You are only showing the last little bit. There should be a little more than 10x to at least 5x time elapsed prior to your curve. 

Screen Shot 2022 04 30 at 17.39.37

 

Not being a pest.  You're just making me think about it!

I was expecting something like that curve as well.  But there are several variables that are different in the way those curves are plotted.  

  • Those Voltage=f(SOC) curves are different than Voltage=f(time) 
  • State of Charge (SOC) is not anywhere near linear WRT time.
  • Those tests are performed at constant current... For most Lithium chemistries, they do it at 1C. 
  • The current draw from the battery shield at 5.0 volts is relatively constant, BUT the 18650 Shield is having to convert a variable voltage between 2.5 and 4.2 up to 5.0 Volts.  The efficiencies doing that are highly non-linear WRT supply voltage.
  • Besides the non-linear chip voltage conversions, there is also the fact at lower volts, more current has to be drawn to maintain the constant wattage the steppers are pulling.

 

Looking at it another way, the WeMos and steppers were drawing 5.0V * 600 mA * 2.42 hours = 7260 mAh.   

The battery that is at least 20 years old and wasn't fully charged (4.05V) and part of some laptop battery that was abused was rated when new at 3.6V * 2350 mAh = 8460 mAh.

Still retains 86% of original rated capacity.  Considering I didn't confirm the current draw during the test and the inefficiencies listed above, I'd say, that's a pretty good battery test.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

@inq I found this link to an ESP8266 specs..and thought you might want to take a look at it.

https://circuits4you.com/2019/01/13/esp8266-absolute-maximum-ratings/

I'm still researching exactly how the 100K in series with the ADC input works, but I'm inclined to think it's just another takeoff from the internal RVD in the ESP8266 providing a different reference voltage as far as the ADC is concerned. I'll keep at it until I can prove my theory..lol

Great work on that battery discharge curve....

regards,

LouisR

LouisR


   
Inq reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@inst-tech Thanks, most of that I knew, was there something specific you thought I would be interested in?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@inst-tech I am still skeptical that a single wire from the battery + to an analog pin works. If it does, patent it and sell it to Victron, but in the meanwhile if I really want to know what is happenigh with a bettery I will use a shunt. Almost every day I see people on the RV forums using voltage to determine the health or capacity of their batteries. 99% have it wrong. For RV use you need true deep discharge batteries. Most do not have them but as long as they are always in a park and plugged in no problems. When it becomes a problem is when there is a prolonged power outage or they decide to camp off grid. Any lead acid battery will be damaged to some degree if the SOC goes below 50%. The voltage at the unloaded terminals after a resting time of maybe an hour is 12.2V. Most will think it is over 12 so good. NO. dead or soon will be.

I did my own solar, spent 2 years studying so I feel I know batteries fairly well. I can't prove it and don't care to but that measuring trick makes no sense to me. However, maybe it works well enough for his purposes so ok.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  
Posted by: @inst-tech

I'm still researching exactly how the 100K in series with the ADC input works, but I'm inclined to think it's just another takeoff from the internal RVD in the ESP8266 providing a different reference voltage as far as the ADC is concerned. I'll keep at it until I can prove my theory..lol

I think, I'm starting to catch up with you.  I dug this up and added what I think we're doing by adding the 100 KΩ.  

VoltageDivider

Thus the Voltage Divider Formula becomes:

Vo = Vi * R2 / (R1 + R3 + R2)

Solving for R3:

R3 = (Vi / Vo - 1) * R2 - R1

Using the resistor values you found for the NodeMCU...

R1 = 220

R2 = 100

Vi = 4.2 Volts - Maximum voltage of a 18650 cell when fully charged.

Vo = 1.0 Volts - Maximum input voltage of the ESP8266 A2D 

Thus:  R3 = 100

Works like a charm!

VBR,

Inq

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech and Will reacted
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  
Posted by: @zander

Almost every day I see people on the RV forums using voltage to determine the health or capacity of their batteries. 99% have it wrong.

I understand you know what you are talking about.  And you are correct.  Using voltage to determine SOC... or battery health is a non-starter.  It is wrong.  

However, you are missing the point.  In this project, we are not looking to know how healthy the 18650 battery is.   It was originally to not over discharge the LiIon battery.  This is no longer the issue.  The Shield will not allow us to draw the battery down below 2.5 volts.  

Now, the issue is to know when the Shield is going to shut down the robot so that the human (or robot) can make a decision to recharge.  Determining the voltage is the only factor the Shield uses... therefore, it is the only one worth checking!

A shunt only measures current.  There is no useful information knowing how much current the Shield/Stepper Motors are drawing in this project.

Posted by: @zander

Most do not have them but as long as they are always in a park and plugged in no problems.

This is perfectly OK as long as the RV, boat... etc is using Lead-Acid batteries.  Which is by-far the most common.  Doing this to Lithium based batteries is the surest way to destroy them unless the power management system has smarts to disconnect the incoming supply line when it should.  But that is another story and not related to this thread.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@inq The reputable battery manufacturers all have BMS either internally or that comes with the battery. In my case even if I did constantly stay at 100% which I don't, it is still ok because the battery capacity is slightly understated. My cells are probably 105AH but I tell the battery monitor they are 100 plus I have solar and a very smart inverter so constantly vary the SOC. Because we often have power failures here at a certain time of year I keep the batteries more full, never less than 80 but in the sunny summer I will let them drop to 60 or even lower. With my master control I can program how much grid power to use, and if I was allowed to, even feed back and scheduled recharges to whatever SOC I choose. Lot's of programmability but with LiFePO4 the watch phrase is simply give em hell and that is from the VP of the company with a 10yr warranty. They might be considered 'dead' in 10 years but what that means is that the original 600AH is now 'only' 480AH which is still more than enough to keep me going for the better part of a sunny week.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Inst-Tech reacted
ReplyQuote
Page 3 / 4