board: f1_dual: add way to measure battery through Heater-

This commit is contained in:
Andrey Gusakov 2022-06-05 19:48:33 +03:00
parent 6becb28cd1
commit ab20b65550
2 changed files with 20 additions and 2 deletions

View File

@ -33,6 +33,14 @@
#define HEATER_PWM_DEVICE PWMD4
#define HEATER_PWM_CHANNEL 0
// PB7
#define L_HEATER_PORT GPIOB
#define L_HEATER_PIN 7
// PB6
#define R_HEATER_PORT GPIOB
#define R_HEATER_PIN 6
// PA1 TIM2_CH2
#define PUMP_DAC_PWM_DEVICE PWMD2
#define PUMP_DAC_PWM_CHANNEL 1

View File

@ -60,10 +60,20 @@ static float AverageSamples(adcsample_t* buffer, size_t idx)
return (float)sum * scale;
}
static float l_vbatt = 0.0, r_vbatt = 0.0;
AnalogResult AnalogSample()
{
bool l_heater = !palReadPad(L_HEATER_PORT, L_HEATER_PIN);
bool r_heater = !palReadPad(R_HEATER_PORT, R_HEATER_PIN);
adcConvert(&ADCD1, &convGroup, adcBuffer, ADC_OVERSAMPLE);
if ((l_heater) && (!palReadPad(L_HEATER_PORT, L_HEATER_PIN)))
l_vbatt = AverageSamples(adcBuffer, 6) / BATTERY_INPUT_DIVIDER;
if ((r_heater) && (!palReadPad(R_HEATER_PORT, R_HEATER_PIN)))
r_vbatt = AverageSamples(adcBuffer, 7) / BATTERY_INPUT_DIVIDER;
return
{
.ch = {
@ -71,13 +81,13 @@ AnalogResult AnalogSample()
/* left */
.NernstVoltage = AverageSamples(adcBuffer, 3) * NERNST_INPUT_GAIN,
.PumpCurrentVoltage = AverageSamples(adcBuffer, 2),
.BatteryVoltage = AverageSamples(adcBuffer, 6) / BATTERY_INPUT_DIVIDER,
.BatteryVoltage = l_vbatt,
},
{
/* right */
.NernstVoltage = AverageSamples(adcBuffer, 1) * NERNST_INPUT_GAIN,
.PumpCurrentVoltage = AverageSamples(adcBuffer, 0),
.BatteryVoltage = AverageSamples(adcBuffer, 7) / BATTERY_INPUT_DIVIDER,
.BatteryVoltage = r_vbatt,
},
},
/* Dual board has separate internal virtual ground = 3.3V / 2