src/vl53l1x.cpp
bool Vl53l1x::setMeasurementTimingBudget(uint32_t budget_us)
{
  // assumes PresetMode is LOWPOWER_AUTONOMOUS

  if (budget_us <= TimingGuard) { return false; }

  uint32_t range_config_timeout_us = budget_us -= TimingGuard;
  if (range_config_timeout_us > 1100000) { return false; } // FDA_MAX_TIMING_BUDGET_US * 2

  range_config_timeout_us /= 2;

  // VL53L1_calc_timeout_register_values() begin

  uint32_t macro_period_us;

  // "Update Macro Period for Range A VCSEL Period"
  macro_period_us = calcMacroPeriod(readReg(RANGE_CONFIG__VCSEL_PERIOD_A));

  // "Update Phase timeout - uses Timing A"
  // Timeout of 1000 is tuning parm default (TIMED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT)
  // via VL53L1_get_preset_mode_timing_cfg().
  uint32_t phasecal_timeout_mclks = timeoutMicrosecondsToMclks(1000, macro_period_us);
  if (phasecal_timeout_mclks > 0xFF) { phasecal_timeout_mclks = 0xFF; }
  writeReg(PHASECAL_CONFIG__TIMEOUT_MACROP, phasecal_timeout_mclks);

  // "Update MM Timing A timeout"
  // Timeout of 1 is tuning parm default (LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US_DEFAULT)
  // via VL53L1_get_preset_mode_timing_cfg(). With the API, the register
  // actually ends up with a slightly different value because it gets assigned,
  // retrieved, recalculated with a different macro period, and reassigned,
  // but it probably doesn't matter because it seems like the MM ("mode
  // mitigation"?) sequence steps are disabled in low power auto mode anyway.
  writeReg16Bit(MM_CONFIG__TIMEOUT_MACROP_A, encodeTimeout(
    timeoutMicrosecondsToMclks(1, macro_period_us)));

  // "Update Range Timing A timeout"
  writeReg16Bit(RANGE_CONFIG__TIMEOUT_MACROP_A, encodeTimeout(
    timeoutMicrosecondsToMclks(range_config_timeout_us, macro_period_us)));

  // "Update Macro Period for Range B VCSEL Period"
  macro_period_us = calcMacroPeriod(readReg(RANGE_CONFIG__VCSEL_PERIOD_B));

  // "Update MM Timing B timeout"
  // (See earlier comment about MM Timing A timeout.)
  writeReg16Bit(MM_CONFIG__TIMEOUT_MACROP_B, encodeTimeout(
    timeoutMicrosecondsToMclks(1, macro_period_us)));

  // "Update Range Timing B timeout"
  writeReg16Bit(RANGE_CONFIG__TIMEOUT_MACROP_B, encodeTimeout(
    timeoutMicrosecondsToMclks(range_config_timeout_us, macro_period_us)));

  // VL53L1_calc_timeout_register_values() end

  return true;
}
// Set the measurement timing budget in microseconds, which is the time allowed
// for one measurement. A longer timing budget allows for more accurate
// measurements.
// based on VL53L1_SetMeasurementTimingBudgetMicroSeconds()
Set the measurement timing budget in microseconds, which is the time allowed
for one measurement. A longer timing budget allows for more accurate
measurements.
Set the measurement timing budget in microseconds which is the time allowed for one measurement . A longer timing budget allows for more accurate measurements .
bool Vl53l1x::setMeasurementTimingBudget(uint32_t budget_us)
{
  if (budget_us <= TimingGuard) { return false; }
  uint32_t range_config_timeout_us = budget_us -= TimingGuard;
  if (range_config_timeout_us > 1100000) { return false; } 
  range_config_timeout_us /= 2;
  uint32_t macro_period_us;
  macro_period_us = calcMacroPeriod(readReg(RANGE_CONFIG__VCSEL_PERIOD_A));
  uint32_t phasecal_timeout_mclks = timeoutMicrosecondsToMclks(1000, macro_period_us);
  if (phasecal_timeout_mclks > 0xFF) { phasecal_timeout_mclks = 0xFF; }
  writeReg(PHASECAL_CONFIG__TIMEOUT_MACROP, phasecal_timeout_mclks);
   With the API, the register
  writeReg16Bit(MM_CONFIG__TIMEOUT_MACROP_A, encodeTimeout(
    timeoutMicrosecondsToMclks(1, macro_period_us)));
  writeReg16Bit(RANGE_CONFIG__TIMEOUT_MACROP_A, encodeTimeout(
    timeoutMicrosecondsToMclks(range_config_timeout_us, macro_period_us)));
  macro_period_us = calcMacroPeriod(readReg(RANGE_CONFIG__VCSEL_PERIOD_B));
  writeReg16Bit(MM_CONFIG__TIMEOUT_MACROP_B, encodeTimeout(
    timeoutMicrosecondsToMclks(1, macro_period_us)));
  writeReg16Bit(RANGE_CONFIG__TIMEOUT_MACROP_B, encodeTimeout(
    timeoutMicrosecondsToMclks(range_config_timeout_us, macro_period_us)));
  return true;
}
bool Vl53l1x :: setMeasurementTimingBudget ( uint32_t budget_us ) { if ( budget_us <= TimingGuard ) { return false ; } uint32_t range_config_timeout_us = budget_us -= TimingGuard ; if ( range_config_timeout_us > 1100000 ) { return false ; } range_config_timeout_us /= 2 ; uint32_t macro_period_us ; macro_period_us = calcMacroPeriod ( readReg ( RANGE_CONFIG__VCSEL_PERIOD_A ) ) ; uint32_t phasecal_timeout_mclks = timeoutMicrosecondsToMclks ( 1000 , macro_period_us ) ; if ( phasecal_timeout_mclks > 0xFF ) { phasecal_timeout_mclks = 0xFF ; } writeReg ( PHASECAL_CONFIG__TIMEOUT_MACROP , phasecal_timeout_mclks ) ; writeReg16Bit ( MM_CONFIG__TIMEOUT_MACROP_A , encodeTimeout ( timeoutMicrosecondsToMclks ( 1 , macro_period_us ) ) ) ; writeReg16Bit ( RANGE_CONFIG__TIMEOUT_MACROP_A , encodeTimeout ( timeoutMicrosecondsToMclks ( range_config_timeout_us , macro_period_us ) ) ) ; macro_period_us = calcMacroPeriod ( readReg ( RANGE_CONFIG__VCSEL_PERIOD_B ) ) ; writeReg16Bit ( MM_CONFIG__TIMEOUT_MACROP_B , encodeTimeout ( timeoutMicrosecondsToMclks ( 1 , macro_period_us ) ) ) ; writeReg16Bit ( RANGE_CONFIG__TIMEOUT_MACROP_B , encodeTimeout ( timeoutMicrosecondsToMclks ( range_config_timeout_us , macro_period_us ) ) ) ; return true ; }
Set the measurement timing budget in microseconds, which is the time allowed
for one measurement.
Set the measurement timing budget in microseconds which is the time allowed for one measurement .
// assumes PresetMode is LOWPOWER_AUTONOMOUS // FDA_MAX_TIMING_BUDGET_US * 2 // VL53L1_calc_timeout_register_values() begin // "Update Macro Period for Range A VCSEL Period" // "Update Phase timeout - uses Timing A" // Timeout of 1000 is tuning parm default (TIMED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT) // via VL53L1_get_preset_mode_timing_cfg(). // "Update MM Timing A timeout" // Timeout of 1 is tuning parm default (LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US_DEFAULT) // via VL53L1_get_preset_mode_timing_cfg(). With the API, the register // actually ends up with a slightly different value because it gets assigned, // retrieved, recalculated with a different macro period, and reassigned, // but it probably doesn't matter because it seems like the MM ("mode // mitigation"?) sequence steps are disabled in low power auto mode anyway. // "Update Range Timing A timeout" // "Update Macro Period for Range B VCSEL Period" // "Update MM Timing B timeout" // (See earlier comment about MM Timing A timeout.) // "Update Range Timing B timeout" // VL53L1_calc_timeout_register_values() end