Skip to content

Commit

Permalink
plumb mcu temp
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Feb 19, 2025
1 parent 0c169da commit ac9fc9a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions firmware/boards/f0_module/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ AnalogResult AnalogSample()
},
},
.VirtualGroundVoltageInt = AverageSamples(adcBuffer, 2),

// TODO!
.McuTemp = 0,
};
}

Expand Down
3 changes: 3 additions & 0 deletions firmware/boards/f1_rev3/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ AnalogResult AnalogSample()
* VirtualGroundVoltageInt is used to calculate Ip current only as it
* is used as offset for diffirential amp */
.VirtualGroundVoltageInt = HALF_VCC,

// TODO!
.McuTemp = 0,
};
}

Expand Down
2 changes: 2 additions & 0 deletions firmware/boards/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct AnalogResult
#ifdef BOARD_HAS_VOLTAGE_SENSE
float SupplyVoltage;
#endif

float McuTemp;
};

// Enable ADCs, configure pins, etc
Expand Down
2 changes: 2 additions & 0 deletions firmware/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ const ISampler& GetSampler(int ch);
float GetSupplyVoltage();
#endif

float GetMcuTemperature();

void StartSampling();
7 changes: 7 additions & 0 deletions firmware/sampling_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ float GetSupplyVoltage()
}
#endif

static float mcuTemp = 0;
float GetMcuTemperature()
{
return mcuTemp;
}

static void SamplingThread(void*)
{
chRegSetThreadName("Sampling");
Expand All @@ -44,6 +50,7 @@ static void SamplingThread(void*)
#ifdef BOARD_HAS_VOLTAGE_SENSE
supplyVoltage = result.SupplyVoltage;
#endif
mcuTemp = result.McuTemp;

for (int ch = 0; ch < AFR_CHANNELS; ch++)
{
Expand Down
4 changes: 3 additions & 1 deletion firmware/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ static void UartThread(void*)
int vbattIntPart = vbatt;
int vbattTenths = (vbatt - vbattIntPart) * 10;

size_t writeCount = chsnprintf(printBuffer, sizeof(printBuffer), "Board: VBatt %d.%01d\r\n", vbattIntPart, vbattTenths);
int tempC = GetMcuTemperature();

size_t writeCount = chsnprintf(printBuffer, sizeof(printBuffer), "Board: VBatt %d.%01d Temp %d deg C\r\n", vbattIntPart, vbattTenths, tempC);
chnWrite(&SD1, (const uint8_t *)printBuffer, writeCount);
}
#endif
Expand Down

0 comments on commit ac9fc9a

Please sign in to comment.