-
I think you could stil use the built-in ADC, if you requirement for precision is not extreme (like with 1% error). But you have to compensate the errors of the ADC.
a) the zero point. look at which input voltage the output is different to zero. According to a comment below, this is somewhat like 0.1 V
b) the scaling: Look at which input voltage the output just reaches the maximum value.
c) nonlinearity. You could make a compensation table, or ignore it, if it is small enough and outside the range of interest.
d) Noise
a) and b) is easily compensated for. d) is reduced with taking an average of many samples, like you did. You do not have to wait a second between the samples. A few ms is sufficient, if at all, and a small capacitor like 10 nF with short leads directly at the ADC helps.Another observation: You connect the NTC to 3.2 V (are you sure it's not 3.3V?). The ADC max range is at 3.6 V, the reading at 3.2 V would be 3631. Instead of 4095, you should therefore use 3631 as the virtual maximum value. Then, the resistor value is 9793 (10412 for 3.3 V), which is 2% off the nominal value, and depending of the precision class of the resistor that could be the real value.
-
@robert-hh said in NTC temperature sensor:
if you requirement for precision is not extreme (like with 1% error)
There is no exterme precision requirement. 1% would be completely fine.
a) the zero point. look at which input voltage the output is different to zero. According to a comment below, this is somewhat like 0.1 V
b) the scaling: Look at which input voltage the output just reaches the maximum value.
c) nonlinearity. You could make a compensation table, or ignore it, if it is small enough and outside the range of interest.
d) Noise
a) and b) is easily compensated for. d) is reduced with taking an average of many samples, like you did. You do not have to wait a second in between, and a small capacitor like 10 nF with short leads directly at the ADC helps.Thanks for the inputs!
Another observation: You connect the NTC to 3.2 V (are you sure it's not 3.3V?).
It is connected to 3V3, so it is of course 3.3V. I've chosen 3.2V for
Vinin the second equation because of the parameterattn=3. I've read that in this threads: https://forum.pycom.io/topic/226/lopy-adcs and here https://forum.pycom.io/topic/602/ntc-temperature-sensor/6The ADC max range is at 3.6 V, the reading at 3.2 V would be 3631. Instead of 4095, you should therefore use 3631 as the virtual maximum value. Then, the resistor value is 9793 (10412 for 3.3 V), which is 2% off the nominal value, and depending of the precision class of the resistor that could be the real value.
Interesting. I must have missed this information in the documentation, I thought 3.3V is the maximum.
-
As always, the information given by espressif is poor. Nothing compared to the manuals issued for instance by Atmel, STM or Freescale. It is unclear, how much the attenuation level really is, some say 11db, some say 12 db. 11db would be a factor 3.55, 12 db a factor 3,98 (10**(atten/20)) of the base range, which is ?. In any case, better give it a try. If you have a voltage meter, get the value at the input and scale it by:
Vrange = Vinput * (4095/reading)
-
So I gave it a try, connected a power source to the input and read the average of 100 samples each. The results are not convincing.
a) Even at an average of 100 samples, there is a lot of noise..
b) it looks pretty nonlinear., at least at attn 3
results:attn = 3 value 0 until 125 mV 107 mV -> 0 200 mV -> 95 300 mV -> 215 500 mV -> 455 700 mV -> 700 1000 mV -> 1070 1500 mV -> 1700 1600 mV -> 1815 2000 mV -> 2310 2500 mV -> 2930 2900 mV -> 3540 3000 mV -> 3740 3100 mV -> 3955 3170 mV -> 4095 attn = 0 Value 0 until 57 mV 100 mV -> 127 200 mV -> 550 300 mV -> 974 500 mV -> 1820 700 mV -> 2650 900 mV -> 3510 1000 mV -> 3933 1044 mV -> 4095If you look at that in a graph, at attn 3 the bends up beyond 2.5 V, while the attn=0 graph looks more linear, besides the 0-Offset.
That's worse than I expected. The best one can get is to work with attn = 0 and use an external voltage divider.
Edit: I found a link that shows an experience, which pretty much matches mine:
http://www.esp32.com/viewtopic.php?t=1045
The Figures I got are pretty much the same. So 6db attn would be an option too. -
@robert-hh
this is an open issue on ESP-IDF and also the Arduino corehttps://github.com/espressif/esp-idf/issues/164
https://github.com/espressif/arduino-esp32/issues/92The official response from Espressif is:
The ADC frontend indeed has a non-linear response. Once characterization data is ready, we will take it into account inside ADC APIs, and update the datasheet with correct values of INL/DNL and effective resolution.
So any efforts to compensate it at this stage will likely be rendered useless in a future update once the characterisation is complete (at least at ESP-IDF/MicroPython level)
That's also why I suggested an external ADC for the time being, at least that won't change.
-
@jmarcelino: Yes, Ive read that. But you would still have to compensate for the non-zero range (at least in your circuit). So at the moment and with limited requirements for precision, using the lower attenuation variants 0 and 6db and simply adding an offset would be sufficient as compensation.
If you need precise values, yes, then an external ADC is anyhow recommended.
B.T.W. Is there still the option to use the ADC in 10 bit mode, like by an option res = xx in the channel set-up?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login