Esempio n. 1
0
void voltageMeterADCRefresh(void)
{
    for (uint8_t i = 0; i < MAX_VOLTAGE_SENSOR_ADC && i < ARRAYLEN(voltageMeterAdcChannelMap); i++) {
        voltageMeterADCState_t *state = &voltageMeterADCStates[i];
#ifdef USE_ADC
        // store the battery voltage with some other recent battery voltage readings

        const voltageSensorADCConfig_t *config = voltageSensorADCConfig(i);

        uint8_t channel = voltageMeterAdcChannelMap[i];
        uint16_t rawSample = adcGetChannel(channel);

        uint16_t filteredSample = biquadFilterApply(&state->filter, rawSample);

        // always calculate the latest voltage, see getLatestVoltage() which does the calculation on demand.
        state->voltageFiltered = voltageAdcToVoltage(filteredSample, config);
        state->voltageUnfiltered = voltageAdcToVoltage(rawSample, config);
#else
        UNUSED(voltageAdcToVoltage);

        state->voltageFiltered = 0;
        state->voltageUnfiltered = 0;
#endif
    }
}
Esempio n. 2
0
// unfiltered - always recalcualates voltage based on last adc sensor reading
uint16_t getLatestVoltageForADCChannel(uint8_t channel)
{
    for (uint8_t i = 0; i < MAX_VOLTAGE_METERS && i < ARRAYLEN(voltageMeterAdcChannelMap); i++) {
        if (voltageMeterAdcChannelMap[i] == channel) {
            voltageMeterState_t *state = &voltageMeterStates[i];
            voltageMeterConfig_t *config = voltageMeterConfig(i);

            return voltageAdcToVoltage(state->vbatLatestADC, config);
        }
    }

    failureMode(FAILURE_DEVELOPER);

    return 0;
}
Esempio n. 3
0
void voltageMeterUpdate(void)
{
    uint16_t vbatSample;

    for (uint8_t i = 0; i < MAX_VOLTAGE_METERS && i < ARRAYLEN(voltageMeterAdcChannelMap); i++) {
        // store the battery voltage with some other recent battery voltage readings

        voltageMeterState_t *state = &voltageMeterStates[i];
        voltageMeterConfig_t *config = voltageMeterConfig(i);

        uint8_t channel = voltageMeterAdcChannelMap[i];
        vbatSample = state->vbatLatestADC = adcGetChannel(channel);

        vbatSample = biquadFilterApply(&state->vbatFilterState, vbatSample);

        // always calculate the latest voltage, see getLatestVoltage() which does the calculation on demand.
        state->vbat = voltageAdcToVoltage(vbatSample, config);
    }
}