Skip to content
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

adc.readvdd33() #2925

Closed
lmercucci opened this issue Sep 23, 2019 · 16 comments
Closed

adc.readvdd33() #2925

lmercucci opened this issue Sep 23, 2019 · 16 comments
Assignees
Labels

Comments

@lmercucci
Copy link

lmercucci commented Sep 23, 2019

adc.readvd33() not working....
in my init.lua have:

if adc.force_init_mode(adc.INIT_VDD33) then
  node.restart()
  return -- don't bother continuing, the restart is scheduled
end
print("System voltage (mV):", adc.readvdd33(0))

but

=adc.readvdd33()
=adc.readvdd33()
65535

@ildar
Copy link

ildar commented Sep 24, 2019 via email

@HHHartmann
Copy link
Member

That's exactly the example in the documentation. So this is a software or documentation bug.

@HHHartmann HHHartmann added the bug label Sep 24, 2019
@marcelstoer
Copy link
Member

According to our documentation (and the code) readvdd33() doesn't take any parameters. Yet, the code above and in the documentation calls it with 0.

@HHHartmann
Copy link
Member

For

NodeMCU 3.0.0.0 
	branch: dev
	commit: 0b90495517c8e2b34dbb3a2a99455ac3c4f05f1c

calling it with no argument yields the same result.

But for

NodeMCU 2.2.0.0 built with Docker provided by frightanic.com
	branch: dev
	commit: 5514475ab0b152eaa994495e6d034123ae811786

it returns 3015 which is what I would expect

@TerryE
Copy link
Collaborator

TerryE commented Sep 26, 2019

Doing a quick git diff 5514475a 0b904955 -- ../modules/adc.c shows that adc_sample() hasn't changed (except removing a trailing whitespace on the return). It's essentially a wrapper for system_get_vdd33() which only works if byte 107 of esp_init_data_default.bin is set as 0xFF, and this in turn breaks the read() function.
xxd -s 107 -l 1 sdk/esp_iot_sdk_v3.0-e4434aa/bin/esp_init_data_default_v05.bin returns 0, so it shouldn't work by default. If we want it to work by default we need to override byte 107.

@marcelstoer
Copy link
Member

If we want it to work by default we need to override byte 107.

Hhm, that's what adc.force_init_mode() i.e. adc_init107() does - or used to do. However, git blame shows it hasn't changed in years, either.

If the test script keeps rebooting the device it means that adc_init107() detects that byte 107 isn't 0xFF but it fails to overwrite it.

@HHHartmann
Copy link
Member

adc.force_init_mode returns true for the first call only.

@TerryE
Copy link
Collaborator

TerryE commented Sep 26, 2019

Oops. Definitely bug. I missed adc.c:L132. The Phy Data sector is no longer at END-4. We need to read its address from the PT

  partition_item_t pt = {0,0,0};
  system_partition_get_item(SYSTEM_PARTITION_PHY_DATA, &pt);

@TerryE
Copy link
Collaborator

TerryE commented Nov 17, 2019

I have fixed this in my working directory and will add this fix to my #2912 next commit.

@Michal78S
Copy link

Please clarify this: adc.readvdd33(0) returns system voltage in milivolts, but adc.read(0) returns what?
Voltage on ADC pin in milivolts or direct convertion resulst in range of 0-1024?

@ildar
Copy link

ildar commented Dec 13, 2019 via email

@Michal78S
Copy link

Are You siure?
I got as below:

mV ADC
0 14
100 114
500 525
963 1000
986 1024
So 14 is ADC offset, and then when substracted offset I got exacly 977 for 1V. It is the same when divide 1000mV/1024.

@jmd13391
Copy link

@Michal78S The ESP8266 ADC has inherent stability issues as a result of an internal hardware design flaw. You may find some of 2864 and esp8266/Arduino:2070 relevant.

@rptnscz
Copy link

rptnscz commented Jan 5, 2020

According to our documentation (and the code) readvdd33() doesn't take any parameters. Yet, the code above and in the documentation calls it with 0.

There are two examples in the doc https://nodemcu.readthedocs.io/en/master/modules/adc/
The example in adc.force_init_mode() chapter shows 'readvdd33(0)' with '0' as a parameter.
But in adc.readvdd33() the syntax is without any parameters.

Anyway both doesn't work in the branch master.

@TerryE: how can i checkout your fix of the bug? I guess there are no change in adc.c module.

@marcelstoer
Copy link
Member

@rptnscz maybe this one 32e161b#diff-1925935f8d24083ba3e86383f92b7ea8 It's a bit unfortunate that many fixes went into that branch (rather than dev) but that's just how it is. Please be patient.

@TerryE
Copy link
Collaborator

TerryE commented May 29, 2020

Fixed in #3075

@TerryE TerryE closed this as completed May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants