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

[FR] ADC tuning regarding the vcc input #18420

Open
ShadowOfTheDamn opened this issue Jun 25, 2020 · 4 comments
Open

[FR] ADC tuning regarding the vcc input #18420

ShadowOfTheDamn opened this issue Jun 25, 2020 · 4 comments
Labels
T: Feature Request Features requested by users.

Comments

@ShadowOfTheDamn
Copy link

ShadowOfTheDamn commented Jun 25, 2020

Description

ADC needs to be tuned with regards to the input voltage
this feature should be implemented on the core of the marlin, regarding the analogue data reads like temperature sensor reads and so on. As you know Arduino boards does not have a reference voltage pin connected and so the controller will use the Vcc as the V_ref for ADC conversions. this will result in imprecise readings of the analogue input.
there is a video on the you-tube channel "Andreas Spiess" with the following link: https://www.youtube.com/watch?v=UAJMLTzrM9Q
in this link it is explained why the ADC is imprecise on many controllers regarding the reference voltage sampling and a code is suggested for somehow correcting the current ADC result for super precise measurements
please consider this for more accurate temperature readings on all hardware.

Additional Information

Video showing the way ADC work on ESP8266, ESP32 and Arduino micro-controllers as well as external ADC boards

https://www.youtube.com/watch?v=UAJMLTzrM9Q

Video of the code in use for precise ADC measurements

https://www.youtube.com/watch?v=xI_qU2auVx8

Sample code of the previous Video

https://github.com/SensorsIot/ADC_Test/

@thisiskeithb thisiskeithb added the T: Feature Request Features requested by users. label Jun 25, 2020
@ellensp
Copy link
Contributor

ellensp commented Jun 25, 2020

This mostly does not apply to our 3d printers.
This applies to measuring external voltages. The voltages we measure are derived from the same vcc that is applied to the a_ref

eg thermistors. Basically a voltage divider. 4.7k fixed with a variable resistor that is the thermistor.
Ie this
voltage dividers

let presume that the thermistor is also reading 4.7k to make the math simple

So the math becomes Vout = Vin/2
Vin = 5v => Vout 2.5v so half the a_ref voltage so you get max adc value/2 ie 1024/2 512
now we drop the voltage
Vin = 4v => Vout 2v so half the a_ref voltage so you get max adc value/2 ie still 512

The result in the same temperature reading.

@AnHardt
Copy link
Contributor

AnHardt commented Jun 25, 2020

That's right as long we are measuring resistor relations.
But there are a few cases where we are indeed measuring voltages directly. For example when we use tables 20 or 21, -1 or -4. And the we are in trouble. There switching the power supply for the processor from USB to an other voltage regulator usually makes a noticeable difference.

@AnHardt
Copy link
Contributor

AnHardt commented Jun 30, 2020

Additionally to the already provided solution for the AVRs i could find a solution for the STM32s using stm32duino.

@AnHardt
Copy link
Contributor

AnHardt commented Jun 30, 2020

The best exactness could be achieved by handling the Vref-channel like the other ADC-pins, in every loop over the pins.
A far less performance intensive variation could be to test Vref only one during startup. This would at least be able to handle the big differences when running from different sources for the power.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: Feature Request Features requested by users.
Projects
None yet
Development

No branches or pull requests

4 participants