Skip to content

ADC reading differs if WAKE_RF_DISABLED is used in deepSleep() command #8728

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

Open
5 tasks done
tjb36 opened this issue Nov 24, 2022 · 1 comment
Open
5 tasks done

Comments

@tjb36
Copy link

tjb36 commented Nov 24, 2022

Problem Description (basic info below)

When periodically waking the chip from deep sleep in order to read the ADC pin, I measure a different behaviour depending on whether the WAKE_RF_DISABLED flag is passed to the ESP.deepSleep() command.

The voltage is applied to the ADC pin using an external bench top power supply (to ensure low output impedance), and its value is checked using a floating precision multimeter. Below is the ADC response depending on whether the WAKE_RF_DISABLED flag is passed or not (red and blue lines, respectively):

In addition to this, when the WAKE_RF_DISABLED flag is passed, the value read on the first boot up after power on is actually the same as the case when the WAKE_RF_DISABLED flag is not passed. But then all susequent wakes from deep sleep give a different value. These two values are marked on the graph above as green cross and purple circle, respectively.

Hardware connections:

GPIO15 --> pulled to GND with 5k resistor
GPIO2 --> pulled to VCC with 5k resistor
RST connected to GPIO16 (for deep sleep)
CHIP_EN --> pulled to VCC with 5k resistor

Stable 3.3V VCC is provided by MCP1700 linear regulator.

The only reference I could find to a similar problem is in this comment.

MCVE Sketch

#include <ESP8266WiFi.h>

void setup() {

  // TURN OFF WIFI //////////////////////////
  WiFi.mode( WIFI_OFF );
  WiFi.forceSleepBegin();
  delay(1);
  ///////////////////////////////////////////

  Serial.begin(74880);
  delay(1000);

  // TAKE AVERAGE OF x5 ADC READINGS ////////
  int adc;
  float avrg_cnt = 0.0;
  int i = 0;
  while (i<5) {
    adc = analogRead(A0);
    Serial.println(adc);
    avrg_cnt = avrg_cnt + float(adc);
    i = i + 1;
    delay(1);
  }
  Serial.println(avrg_cnt/5.0 , 1);
  ///////////////////////////////////////////

  // TURN ON WIFI ///////////////////////////
  WiFi.forceSleepWake();
  delay( 1 );
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin($$SSID$$, $$PASSWORD$$);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(10);
  }
  Serial.println("Connected");
  ///////////////////////////////////////////

  delay(1000);
  
  // TURN OFF WIFI //////////////////////////
  WiFi.disconnect( true );
  delay(1);
  ESP.deepSleep(1e6, WAKE_RF_DISABLED); // Removing WAKE_RF_DISABLED changes ADC behaviour
  ///////////////////////////////////////////
}

void loop() {
  
}

Debug Messages

Below is the output of the very first ADC read after power on, and the second read after waking from deep sleep with the WAKE_RF_DISABLED flag :

ADC counts:
944
944
944
944
944
Average: 944.0
Connecting
Connected

ADC counts:
1018
1018
1018
1018
1018
Average: 1018.0
Connecting
Connected

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • [] If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12E
  • Core Version: 3.0.2
  • Development Env: Arduino IDE 1.8.19
  • Operating System: Windows

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: DOUT (compatible)
  • Flash Size: 1MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200
@dok-net
Copy link
Contributor

dok-net commented Mar 12, 2023

Please refer to https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf, section 3.3.11 and 3.3.12. VDD33 calibration is part of the RF calibration, this would account for your different measurements.

Please check out #8783 for guidance on how to change the calibration behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants