sample battery voltage

This commit is contained in:
Matthew Kennedy 2022-04-06 01:07:18 -07:00
parent b6985f6416
commit b838c414fa
4 changed files with 8 additions and 4 deletions

View File

@ -45,6 +45,7 @@ AnalogResult AnalogSample()
.NernstVoltage = AverageSamples(adcBuffer, 0) * NERNST_INPUT_GAIN,
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
.VirtualGroundVoltageInt = AverageSamples(adcBuffer, 2),
.BatteryVoltage = 0,
};
}

View File

@ -192,6 +192,7 @@
* PA2 - Vm_sense (analog in).
* PA3 - Un_sense (analog in).
* PA4 - Vm (analog in, unused).
* PA5 - Battery sense (analog in).
* PA8 - Green LED (output pushpull).
* PA9 - UART TX (output pushpull, alternate).
* PA10 - UART RX (digital input, alternate).
@ -200,7 +201,7 @@
* PA13 - Pull-up input (GPIOA_SWDIO).
* PA14 - Pull-down input (GPIOA_SWCLK).
*/
#define VAL_GPIOACRL 0x88800020 /* PA7...PA0 */
#define VAL_GPIOACRL 0x88000020 /* PA7...PA0 */
#define VAL_GPIOACRH 0x888B88B2 /* PA15...PA8 */
#define VAL_GPIOAODR 0xFFFFFFFF

View File

@ -5,7 +5,7 @@
#include "hal.h"
#define ADC_CHANNEL_COUNT 3
#define ADC_CHANNEL_COUNT 4
#define ADC_SAMPLE ADC_SAMPLE_7P5
static adcsample_t adcBuffer[ADC_CHANNEL_COUNT * ADC_OVERSAMPLE];
@ -20,11 +20,11 @@ ADCConversionGroup convGroup =
// SMPR1
0,
// SMPR2
ADC_SMPR2_SMP_AN3(ADC_SAMPLE) | ADC_SMPR2_SMP_AN0(ADC_SAMPLE) | ADC_SMPR2_SMP_AN2(ADC_SAMPLE),
ADC_SMPR2_SMP_AN3(ADC_SAMPLE) | ADC_SMPR2_SMP_AN0(ADC_SAMPLE) | ADC_SMPR2_SMP_AN2(ADC_SAMPLE) | ADC_SMPR2_SMP_AN5(ADC_SAMPLE),
// SQR
ADC_SQR1_NUM_CH(ADC_CHANNEL_COUNT),
0,
ADC_SQR3_SQ1_N(3) | ADC_SQR3_SQ2_N(0) | ADC_SQR3_SQ3_N(2)
ADC_SQR3_SQ1_N(3) | ADC_SQR3_SQ2_N(0) | ADC_SQR3_SQ3_N(2) | ADC_SQR3_SQ4_N(5)
};
static float AverageSamples(adcsample_t* buffer, size_t idx)
@ -51,6 +51,7 @@ AnalogResult AnalogSample()
.NernstVoltage = AverageSamples(adcBuffer, 0) * NERNST_INPUT_GAIN,
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
.VirtualGroundVoltageInt = AverageSamples(adcBuffer, 2),
.BatteryVoltage = AverageSamples(adcBuffer, 3) / BATTERY_INPUT_DIVIDER,
};
}

View File

@ -8,6 +8,7 @@ struct AnalogResult
float NernstVoltage;
float PumpCurrentVoltage;
float VirtualGroundVoltageInt;
float BatteryVoltage;
};
AnalogResult AnalogSample();