Skip to content

Commit

Permalink
Adapt some procedure sleep times depending on reference clock frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
rjonaitis committed Aug 9, 2023
1 parent afa538b commit e83c13b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/lms7002m/LMS7002M.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,7 @@ float_type LMS7002M::GetTemperature()
uint16_t biasMux = Get_SPI_Reg_bits(LMS7_MUX_BIAS_OUT);
Modify_SPI_Reg_bits(LMS7_MUX_BIAS_OUT, 2);

this_thread::sleep_for(chrono::microseconds(250));
SleepForRefClkTicks(7680);
const uint16_t reg606 = SPI_read(0x0606, true);
float Vtemp = (reg606 >> 8) & 0xFF;
Vtemp *= 1.84;
Expand Down Expand Up @@ -2818,7 +2818,7 @@ int LMS7002M::CalibrateAnalogRSSI_DC_Offset()
if(value < 0)
wrValue |= 0x40;
Modify_SPI_Reg_bits(LMS7param(RSSIDC_DCO1), wrValue, true);
this_thread::sleep_for(chrono::microseconds(5));
SleepForRefClkTicks(154);
cmp = Get_SPI_Reg_bits(LMS7param(RSSIDC_CMPSTATUS), true);
if(cmp != cmpPrev)
{
Expand All @@ -2842,3 +2842,11 @@ int LMS7002M::CalibrateAnalogRSSI_DC_Offset()
Modify_SPI_Reg_bits(LMS7_EN_INSHSW_W_RFE, 0);
return 0;
}

void LMS7002M::SleepForRefClkTicks(uint32_t ticks)
{
float refclk = GetReferenceClk_SX(Rx);
int64_t period_ns = 1e9/refclk;
chrono::nanoseconds duration_ns = chrono::nanoseconds(ticks*period_ns);
this_thread::sleep_for(duration_ns);
}
1 change: 1 addition & 0 deletions src/lms7002m/LMS7002M.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ class LIME_API LMS7002M
int Modify_SPI_Reg_mask(const uint16_t *addr, const uint16_t *masks, const uint16_t *values, uint8_t start, uint8_t stop);
///@}

void SleepForRefClkTicks(uint32_t ticks);
virtual void Log(const char* text, LogType type);

void Log(LogType type, const char *format, ...)
Expand Down
5 changes: 4 additions & 1 deletion src/lms7002m/LMS7002M_BaseCalibrations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int LMS7002M::CalibrateInternalADC(int clkDiv)
}
++bias;
Modify_SPI_Reg_bits(LMS7_RSSI_BIAS, bias);
SleepForRefClkTicks(7575);
regValue = SPI_read(0x0601, true);
}
Modify_SPI_Reg_bits(LMS7_RSSI_PD, 0);
Expand All @@ -63,7 +64,7 @@ int LMS7002M::CalibrateRP_BIAS()

const uint16_t biasMux = Get_SPI_Reg_bits(LMS7_MUX_BIAS_OUT);
Modify_SPI_Reg_bits(LMS7_MUX_BIAS_OUT, 1);
this_thread::sleep_for(chrono::microseconds(250));
SleepForRefClkTicks(7575);
uint16_t reg606 = SPI_read(0x0606, true);
uint16_t Vref = (reg606 >> 8) & 0xFF;
uint16_t Vptat = reg606 & 0xFF;
Expand All @@ -75,6 +76,7 @@ int LMS7002M::CalibrateRP_BIAS()
{
--rpCalib;
Modify_SPI_Reg_bits(LMS7_RP_CALIB_BIAS, rpCalib);
SleepForRefClkTicks(7575);
reg606 = SPI_read(0x0606, true);
Vref = (reg606 >> 8) & 0xFF;
Vptat = reg606 & 0xFF;
Expand All @@ -87,6 +89,7 @@ int LMS7002M::CalibrateRP_BIAS()
{
++rpCalib;
Modify_SPI_Reg_bits(LMS7_RP_CALIB_BIAS, rpCalib);
SleepForRefClkTicks(7575);
reg606 = SPI_read(0x0606, true);
Vref = (reg606 >> 8) & 0xFF;
Vptat = reg606 & 0xFF;
Expand Down

0 comments on commit e83c13b

Please sign in to comment.