From a92024a8584ce5adf4b1fd96006ff195d204adea Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 14 May 2022 17:32:33 +0200 Subject: [PATCH] now supports auto mode as well --- linux/devices/Max31865RtdLowlevelHandler.cpp | 31 ++++++++++++++++---- linux/devices/Max31865RtdLowlevelHandler.h | 5 +--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/linux/devices/Max31865RtdLowlevelHandler.cpp b/linux/devices/Max31865RtdLowlevelHandler.cpp index f1c8d0e6..9b24f268 100644 --- a/linux/devices/Max31865RtdLowlevelHandler.cpp +++ b/linux/devices/Max31865RtdLowlevelHandler.cpp @@ -4,6 +4,19 @@ #include #include +#define OBSW_RTD_AUTO_MODE 1 + +#if OBSW_RTD_AUTO_MODE == 1 +static constexpr uint8_t BASE_CFG = (MAX31865::Bias::ON << MAX31865::CfgBitPos::BIAS_SEL) | + (MAX31865::Wires::FOUR_WIRE << MAX31865::CfgBitPos::WIRE_SEL) | + (MAX31865::ConvMode::AUTO << MAX31865::CfgBitPos::CONV_MODE); +#else +static constexpr uint8_t BASE_CFG = + (MAX31865::Bias::OFF << MAX31865::CfgBitPos::BIAS_SEL) | + (MAX31865::Wires::FOUR_WIRE << MAX31865::CfgBitPos::WIRE_SEL) | + (MAX31865::ConvMode::NORM_OFF << MAX31865::CfgBitPos::CONV_MODE); +#endif + Max31865RtdReader::Max31865RtdReader(object_id_t objectId, SpiComIF* lowLevelComIF, GpioIF* gpioIF) : SystemObject(objectId), rtds(EiveMax31855::NUM_RTDS), comIF(lowLevelComIF), gpioIF(gpioIF) { readerMutex = MutexFactory::instance()->createMutex(); @@ -12,21 +25,26 @@ Max31865RtdReader::Max31865RtdReader(object_id_t objectId, SpiComIF* lowLevelCom ReturnValue_t Max31865RtdReader::performOperation(uint8_t operationCode) { using namespace MAX31865; ReturnValue_t result = RETURN_OK; + static_cast(result); // Stopwatch watch; if (periodicInitHandling()) { +#if OBSW_RTD_AUTO_MODE == 0 // 10 ms delay for VBIAS startup TaskFactory::delayTask(10); +#endif } else { // No devices usable (e.g. TCS board off) return RETURN_OK; } +#if OBSW_RTD_AUTO_MODE == 0 result = periodicReadReqHandling(); if (result != RETURN_OK) { return result; } // After requesting, 65 milliseconds delay required TaskFactory::delayTask(65); +#endif return periodicReadHandling(); } @@ -57,8 +75,7 @@ bool Max31865RtdReader::periodicInitHandling() { sif::error << "Max31865RtdReader::periodicInitHandling: Manual CS lock failed" << std::endl; break; } - uint8_t cfg = rtd->defCfg; - result = writeCfgReg(rtd->spiCookie, cfg); + result = writeCfgReg(rtd->spiCookie, BASE_CFG); if (result != HasReturnvaluesIF::RETURN_OK) { handleSpiError(rtd, result, "writeCfgReg"); } @@ -94,8 +111,10 @@ bool Max31865RtdReader::periodicInitHandling() { continue; } if (rtdIsActive(rtd->idx)) { +#if OBSW_RTD_AUTO_MODE == 0 someRtdUsable = true; - result = writeBiasSel(Bias::ON, rtd->spiCookie, rtd->defCfg); + result = writeBiasSel(Bias::ON, rtd->spiCookie, BASE_CFG); +#endif } } return someRtdUsable; @@ -114,7 +133,7 @@ ReturnValue_t Max31865RtdReader::periodicReadReqHandling() { continue; } if (rtdIsActive(rtd->idx)) { - ReturnValue_t result = writeCfgReg(rtd->spiCookie, rtd->defCfg | (1 << CfgBitPos::ONE_SHOT)); + ReturnValue_t result = writeCfgReg(rtd->spiCookie, BASE_CFG | (1 << CfgBitPos::ONE_SHOT)); if (result != RETURN_OK) { handleSpiError(rtd, result, "writeCfgReg"); // Release mutex ASAP @@ -152,6 +171,7 @@ ReturnValue_t Max31865RtdReader::periodicReadHandling() { rtd->db.adcCode = rtdVal; } } +#if OBSW_RTD_AUTO_MODE == 0 for (auto& rtd : rtds) { if (rtd == nullptr) { continue; @@ -159,9 +179,10 @@ ReturnValue_t Max31865RtdReader::periodicReadHandling() { // Even if a device was made inactive, turn off the bias here. If it was turned off, not // necessary anymore.. if (rtd->on) { - result = writeBiasSel(Bias::OFF, rtd->spiCookie, rtd->defCfg); + result = writeBiasSel(Bias::OFF, rtd->spiCookie, BASE_CFG); } } +#endif return RETURN_OK; } diff --git a/linux/devices/Max31865RtdLowlevelHandler.h b/linux/devices/Max31865RtdLowlevelHandler.h index 3266bbbd..d3845bd5 100644 --- a/linux/devices/Max31865RtdLowlevelHandler.h +++ b/linux/devices/Max31865RtdLowlevelHandler.h @@ -21,10 +21,7 @@ struct Max31865ReaderCookie : public CookieIF { std::string locString = ""; std::array exchangeBuf{}; Countdown cd = Countdown(MAX31865::WARMUP_MS); - // I'd prefer if we could use the NORM_OFF mode, but it does not work for some reason.. - uint8_t defCfg = (MAX31865::Bias::ON << MAX31865::CfgBitPos::BIAS_SEL) | - (MAX31865::Wires::FOUR_WIRE << MAX31865::CfgBitPos::WIRE_SEL) | - (MAX31865::ConvMode::AUTO << MAX31865::CfgBitPos::CONV_MODE); + bool on = false; bool configured = false; bool active = false;