From bcdd87689ad4bcf381896c96367adc900b9ebed3 Mon Sep 17 00:00:00 2001 From: peabody124 Date: Fri, 21 Jan 2011 17:18:24 +0000 Subject: [PATCH] OP-295 Modules/SystemMod: Get the internal CPU temperature sensor and store in system stats when available git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2511 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/Modules/System/systemmod.c | 7 +++++++ ground/src/shared/uavobjectdefinition/systemstats.xml | 1 + 2 files changed, 8 insertions(+) diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index f97180f0e..17397405f 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -266,6 +266,13 @@ static void updateStats() stats.CPULoad = 100 - (uint8_t) round(100.0 * ((float)idleCounter / (float)(SYSTEM_UPDATE_PERIOD_MS / 1000)) / (float)IDLE_COUNTS_PER_SEC_AT_NO_LOAD); idleCounterClear = 1; + +#if defined(PIOS_INCLUDE_ADC) && defined(PIOS_ADC_USE_TEMP_SENSOR) + float temp_voltage = 3.3 * PIOS_ADC_PinGet(0) / ((1 << 12) - 1); + const float STM32_TEMP_V25 = 1.43; /* V */ + const float STM32_TEMP_AVG_SLOPE = 4.3; /* mV/C */ + stats.CPUTemp = (temp_voltage-STM32_TEMP_V25) * 1000 / STM32_TEMP_AVG_SLOPE + 25; +#endif SystemStatsSet(&stats); } diff --git a/ground/src/shared/uavobjectdefinition/systemstats.xml b/ground/src/shared/uavobjectdefinition/systemstats.xml index bf98f3587..ee4fb2a9a 100644 --- a/ground/src/shared/uavobjectdefinition/systemstats.xml +++ b/ground/src/shared/uavobjectdefinition/systemstats.xml @@ -4,6 +4,7 @@ +