f1_dual: sample PWM pins first than do math (#190)

Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
rusefillc 2023-02-04 21:21:22 -05:00 committed by GitHub
parent 6831f5a1ae
commit 6d908fb110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -89,13 +89,16 @@ AnalogResult AnalogSample()
adcConvert(&ADCD1, &convGroup, adcBuffer, ADC_OVERSAMPLE);
if ((l_heater) && (!palReadPad(L_HEATER_PORT, L_HEATER_PIN)))
bool l_heater_new = !palReadPad(L_HEATER_PORT, L_HEATER_PIN);
bool r_heater_new = !palReadPad(R_HEATER_PORT, R_HEATER_PIN);
if (l_heater && l_heater_new)
{
float vbatt_raw = GetMaxSample(adcBuffer, 6) / BATTERY_INPUT_DIVIDER;
l_vbatt = BATTERY_FILTER_ALPHA * vbatt_raw + (1.0 - BATTERY_FILTER_ALPHA) * l_vbatt;
}
if ((r_heater) && (!palReadPad(R_HEATER_PORT, R_HEATER_PIN)))
if (r_heater && r_heater_new)
{
float vbatt_raw = GetMaxSample(adcBuffer, 7) / BATTERY_INPUT_DIVIDER;
r_vbatt = BATTERY_FILTER_ALPHA * vbatt_raw + (1.0 - BATTERY_FILTER_ALPHA) * r_vbatt;