-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fluctuating ADC with stabilized source #2070
Comments
Full code, when logging to the IDE's Serial Plotter:
I've had this code running for a few hours on a ESP with only the 2 resistors on the A0, one connected to Gnd and one connected to an LM1117 3.3v output. |
I've set up a circuit to test this, so far I'm getting readings within 1 LSB of average. The thing will run for a few hours, and I'll post a graph by end of day. Here's my schematic, for the record: |
@igrr , I think I made some progress.
Then I noticed that after a reset, it was stable for only a few seconds. Then I added the So this issue is related to WiFi. |
To me, this looks like the power draw from WiFi is distorting the onboard ADC. |
Using an 'external' adc is not an option for my setup, simply because I don't have any empty usable digital pins left on the module. How could I control the sample timing? |
Until now I have this as a work-around to do a reading every minute:
Only this introduces another issue, that the ESP doesn't always (re)connect to wifi causing it to hang. |
I have the issue with 3 NodeMCU boards, so I tried to find out if it was perhaps related to the small power regulator on those board. Instead of powering over usb or with an external 5V powersupply to the Vin pin, I now used a LM1117 3.3V reguator to supply to the 3.3V of the board. (thus bypassing the small onboard voltage regulator) |
Same problem for me see: http://bbs.espressif.com/viewtopic.php?f=66&t=2286&p=7367#p7367 Even tried battery powered and entire Board shielded with foil. After wifi.disconnect() the reading is ok! |
Btw as for me I also have no pins for external ADC which probably would be the best choice. |
Isn't there a way to check if wifi is transmitting and poll the ADC when it's not? |
same problem here... is there a way to "pause" the wifi radio without really disconnecting? |
Simply tested that. The resulting analogRead looks stable. |
Another Thing I noticed.... When using Blynk App in my sketch and doing Blynk.Write every 100ms it seems to be stable as well so the unstability might be just when Wifi starts or stops transmitting. |
I also noticed it just starts getting wrong readings once it seems the WIFI connection has been established the first time (some seconds after powerup). It then gets wrong radings in the range 1-7 above (always!) the correct reading with seldom a correct reading in between. If I put AIN to GND I get readings 0-1 which schould be normal but as soon as the connection is established the readings are 0-7 where most of them are in the 5-7 range. I now used a sketch to read for some time and only use the lowest reading which works but is VERY slow because as soon as I sample readings for less than around 100ms it seems to miss the seldom correct (low) readings and I get wrong ones sometimes in my result.
BTW... I also use the same voltage regulator, maybe a problem with that one (LM1117V33)? I also found this (09bb758) and would like to try if that's solving my problen but don't know how. Just integrating it in my sketch doresn't seem to work. Any advice? REMARK: If the ESP has established a connection once it automatically will after powerup so you will see this problen only if the ESP has been connected before or if it gets connected by WiFi.begin() command Closed my other Issue since it's the same as this. |
@Gorkde I think that code fails on @igrr I have tested it with the latest GIT version, which includes SDK 1.5.4. In the rellease notes of that SDK is a note about a fix of analogread: |
I wrote that piece of code to make my sketch work until the issue is fixed. When I do analogread I found the readings always go up from the correct reading. Therefore I wrote a read function that samples readings an just uses the lowest of them because that's the correct reading. But as I said, it's just for the time being until the issue is fixed. Maybe this is an hardware issue of the modules we have or the voltage regulator? Which one do you use? |
Did some further investigation. When printing in Serial plotter it's easy to see the readings are +/-1 which should be normal but once the Wifi is enabled and connected it seems to have a constant minimal positive voltage offset that's causing the problem (no longterm fluctuations fir me, they probably are Vcc related). So I get 6 +/-1 from then on most of the time. Tried some Capacitors (100nF and/or 10uF) soldierd directly to Vcc/GND, as well GPIO0, GPIO2, GPIO15 to GND. Same readings. Therfore I really don't think thats a voltage regulator issue, maybe defective Modules or really some kind of bug in ADC. @igrr @Others |
I tested with an ESP8266 mounted onto a test board, I can repeat with a NodeMCU which has ESP12F on it. Could you please post your sketch so that our tests happens in the same conditions? |
ADC is Grounded and reading should be 0/1 Once I do WiFi.disconnect() every reading is ok again.
|
I mounted my ESP on a pcb along with 100nF (also tried 10uF additional) which is plugged in my breadboard. Voltage is supported by a LM1117V33 with 100nF input and 10uF or 470uF at the output (tried all possible means). VCC of the ESP is connected by a switch (tried with direct connection as well, same result). Also tried on a seperate Breadboard with no other Hardware than Voltage regulator ESP and Caps. While testing I also noticed the ESP-VCC drops from 3.3V to 3.2 or even 3.0 (at random for each start) as I apply VCC to the ESP (no matter what, the voltage regulator cannot get it up again). Even with very big capacitors directly at ESP-VCC and Voltage regulator directly at the ESP the Voltage drops. My Voltage regulator is supplied by an 1A power adapter which I tried setting to lower or higher voltage. Doesen't change anything. Also the input voltage doesn't break in below 7V so that's not the problem. Tried another power adapter as well, no change. The Voltage regulator is rated 800mA so either the ESP is drawing more than that (which shouldnt be the case) or there's some other thing going on that I can't locate with my means of measuring. But as soon as WiFi connects the voltage goes up to normal 3.3V again. So at the mysterious voltage drop before connecting I get correct readings (also when ADC is not Grounded but set to any voltage like 0,5V) but when WiFi connects and VCC gets to normal the reading starts getting an offset. I got no parts here to try ESP12E or another voltage regulator but ordered them. This will take 3 at least 3 weeks until they arrive. |
For what I can measure the ESP draws around 20-70mA |
Have you tried with a simple condenser? |
The noise is not random and does not average around the true value. So a capacitor will not necessarily provide the correct result. If it were consistent then it would be easier to compensate for the deviations. |
My findings for this were that the internal WiFi circuitry is coupling to the ADC reference of the ADC. I might try use it without turning off Wifi and computing the results... Also, why is the minimum value the correct one? All my tests show that the highest one is the correct one. Unless my LiPo batter really is dropping to 2.3V and up to 3.7V :-p Note: I am not using Arduino. I use the ESP8266_NONOS_SDK_V2.0.0 I will try to look for some way to interrupt the ic when its not drawing current, like the start of an incoming WiFi packet, assuming its synchronous. Or Does anyone know how the WiFi circuity can be properly decoupled from the ADC? |
OK.. My ideas worked with varying degrees if failure.. I next tried to use wifi_status_led_install() to toggle a pin based on activity, then only used the ADC when that pin was low.. Which again worked, but not as well as i would have expected if that was the issue. So i tried to hold the CH_PD pin low, which helped a lot, since my design was toggling GPIO14 next to CH_PD, there was noise coupling onto CD_PD and the IC was slowing or stuttering for a bit which was one issue. I then thought "what if my big fat capacitor does need to be closer to the module?" Anyway.. My statement above was wrong. And i did have supply decoupling issues. |
I think it is a hardware problem due to the floating nature. It is like we need a clean reference via a diode... Not saying it can't be accomplished via software just over my head. ;/ |
Closing this, because so far I don't really see a possible action within the core. If that changes, please open a new issue with the relevant details, and reference this one. |
So everyone gave up having a stabilised ADC on the ESP8266? |
My issues were related to interrupts firing and sleep states. From memory, when I put the ADC conversion code inside a task, instead of an interrupt handler, all was OK. And I added proper decoupling capacitors. The ones I was using were not small enough. |
Yeah, I gave up and used an external adc. I only needed one input, too. Super sad. looking for a different chip to produce my product. Amazing insight in this thread, but we need a stable pin with wifi on. |
Not really given up, just stopped discussing for a while. |
This was from an ESP-07 and I can't seem to find a way to have "not too bad" results :-| |
OK got something not too bad with a 0.1uF cap between the ADC and GND... not perfect but much better so far. |
Does this stabilize the readings? For my purposes consistency is more
important an precise accuracy.
Thanks for the update!!
…On Wed, Sep 12, 2018, 12:24 Pierrick Brossin ***@***.***> wrote:
OK got something not too bad with a 0.1uF cap between the ADC and GND...
not perfect but much better so far.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2070 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALAHUZS1NG36ZVoMLV8zB0HdSC8GVjNjks5uaV9cgaJpZM4Ipuna>
.
|
Just removed one of the cap to use an external antenna instead: And it seems to also improve things... There are still weird results though: |
Just gave an ADS1115 a try and it's damn stable :-) |
I finally got pretty stable results using... extern "C" {
#include "user_interface.h"
}
int getAnalog() {
unsigned int total = 0;
wifi_set_opmode(NULL_MODE);
system_soft_wdt_stop();
ets_intr_lock( );
noInterrupts();
total = system_adc_read();
interrupts();
ets_intr_unlock();
system_soft_wdt_restart();
return total;
} |
…sor values is taken -> see esp8266/Arduino#2070, Updated to ESP 2.6.3 version for the .bin file
…e logFileSplitSize (which is currently set to 9kb) -> meaning log file grows up to 11kb and is then shortend to 9kb and so on Bin File: ESP8266 Arduino Board Config updated to 2.7.0 Internal: Moved back to readable hmtl sites within code (enough ram availble) System: LogFiles reworked for better readablity with a uniform timeStamp at the beginning BugFix: Starting Robi although not within the given Mow from to timeframe Sensor readings: Reduced to 70 to take the smallest one -> see bug: esp8266/Arduino#2070 Sensor readings: Update frequency set to every 3 sec instead of previous 5 sec
After a lot of research i found out that the flucuating reading on pin A0 only appears if delay is used in the code. If timing is done with a non blocking pattern, the readings of pin A0 are stable. Here are my code examples and the resulting values Using delay:
Using a non blocking pattern:
I hope this can be useful for you |
Adding to this: Yielding for some time before reading pin A0 also results in more stable readings.
|
@BetaAthe Thank You, I love you |
I supply the ADC with a stable voltage, supplied by a separate LM1117 3.3V with 100uF capacitor a resistor voltage divider. The LM1117 will provide 3.3V regardless of the load of the ESP's own voltage regulator, the capacitor takes away any noise and the 2 resistors make a fixed voltage suitable to be read by the ADC.
(GND for both the ESP and the LM1117 are connected)
Then, based on this article, I tried to add more stability to the readings:
https://www.quora.com/Why-is-a-little-delay-needed-after-analogRead-in-Arduino
So I do subsequent readings and only use the last one. I even do it 3 times instead of 2, and then only use the last one because that one is supposed to be stable.
Readings are done and stored every minute.
The ADC reading has 2 fluctuations, a slow drift and spikes.
This show the ADC output:
This has been tested with the mentioned 'external' 3.3V regulator and with the 3.3V output from the ESP itself. I also tried with or without the subsequent readings. I don't really mind the spikes because I can add some code to flatten those, but the "long" wave-like fluctuation makes it all useless.
(I need this to read an MQ135 sensor.)
Using current core stable and Arduino IDE 1.6.9.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: