diff --git a/src/boards/Main/Configs/SensorsConfig.h b/src/boards/Main/Configs/SensorsConfig.h index 05ad0d27c22b287fe8a6964098680fb31ff187f7..43c7d5d802e022a8fb9e4e858f1999d8339d0838 100644 --- a/src/boards/Main/Configs/SensorsConfig.h +++ b/src/boards/Main/Configs/SensorsConfig.h @@ -117,6 +117,7 @@ constexpr unsigned int GPS_SAMPLE_RATE = 5; // Sampling periods and dividers constexpr unsigned int SAMPLE_PERIOD_ADC_ADS131M04 = 1; constexpr unsigned int SAMPLE_PERIOD_INTERNAL_ADC = 1; +constexpr unsigned int SAMPLE_PERIOD_INTERNAL_TEMP = 200; constexpr unsigned int SAMPLE_PERIOD_PRESS_DIGITAL = 15; constexpr unsigned int TEMP_DIVIDER_PRESS_DIGITAL = 5; constexpr unsigned int SAMPLE_PERIOD_IMU_MPU = 5; diff --git a/src/boards/Main/Sensors/Sensors.cpp b/src/boards/Main/Sensors/Sensors.cpp index 2908ffab36bd0e00792c489bbb410beb2a45c3dd..c329614fa408a77defe4571c82d2a8385238172f 100644 --- a/src/boards/Main/Sensors/Sensors.cpp +++ b/src/boards/Main/Sensors/Sensors.cpp @@ -580,7 +580,7 @@ void Sensors::batteryVoltageInit() void Sensors::internalAdcInit() { - internalAdc = new InternalADC(ADC1, INTERNAL_ADC_VREF); + internalAdc = new InternalADC(ADC2, INTERNAL_ADC_VREF); internalAdc->enableChannel(INTERNAL_ADC_CH_5V_CURRENT); internalAdc->enableChannel(INTERNAL_ADC_CH_CUTTER_CURRENT); @@ -610,4 +610,17 @@ void Sensors::internalAdcInit() LOG_INFO(logger, "Internal ADC setup done!"); } +void Sensors::internalTempInit() +{ + internalTemp = new InternalTemp(InternalADC::CYCLES_480, INTERNAL_ADC_VREF); + + SensorInfo info( + "INTERNAL_TEMP", SAMPLE_PERIOD_INTERNAL_TEMP, + [&]() { Logger::getInstance().log(internalTemp->getLastSample()); }); + + sensorsMap.emplace(make_pair(internalTemp, info)); + + LOG_INFO(logger, "Internal TEMP setup done!"); +} + } // namespace Main diff --git a/src/boards/Main/Sensors/Sensors.h b/src/boards/Main/Sensors/Sensors.h index 3634a84f48bc50716950c3240283dfa6fa1418d0..ac0227e53c2ce4dcc6a143fdc0b23850ce226bb8 100644 --- a/src/boards/Main/Sensors/Sensors.h +++ b/src/boards/Main/Sensors/Sensors.h @@ -24,6 +24,7 @@ #include <diagnostic/PrintLogger.h> #include <drivers/adc/InternalADC.h> +#include <drivers/adc/InternalTemp.h> #include <sensors/ADS131M04/ADS131M04.h> #include <sensors/BMX160/BMX160.h> #include <sensors/BMX160/BMX160WithCorrection.h> @@ -136,6 +137,8 @@ private: void internalAdcInit(); + void internalTempInit(); + Boardcore::BMX160WithCorrection *bmx160WithCorrection = nullptr; Boardcore::MPU9250 *mpu9250 = nullptr; Boardcore::MS5803 *ms5803 = nullptr; @@ -149,7 +152,8 @@ private: Boardcore::AnalogLoadCell *loadCell = nullptr; Boardcore::BatteryVoltageSensor *batteryVoltage = nullptr; - Boardcore::InternalADC *internalAdc = nullptr; + Boardcore::InternalADC *internalAdc = nullptr; + Boardcore::InternalTemp *internalTemp = nullptr; Boardcore::SensorManager *sensorManager = nullptr; diff --git a/src/boards/Payload/Configs/SensorsConfig.h b/src/boards/Payload/Configs/SensorsConfig.h index dd35ac47861b1e02868a85c2d7317952585ae1c4..57f31660a3a3f578463a6877978ee87423f418a3 100644 --- a/src/boards/Payload/Configs/SensorsConfig.h +++ b/src/boards/Payload/Configs/SensorsConfig.h @@ -114,6 +114,7 @@ static constexpr unsigned int GPS_SAMPLE_RATE = 10; // Sampling periods and dividers constexpr unsigned int SAMPLE_PERIOD_PRESS_DIGITAL = 15; constexpr unsigned int SAMPLE_PERIOD_INTERNAL_ADC = 1000; +constexpr unsigned int SAMPLE_PERIOD_INTERNAL_TEMP = 2000; constexpr unsigned int SAMPLE_PERIOD_ADS1118 = 6; constexpr unsigned int SAMPLE_PERIOD_MAG_LIS = 15; constexpr unsigned int SAMPLE_PERIOD_GPS = 1000 / GPS_SAMPLE_RATE; diff --git a/src/boards/Payload/Sensors/Sensors.cpp b/src/boards/Payload/Sensors/Sensors.cpp index 3bb500f63f3223365b1bac1ac1240b9f176f470e..0c22eed9d729aa618ae0d49d9f6d1e49e0ffb4d7 100644 --- a/src/boards/Payload/Sensors/Sensors.cpp +++ b/src/boards/Payload/Sensors/Sensors.cpp @@ -517,4 +517,17 @@ void Sensors::batteryVoltageInit() LOG_INFO(logger, "Battery voltage sensor setup done!"); } +void Sensors::internalTempInit() +{ + internalTemp = new InternalTemp(InternalADC::CYCLES_480, INTERNAL_ADC_VREF); + + SensorInfo info( + "INTERNAL_TEMP", SAMPLE_PERIOD_INTERNAL_TEMP, + [&]() { Logger::getInstance().log(internalTemp->getLastSample()); }); + + sensorsMap.emplace(make_pair(internalTemp, info)); + + LOG_INFO(logger, "Internal TEMP setup done!"); +} + } // namespace Payload diff --git a/src/boards/Payload/Sensors/Sensors.h b/src/boards/Payload/Sensors/Sensors.h index 97b8397005400411aeef050eed5f340ae22b4f91..07c1c8e12dde695a8af8801cf85b24058eeac0d3 100644 --- a/src/boards/Payload/Sensors/Sensors.h +++ b/src/boards/Payload/Sensors/Sensors.h @@ -23,6 +23,7 @@ #pragma once #include <drivers/adc/InternalADC.h> +#include <drivers/adc/InternalTemp.h> #include <scheduler/TaskScheduler.h> #include <sensors/ADS1118/ADS1118.h> #include <sensors/BMX160/BMX160.h> @@ -106,6 +107,8 @@ private: void internalADCInit(); void batteryVoltageInit(); + void internalTempInit(); + Boardcore::BMX160WithCorrection* bmx160WithCorrection; Boardcore::LIS3MDL* lis3mdl; Boardcore::MS5803* ms5803; @@ -118,6 +121,7 @@ private: Boardcore::Pitot* pitot; Boardcore::InternalADC* internalADC; Boardcore::BatteryVoltageSensor* batteryVoltage; + Boardcore::InternalTemp* internalTemp = nullptr; Boardcore::SensorManager* sensorManager = nullptr;