Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firmware/console/binary/output_channels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ struct_no_prefix output_channels_s
uint16_t autoscale mafMeasured;@@GAUGE_NAME_AIR_FLOW_MEASURED@@;"kg/h",{1/@@PACK_MULT_MASS_FLOW@@}, 0, 0, 0, 1
uint16_t autoscale mafMeasured2;@@GAUGE_NAME_AIR_FLOW_MEASURED_2@@;"kg/h",{1/@@PACK_MULT_MASS_FLOW@@}, 0, 0, 0, 1

int8_t internalMcuTemperature;@@GAUGE_NAME_ECU_TEMPERATURE@@;"deg C",1, 0, 0, 0, 0
uint16_t autoscale mcuBackupVoltage;@@GAUGE_NAME_ECU_BACKUP_VOLTAGE@@;"V",{1/@@PACK_MULT_VOLTAGE@@}, 0, 0, 0, 2

! Fueling
int16_t[STFT_BANK_COUNT iterate] autoscale fuelPidCorrection;Fuel: Trim bank;"%",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2
Expand Down Expand Up @@ -164,8 +166,6 @@ struct_no_prefix output_channels_s
uint8_t widebandUpdateProgress;;"%", 1, 0, 0, 100, 0
uint8_t orderingErrorCounter;;"",1, 0, 0, 0, 0

int8_t internalMcuTemperature;@@GAUGE_NAME_ECU_TEMPERATURE@@;"deg C",1, 0, 0, 0, 0

uint16_t autoscale actualLastInjection;@@GAUGE_NAME_FUEL_LAST_INJECTION@@\nActual last injection time - including all compensation and injection mode;"ms",{1/@@PACK_MULT_MS@@}, 0, 0, 0, 3
uint16_t autoscale actualLastInjectionStage2;@@GAUGE_NAME_FUEL_LAST_INJECTION_STAGE_2@@;"ms",{1/@@PACK_MULT_MS@@}, 0, 0, 0, 3

Expand Down
3 changes: 3 additions & 0 deletions firmware/console/status_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ static void updateMiscSensors() {
engine->outputChannels.internalMcuTemperature =
Sensor::get(SensorType::EcuInternalTemperature)
.value_or(getMCUInternalTemperature());
engine->outputChannels.mcuBackupVoltage =
Sensor::get(SensorType::EcuBackupVoltage)
.value_or(getMCUBackupVoltage());
#endif /* HAL_USE_ADC */
}

Expand Down
6 changes: 4 additions & 2 deletions firmware/controllers/sensors/sensor_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class SensorType : unsigned char {
FuelTemperature,

// This is the "resolved" position, potentially composited out of the following two
Tps1, // 10
Tps1,
// This is the first sensor
Tps1Primary,
// This is the second sensor
Expand All @@ -59,7 +59,7 @@ enum class SensorType : unsigned char {
// This maps to the pedal if we have one, and Tps1 if not.
DriverThrottleIntent,

AuxTemp1, // 20
AuxTemp1,
AuxTemp2,

Lambda1,
Expand All @@ -75,6 +75,8 @@ enum class SensorType : unsigned char {
MainRelayVoltage,
Sensor5vVoltage,

EcuBackupVoltage, // STM32 Vbat

BarometricPressure,

FuelLevel,
Expand Down
6 changes: 6 additions & 0 deletions firmware/hw_layer/adc/adc_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ float getVoltage(const char *msg, adc_channel_e hwChannel) {
static uint32_t slowAdcCounter = 0;

static float mcuTemperature;
static float mcuBackupVoltage;

float getMCUBackupVoltage() {
return mcuBackupVoltage;
}

float getMCUInternalTemperature() {
return mcuTemperature;
Expand Down Expand Up @@ -77,6 +82,7 @@ void updateSlowAdc(efitick_t nowNt) {

// Ask the port to sample the MCU temperature
mcuTemperature = getMcuTemperature();
mcuBackupVoltage = getMcuBackupVoltage();
}

{
Expand Down
1 change: 1 addition & 0 deletions firmware/hw_layer/ports/mpu_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool isStm32F42x();
// ADC
#if HAL_USE_ADC
void portInitAdc();
float getMcuBackupVoltage();
float getMcuTemperature();
// Convert all slow ADC inputs. Returns true if the conversion succeeded, false if a failure occured.
bool readSlowAnalogInputs();
Expand Down
38 changes: 29 additions & 9 deletions firmware/hw_layer/ports/stm32/stm32_adc_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ static const ADCConversionGroup tempSensorConvGroup = {
.cr2 = ADC_CR2_SWSTART,
// sample times for channels 10...18
.smpr1 =
ADC_SMPR1_SMP_VBAT(ADC_SAMPLE_144) | /* input18 - temperature and vbat input on some STM32F7xx */
ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144), /* input16 - temperature sensor input on STM32F4xx */
ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144) | /* input16 - temperature sensor on STM32F40x/F41x */
ADC_SMPR1_SMP_VBAT(ADC_SAMPLE_144), /* input18 - temperature sensor and vbat on STM32F42x/F43x and some STM32F7xx */
.smpr2 = 0,
.htr = 0, .ltr = 0,
.sqr1 = 0,
Expand All @@ -103,22 +103,42 @@ static const ADCConversionGroup tempSensorConvGroup = {
static constexpr int oversample = 4;
static adcsample_t samples[oversample];

float getMcuTemperature() {
// Temperature sensor is only physically wired to ADC1
float getInternalAdcVoltage() {
// The temperature sensor, VREFINT and the VBAT channel are available only on the master ADC1 peripheral.
adcConvert(&ADCD1, &tempSensorConvGroup, samples, oversample);

uint32_t sum = 0;
for (size_t i = 0; i < oversample; i++) {
sum += samples[i];
}

float volts = (float)sum / (4096 * oversample);
volts *= engineConfiguration->adcVcc;
float sense = (float)sum / (4095 * oversample);
sense *= engineConfiguration->adcVcc;

return sense;
}

float getMcuBackupVoltage() {
// the backup Vbat voltage (RTC, coin cell, backup, battery)

adcSTM32EnableVBATE();

float volts = getInternalAdcVoltage();

adcSTM32DisableVBATE();

return volts;
}

float getMcuTemperature() {
// the internal device junction temperature sensor

float volts = getInternalAdcVoltage();

volts -= 0.760f; // Subtract the reference voltage at 25 deg C
float degrees = volts / 0.0025f; // Divide by slope 2.5mV
volts -= 0.760f; // Subtract the reference voltage at 25 deg C: 0.76 V
float degrees = volts / 0.0025f; // Divide by average slope: 2.5mV

degrees += 25.0; // Add the 25 deg C
degrees += 25.0f; // Add the 25 deg C

if (degrees > 150.0f || degrees < -50.0f) {
/*
Expand Down
5 changes: 5 additions & 0 deletions firmware/hw_layer/ports/stm32/stm32_adc_v4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ void portInitAdc() {
SYSCFG->PMCR &= ~(SYSCFG_PMCR_PA0SO | SYSCFG_PMCR_PA1SO | SYSCFG_PMCR_PC2SO | SYSCFG_PMCR_PC3SO);
}

float getMcuBackupVoltage() {
// the backup Vbat voltage (RTC, coin cell, backup, battery)
return 0;
}

float getMcuTemperature() {
// Ugh, internal temp sensor is wired to ADC3, which makes it nearly useless on the H7.
return 0;
Expand Down
1 change: 1 addition & 0 deletions firmware/integration/fome_config_shared.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
#define GAUGE_NAME_OIL_TEMPERATURE "Oil Temperature"

#define GAUGE_NAME_ECU_TEMPERATURE "ECU temperature"
#define GAUGE_NAME_ECU_BACKUP_VOLTAGE "ECU backup voltage"

#define GAUGE_NAME_AUX_LINEAR_1 "Aux linear 1"
#define GAUGE_NAME_AUX_LINEAR_2 "Aux linear 2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum SensorType {
BatteryVoltage,
MainRelayVoltage,
Sensor5vVoltage,
EcuBackupVoltage,
BarometricPressure,
FuelLevel,
VehicleSpeed,
Expand Down
Loading