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 voltage calculation incorrect #55

Closed
whitfijs-jw opened this issue Mar 6, 2024 · 0 comments · Fixed by #56
Closed

ADC voltage calculation incorrect #55

whitfijs-jw opened this issue Mar 6, 2024 · 0 comments · Fixed by #56
Assignees

Comments

@whitfijs-jw
Copy link
Owner

In adc.h:

/* 5V inputs go through voltage divider for 3.3V ADC inputs -- not quite 100% */
static constexpr double REFERENCE_VOLTAGE_DIVIDER = (15.0e3 / (15.0e3 + 8.2e3));
static constexpr double INPUT_VOLTAGE_DIVIDER = (15.0e3 / (15.0e3 + 8.2e3));
static constexpr double VOLTAGE_CONVERSION_CORRECTION_FACTOR = 3.3 / (INPUT_VOLTAGE_DIVIDER * 5.0); 

farther down:

    /**
     * @brief Read scaled ADC value
     * @param channel: adc channel to read
     * @return current measured voltage
     */
    double readValue(int channel, double vRef = -1) {
        double volts = ((double)readRawValue(channel) / (double)mMaxVal);

        if (vRef < 0) {
            updateReference();
            return volts * mVref * VOLTAGE_CONVERSION_CORRECTION_FACTOR;
        } else {
            return volts * vRef;
        }
    }

Not sure what happened but the multiplication by mVref and division by 5.0 are superfluous and introduce a small error.

@whitfijs-jw whitfijs-jw linked a pull request Mar 6, 2024 that will close this issue
@whitfijs-jw whitfijs-jw self-assigned this Mar 8, 2024
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

Successfully merging a pull request may close this issue.

1 participant