whitfijs-jw / Volvo240-DigitalDash

Volvo 240 Digital Dash Project. It's not much, but its honest work.
MIT License
43 stars 6 forks source link

ADC voltage calculation incorrect #55

Closed whitfijs-jw closed 7 months ago

whitfijs-jw commented 7 months ago

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.