Skip to content

getVCCV() in the AnalogRead example calculates wrong values #303

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

Closed
idea--list opened this issue Dec 6, 2020 · 0 comments
Closed

getVCCV() in the AnalogRead example calculates wrong values #303

idea--list opened this issue Dec 6, 2020 · 0 comments
Milestone

Comments

@idea--list
Copy link

idea--list commented Dec 6, 2020

I am playing around with Arduino Core V2.0.2. My board is connected to the PC via the USB cable and i get this in the serial monitor:
image

One can see that the vcc/3 values are around 36700. Assuming 14-bit ADC resolution and 2.0V as reference we can calculate the voltage like that 36700/16384 * 2.0 = 4,4799V

However supply_V is reported to be around 13,4V. If that was true, then i would have the original Sparkfun experience 💥 😉
I believe float getVCCV(void) { return ((float)analogReadVCCDiv3() * 6.0) / 16384.0; } is wrong, as the reference voltage is not 6.0.

By changing that to float getVCCV(void) { return ((float)analogReadVCCDiv3() * 2.0) / 16384.0; } i get supply voltage values of 4,46666 V which is much more creditable. Actually my potentiometer measures 4,282 V on the VBAT pin.

Would be even nicer to actually fetch the reference voltage setting from the ADC CFG register (REFSEL field) once while booting up and store that value for later usage within getVCCV().

@ghost ghost added this to the v2.1.0 milestone Mar 2, 2021
@Wenn0101 Wenn0101 modified the milestones: v2.1.0, v2.0.6 Mar 16, 2021
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