-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code for RF temperature sensor (#334)
- Loading branch information
Showing
6 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! @file | ||
//! @brief "Driver" for the temperature sensor TMP36xS | ||
|
||
|
||
#include <Sts1CobcSw/Periphery/TemperatureSensor.hpp> | ||
|
||
#include <rodos_no_using_namespace.h> | ||
|
||
|
||
namespace sts1cobcsw::rftemperaturesensor | ||
{ | ||
// RF_TMP is read on pin PC0 on internal ADC1 | ||
auto adc = RODOS::HAL_ADC(RODOS::ADC_IDX1); | ||
constexpr auto channel = RODOS::ADC_CH_010; | ||
|
||
|
||
auto Initialize() -> void | ||
{ | ||
adc.init(channel); | ||
const int32_t bitResolution = 12; // 3.3 V / 2^12 bits / (10 mV/°C) = 0.0806 °C/bit | ||
adc.config(RODOS::ADC_PARAMETER_RESOLUTION, bitResolution); | ||
} | ||
|
||
|
||
auto Read() -> std::uint16_t | ||
{ | ||
auto rfTemperature = adc.read(channel); | ||
if(rfTemperature == static_cast<std::uint16_t>(RODOS::ADC_ERR_CONV_FAIL)) | ||
{ | ||
adc.reset(); | ||
Initialize(); | ||
rfTemperature = adc.read(channel); | ||
} | ||
return rfTemperature; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
|
||
#include <cstdint> | ||
|
||
|
||
namespace sts1cobcsw::rftemperaturesensor | ||
{ | ||
auto Initialize() -> void; | ||
auto Read() -> std::uint16_t; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <Tests/HardwareTests/RfLatchupDisablePin.hpp> | ||
|
||
#include <Sts1CobcSw/Periphery/TemperatureSensor.hpp> | ||
|
||
#include <rodos_no_using_namespace.h> | ||
|
||
|
||
namespace sts1cobcsw | ||
{ | ||
class TermperatureSensorTest : public RODOS::StaticThread<> | ||
{ | ||
public: | ||
TermperatureSensorTest() : StaticThread("TermperatureSensorTest") | ||
{ | ||
} | ||
|
||
|
||
private: | ||
void init() override | ||
{ | ||
InitializeRfLatchupDisablePins(); | ||
rftemperaturesensor::Initialize(); | ||
} | ||
|
||
|
||
void run() override | ||
{ | ||
using RODOS::PRINTF; | ||
|
||
EnableRfLatchupProtection(); | ||
|
||
PRINTF("\nRF temperature sensor test\n\n"); | ||
|
||
auto const conversionFactor = 0.0806; // °C/bit | ||
auto const offset = -50; // °C at 0 V | ||
TIME_LOOP(0, 1000 * RODOS::MILLISECONDS) | ||
{ | ||
auto temperature = rftemperaturesensor::Read(); | ||
PRINTF("raw value = %5d\n", temperature); | ||
PRINTF("temperature = %5.1f deg C\n", temperature * conversionFactor + offset); | ||
} | ||
} | ||
} termperatureSensorTest; | ||
} |