fixed merge conflicts and added threshold configuration to Max31865Handler
This commit is contained in:
parent
377a9bae79
commit
076c616496
@ -454,7 +454,7 @@ void ObjectFactory::produce(){
|
||||
|
||||
SpiCookie* spiRtdIc3 = new SpiCookie(addresses::RTD_IC3, gpioIds::RTD_IC3,
|
||||
std::string("/dev/spidev2.0"), Max31865Definitions::MAX_REPLY_SIZE,
|
||||
spi::SpiModes::MODE_1, 2000000);
|
||||
spi::SpiModes::MODE_3, 2000000);
|
||||
SpiCookie* spiRtdIc4 = new SpiCookie(addresses::RTD_IC4, gpioIds::RTD_IC4,
|
||||
std::string("/dev/spidev2.0"), Max31865Definitions::MAX_REPLY_SIZE,
|
||||
spi::SpiModes::MODE_1, 2000000);
|
||||
@ -490,7 +490,7 @@ void ObjectFactory::produce(){
|
||||
spi::SpiModes::MODE_1, 2000000);
|
||||
SpiCookie* spiRtdIc15 = new SpiCookie(addresses::RTD_IC15, gpioIds::RTD_IC15,
|
||||
std::string("/dev/spidev2.0"), Max31865Definitions::MAX_REPLY_SIZE,
|
||||
spi::SpiModes::MODE_1, 2000000);
|
||||
spi::SpiModes::MODE_1, 3900000);
|
||||
SpiCookie* spiRtdIc16 = new SpiCookie(addresses::RTD_IC16, gpioIds::RTD_IC16,
|
||||
std::string("/dev/spidev2.0"), Max31865Definitions::MAX_REPLY_SIZE,
|
||||
spi::SpiModes::MODE_1, 2000000);
|
||||
@ -517,10 +517,10 @@ void ObjectFactory::produce(){
|
||||
Max31865PT1000Handler* rtdIc16 = new Max31865PT1000Handler(objects::RTD_IC16, objects::SPI_COM_IF, spiRtdIc16, 0);
|
||||
Max31865PT1000Handler* rtdIc17 = new Max31865PT1000Handler(objects::RTD_IC17, objects::SPI_COM_IF, spiRtdIc17, 0);
|
||||
Max31865PT1000Handler* rtdIc18 = new Max31865PT1000Handler(objects::RTD_IC18, objects::SPI_COM_IF, spiRtdIc18, 0);
|
||||
rtdIc3->setStartUpImmediately();
|
||||
rtdIc17->setStartUpImmediately();
|
||||
// rtdIc4->setStartUpImmediately();
|
||||
|
||||
// (void) rtdIc3;
|
||||
(void) rtdIc3;
|
||||
(void) rtdIc4;
|
||||
(void) rtdIc5;
|
||||
(void) rtdIc6;
|
||||
@ -534,7 +534,7 @@ void ObjectFactory::produce(){
|
||||
(void) rtdIc14;
|
||||
(void) rtdIc15;
|
||||
(void) rtdIc16;
|
||||
(void) rtdIc17;
|
||||
// (void) rtdIc17;
|
||||
(void) rtdIc18;
|
||||
|
||||
#endif /* Q7S_ADD_RTD_DEVICES == 1 */
|
||||
|
@ -41,6 +41,7 @@ debugging. */
|
||||
#define L3GD20_GYRO_DEBUG 0
|
||||
#define DEBUG_RAD_SENSOR 1
|
||||
#define DEBUG_SUS 1
|
||||
#define DEBUG_RTD 1
|
||||
|
||||
// Leave at one as the BSP is linux. Used by the ADIS16507 device handler
|
||||
#define OBSW_ADIS16507_LINUX_COM_IF 1
|
||||
|
@ -8,7 +8,7 @@ Max31865PT1000Handler::Max31865PT1000Handler(object_id_t objectId,
|
||||
DeviceHandlerBase(objectId, comIF, comCookie), switchId(switchId),
|
||||
sensorDataset(this), sensorDatasetSid(sensorDataset.getSid()) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(10);
|
||||
debugDivider = new PeriodicOperationDivider(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -38,10 +38,38 @@ void Max31865PT1000Handler::doStartUp() {
|
||||
|
||||
if(internalState == InternalState::REQUEST_CONFIG) {
|
||||
if (commandExecuted) {
|
||||
commandExecuted = false;
|
||||
internalState = InternalState::CONFIG_HIGH_THRESHOLD;
|
||||
}
|
||||
}
|
||||
|
||||
if(internalState == InternalState::CONFIG_HIGH_THRESHOLD) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::REQUEST_HIGH_THRESHOLD;
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(internalState == InternalState::REQUEST_HIGH_THRESHOLD) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::CONFIG_LOW_THRESHOLD;
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(internalState == InternalState::CONFIG_LOW_THRESHOLD) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::REQUEST_LOW_THRESHOLD;
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(internalState == InternalState::REQUEST_LOW_THRESHOLD) {
|
||||
if(commandExecuted) {
|
||||
setMode(MODE_ON);
|
||||
setMode(MODE_NORMAL);
|
||||
commandExecuted = false;
|
||||
internalState = InternalState::RUNNING;
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,6 +110,22 @@ ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand(
|
||||
*id = Max31865Definitions::REQUEST_CONFIG;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case(InternalState::CONFIG_HIGH_THRESHOLD): {
|
||||
*id = Max31865Definitions::WRITE_HIGH_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case(InternalState::REQUEST_HIGH_THRESHOLD): {
|
||||
*id = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case(InternalState::CONFIG_LOW_THRESHOLD): {
|
||||
*id = Max31865Definitions::WRITE_LOW_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case(InternalState::REQUEST_LOW_THRESHOLD): {
|
||||
*id = Max31865Definitions::REQUEST_LOW_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
default:
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
@ -110,13 +154,49 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(
|
||||
}
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_CONFIG): {
|
||||
commandBuffer[0] = 0x00; // dummy byte
|
||||
commandBuffer[1] = static_cast<uint8_t>(
|
||||
commandBuffer[0] = static_cast<uint8_t>(
|
||||
Max31865Definitions::REQUEST_CONFIG);
|
||||
commandBuffer[1] = 0x00; // dummy byte
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(Max31865Definitions::WRITE_HIGH_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(
|
||||
Max31865Definitions::WRITE_HIGH_THRESHOLD);
|
||||
commandBuffer[1] = static_cast<uint8_t>(HIGH_THRESHOLD >> 8);
|
||||
commandBuffer[2] = static_cast<uint8_t>(HIGH_THRESHOLD & 0xFF);
|
||||
DeviceHandlerBase::rawPacketLen = 3;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(
|
||||
Max31865Definitions::REQUEST_HIGH_THRESHOLD);
|
||||
commandBuffer[1] = 0x00; //dummy byte
|
||||
commandBuffer[2] = 0x00; //dummy byte
|
||||
DeviceHandlerBase::rawPacketLen = 3;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(Max31865Definitions::WRITE_LOW_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(
|
||||
Max31865Definitions::WRITE_LOW_THRESHOLD);
|
||||
commandBuffer[1] = static_cast<uint8_t>(LOW_THRESHOLD >> 8);
|
||||
commandBuffer[2] = static_cast<uint8_t>(LOW_THRESHOLD & 0xFF);
|
||||
DeviceHandlerBase::rawPacketLen = 3;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_LOW_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(
|
||||
Max31865Definitions::REQUEST_LOW_THRESHOLD);
|
||||
commandBuffer[1] = 0x00; //dummy byte
|
||||
commandBuffer[2] = 0x00; //dummy byte
|
||||
DeviceHandlerBase::rawPacketLen = 3;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_RTD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(
|
||||
Max31865Definitions::REQUEST_RTD);
|
||||
@ -144,6 +224,10 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(
|
||||
void Max31865PT1000Handler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(Max31865Definitions::CONFIG_CMD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_CONFIG, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::WRITE_LOW_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_LOW_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::WRITE_HIGH_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_HIGH_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3,
|
||||
&sensorDataset);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3);
|
||||
@ -158,6 +242,39 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start,
|
||||
internalState == InternalState::RUNNING) {
|
||||
*foundId = Max31865Definitions::REQUEST_RTD;
|
||||
*foundLen = rtdReplySize;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
if(remainingSize == 3) {
|
||||
switch(internalState) {
|
||||
case(InternalState::CONFIG_HIGH_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::WRITE_HIGH_THRESHOLD;
|
||||
commandExecuted = true;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(InternalState::REQUEST_HIGH_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(InternalState::CONFIG_LOW_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::WRITE_LOW_THRESHOLD;
|
||||
commandExecuted = true;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(InternalState::REQUEST_LOW_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::REQUEST_LOW_THRESHOLD;
|
||||
return RETURN_OK;
|
||||
}
|
||||
default: {
|
||||
sif::debug << "Max31865PT1000Handler::scanForReply: Unknown internal state"
|
||||
<< std::endl;
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(remainingSize == configReplySize) {
|
||||
@ -203,14 +320,38 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_LOW_THRESHOLD): {
|
||||
uint16_t readLowThreshold = packet[0] << 8 | packet[1];
|
||||
if(readLowThreshold != LOW_THRESHOLD) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && DEBUG_RTD == 1
|
||||
sif::error
|
||||
<< "Max31865PT1000Handler::interpretDeviceReply: Missmatch between written "
|
||||
<< "and readback value of low threshold register"
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
||||
commandExecuted = true;
|
||||
break;
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
|
||||
uint16_t readHighThreshold = packet[0] << 8 | packet[1];
|
||||
if(readHighThreshold != HIGH_THRESHOLD) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && DEBUG_RTD == 1
|
||||
sif::error
|
||||
<< "Max31865PT1000Handler::interpretDeviceReply: Missmatch between written "
|
||||
<< "and readback value of high threshold register"
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
||||
commandExecuted = true;
|
||||
break;
|
||||
}
|
||||
case(Max31865Definitions::REQUEST_RTD): {
|
||||
// first bit of LSB reply byte is the fault bit
|
||||
uint8_t faultBit = packet[2] & 0b0000'0001;
|
||||
if(faultBit == 1) {
|
||||
// Maybe we should attempt to restart it?
|
||||
if(faultByte == 0) {
|
||||
internalState = InternalState::REQUEST_FAULT_BYTE;
|
||||
}
|
||||
internalState = InternalState::REQUEST_FAULT_BYTE;
|
||||
}
|
||||
|
||||
// RTD value consists of last seven bits of the LSB reply byte and
|
||||
@ -329,7 +470,7 @@ void Max31865PT1000Handler::debugInterface(uint8_t positionTracker,
|
||||
|
||||
uint32_t Max31865PT1000Handler::getTransitionDelayMs(
|
||||
Mode_t modeFrom, Mode_t modeTo) {
|
||||
return 10000;
|
||||
return 20000;
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865PT1000Handler::getSwitches(
|
||||
|
@ -37,16 +37,27 @@ public:
|
||||
// Configuration in 8 digit code:
|
||||
// 1. 1 for V_BIAS enabled, 0 for disabled
|
||||
// 2. 1 for Auto-conversion, 0 for off
|
||||
// 3. 1 for 1-shot enabled, 0 for disabled
|
||||
// 3. 1 for 1-shot enabled, 0 for disabled (self-clearing bit)
|
||||
// 4. 1 for 3-wire disabled, 0 for disabled
|
||||
// 5./6. Fault detection: 00 for no action, 01 for automatic delay, 1
|
||||
// 0 for run fault detection with manual delay,
|
||||
// 11 for finish fault detection with manual delay
|
||||
// 7. Fault status: 1 for auto-clear, 0 for auto-clear off
|
||||
// 7. Fault status: Write 1 to reset fault status register (Bit is self cleared afterwards)
|
||||
// 8. 1 for 50 Hz filter, 0 for 60 Hz filter (noise rejection filter)
|
||||
static constexpr uint8_t DEFAULT_CONFIG = 0b11000001;
|
||||
|
||||
static constexpr float RTD_RREF_PT1000 = 4000.0; //!< Ohm
|
||||
/**
|
||||
* Expected temperature range is -100°C and 100°C.
|
||||
* If there are temperatures beyond this range there must be a fault.
|
||||
* The threshold variables cause the MAX1385 to signal an error in case the measured resistance
|
||||
* indicates a temperature higher than 100°C or lower than -100°C.
|
||||
* Default settings of MAX13865 are 0xFFFF for the high threshold register and 0x0 for the
|
||||
* low threshold register.
|
||||
*/
|
||||
static constexpr uint16_t HIGH_THRESHOLD = 11298; // = 100°C
|
||||
static constexpr uint16_t LOW_THRESHOLD = 4902; // = -100°C
|
||||
|
||||
static constexpr float RTD_RREF_PT1000 = 4020.0; //!< Ohm
|
||||
static constexpr float RTD_RESISTANCE0_PT1000 = 1000.0; //!< Ohm
|
||||
protected:
|
||||
/* DeviceHandlerBase abstract function implementation */
|
||||
@ -80,6 +91,10 @@ private:
|
||||
NONE,
|
||||
WARMUP,
|
||||
CONFIGURE,
|
||||
CONFIG_HIGH_THRESHOLD,
|
||||
REQUEST_HIGH_THRESHOLD,
|
||||
CONFIG_LOW_THRESHOLD,
|
||||
REQUEST_LOW_THRESHOLD,
|
||||
REQUEST_CONFIG,
|
||||
RUNNING,
|
||||
REQUEST_FAULT_BYTE
|
||||
|
@ -14,8 +14,12 @@ enum PoolIds: lp_id_t {
|
||||
};
|
||||
|
||||
static constexpr DeviceCommandId_t CONFIG_CMD = 0x80;
|
||||
static constexpr DeviceCommandId_t WRITE_HIGH_THRESHOLD = 0x83;
|
||||
static constexpr DeviceCommandId_t WRITE_LOW_THRESHOLD = 0x85;
|
||||
static constexpr DeviceCommandId_t REQUEST_CONFIG = 0x00;
|
||||
static constexpr DeviceCommandId_t REQUEST_RTD = 0x01;
|
||||
static constexpr DeviceCommandId_t REQUEST_HIGH_THRESHOLD = 0x03;
|
||||
static constexpr DeviceCommandId_t REQUEST_LOW_THRESHOLD = 0x05;
|
||||
static constexpr DeviceCommandId_t REQUEST_FAULT_BYTE = 0x07;
|
||||
|
||||
static constexpr uint32_t MAX31865_SET_ID = REQUEST_RTD;
|
||||
|
Loading…
Reference in New Issue
Block a user