Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adis16470 stability fixes #862

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/ssrc/common
48 changes: 29 additions & 19 deletions src/drivers/imu/analog_devices/adis16470/ADIS16470.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,37 @@ void ADIS16470::RunImpl()
_reset_timestamp = now;
_failure_count = 0;
_state = STATE::WAIT_FOR_RESET;
ScheduleDelayed(193_ms); // 193 ms Software Reset Recovery Time
// 193 ms Software Reset Recovery Time + 20 ms measured delay for register write to take effect
ScheduleDelayed(193_ms + 20_ms);
break;

case STATE::WAIT_FOR_RESET:

if (_self_test_passed) {
if ((RegisterRead(Register::PROD_ID) == Product_identification)) {
if ((RegisterRead(Register::PROD_ID) != Product_identification)) {
// RESET not complete
if (hrt_elapsed_time(&_reset_timestamp) > 1000_ms) {
PX4_DEBUG("Reset failed, retrying");
_state = STATE::RESET;

} else {
PX4_DEBUG("Reset not complete, check again in 100 ms");
}

ScheduleDelayed(100_ms);

} else {
if (_self_test_passed) {
// if reset succeeded then configure
_state = STATE::CONFIGURE;
ScheduleNow();

} else {
// RESET not complete
if (hrt_elapsed_time(&_reset_timestamp) > 1000_ms) {
PX4_DEBUG("Reset failed, retrying");
_state = STATE::RESET;
ScheduleDelayed(100_ms);
RegisterWrite(Register::GLOB_CMD, GLOB_CMD_BIT::Sensor_self_test);
_state = STATE::SELF_TEST_CHECK;

} else {
PX4_DEBUG("Reset not complete, check again in 100 ms");
ScheduleDelayed(100_ms);
}
// Self Test Time + measured delay for register write to take effect
ScheduleDelayed(14_ms + 10_ms);
}

} else {
RegisterWrite(Register::GLOB_CMD, GLOB_CMD_BIT::Sensor_self_test);
_state = STATE::SELF_TEST_CHECK;
ScheduleDelayed(14_ms); // Self Test Time
}

break;
Expand All @@ -175,13 +178,15 @@ void ADIS16470::RunImpl()

if (DIAG_STAT != 0) {
PX4_ERR("DIAG_STAT: %#X", DIAG_STAT);
_state = STATE::RESET;

} else {
PX4_DEBUG("self test passed");
_self_test_passed = true;
_state = STATE::RESET;
ScheduleNow();
_state = STATE::CONFIGURE;
}

ScheduleNow();
}
break;

Expand Down Expand Up @@ -382,6 +387,9 @@ bool ADIS16470::Configure()
RegisterSetAndClearBits(reg_cfg.reg, reg_cfg.set_bits, reg_cfg.clear_bits);
}

// wait for register set to get into use
px4_udelay(100);

// now check that all are configured
bool success = true;

Expand Down Expand Up @@ -459,6 +467,7 @@ uint16_t ADIS16470::RegisterRead(Register reg)
uint16_t cmd[1];
cmd[0] = (static_cast<uint16_t>(reg) << 8);

px4_udelay(1);
transferhword(cmd, nullptr, 1);
px4_udelay(SPI_STALL_PERIOD);
transferhword(nullptr, cmd, 1);
Expand All @@ -474,6 +483,7 @@ void ADIS16470::RegisterWrite(Register reg, uint16_t value)
cmd[0] = (((static_cast<uint16_t>(reg)) | DIR_WRITE) << 8) | ((0x00FF & value));
cmd[1] = (((static_cast<uint16_t>(reg) + 1) | DIR_WRITE) << 8) | ((0xFF00 & value) >> 8);

px4_udelay(1);
transferhword(cmd, nullptr, 1);
px4_udelay(SPI_STALL_PERIOD);
transferhword(cmd + 1, nullptr, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/imu/analog_devices/adis16470/ADIS16470.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ class ADIS16470 : public device::SPI, public I2CSPIDriver<ADIS16470>
} _state{STATE::RESET};

uint8_t _checked_register{0};
static constexpr uint16_t msc_ctrl_val = 0xC1 & ~MSC_CTRL_BIT::DR_polarity;
static constexpr uint8_t size_register_cfg{1};
register_config_t _register_cfg[size_register_cfg] {
// Register | Set bits, Clear bits
{ Register::MSC_CTRL, 0, MSC_CTRL_BIT::DR_polarity },
{ Register::MSC_CTRL, msc_ctrl_val, (uint16_t)~msc_ctrl_val},
};
};
Loading