VL53L4CX generate calibration parameters

VL53L4CX generate calibration parameters

Please read Liability Disclaimer and License Agreement CAREFULLY

The below program is used to generate calibration parameters for VL53L4CX.

VL53L4CX

VL53L4CX is connected to Blue Pill on I2C1 PB6(SCL), PB7(SDA), Interrupt PB8 and XSHUT on PB9.

The data is presented on serial port 1 PA9(TX) and PA10(RX).

The Serial.println(";"); is commented due to memory limitations of the microcontroller, when copying the values in the main program do not forget to add ;

/* https://github.com/stm32duino/VL53L4CX */
#include <Arduino.h>
#include <Wire.h>
#include <vl53l4cx_class.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>

#define DEBUG
#define DEV_I2C Wire


#ifdef DEBUG
  #define DEBUG_Val(x)  \
    Serial.print(#x);  \
    Serial.print(" = ");  \
    Serial.println(x);
    //Serial.println(";");
  #define DEBUG_Arr(x, y)  \
    Serial.print(#x);  \
    Serial.print("[");  \
    Serial.print(y);  \
    Serial.print("] = ");  \
    Serial.println(x[y]);  
    //Serial.println(";");
#else
  #define DEBUG_Val(x)
  #define DEBUG_Arr(x, y)
#endif

constexpr uint8_t INT_PIN     = PB8;
constexpr uint8_t XSHUT       = PB9;
constexpr uint8_t I2C_ADDR    = 0x12;
constexpr uint8_t CALIB_DIST  = 100;
// Components.
VL53L4CX myDevice(&DEV_I2C, XSHUT);

void setup() {
  VL53L4CX_Error sensor_status;
  VL53L4CX_CalibrationData_t calibrationData;
  // Initialize serial for output.
  Serial.begin(9600);
  delay(1000);
  DEV_I2C.begin();
  delay(1000);
  // Initialize Step 1 and 2
  sensor_status = myDevice.InitSensor(I2C_ADDR);
  // Serial.println("Step 1+2");
  // Serial.println(sensor_status);
  // Should be called after VL53L4CX_DataInit()
  sensor_status = myDevice.VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG);
  // Serial.println("Step Distance Mode");
  // Serial.println(sensor_status);
  // Step 1 & 2 done in init
  // Step 3 must be called first in the calibration procedure
  sensor_status = myDevice.VL53L4CX_PerformRefSpadManagement();
  // Serial.println("Step 3");
  // Serial.println(sensor_status);
  // Step 4 crosstalk correction
  sensor_status = myDevice.VL53L4CX_PerformXTalkCalibration();
  // Serial.println("Step 4");
  // Serial.println(sensor_status);
  // Step 5 - place the sensor 100mm away from target
  sensor_status = myDevice.VL53L4CX_PerformOffsetPerVcselCalibration(CALIB_DIST);
  // Serial.println("Step 5");
  // Serial.println(sensor_status); 
  // Step 6
  sensor_status = myDevice.VL53L4CX_GetCalibrationData(&calibrationData);
  // Serial.println("Step 6");
  // Serial.println(sensor_status);

  // Step 6A - print calibration data
  // Serial.println("----Calibration data----");
  DEBUG_Val(calibrationData.customer.global_config__spad_enables_ref_0);
  DEBUG_Val(calibrationData.customer.global_config__spad_enables_ref_1);
  DEBUG_Val(calibrationData.customer.global_config__spad_enables_ref_2);
  DEBUG_Val(calibrationData.customer.global_config__spad_enables_ref_3);
  DEBUG_Val(calibrationData.customer.global_config__spad_enables_ref_4);
  DEBUG_Val(calibrationData.customer.global_config__spad_enables_ref_5);
  DEBUG_Val(calibrationData.customer.global_config__ref_en_start_select);
  DEBUG_Val(calibrationData.customer.ref_spad_man__num_requested_ref_spads);
  DEBUG_Val(calibrationData.customer.ref_spad_man__ref_location);
  DEBUG_Val(calibrationData.customer.algo__crosstalk_compensation_plane_offset_kcps);
  DEBUG_Val(calibrationData.customer.algo__crosstalk_compensation_x_plane_gradient_kcps);
  DEBUG_Val(calibrationData.customer.algo__crosstalk_compensation_y_plane_gradient_kcps);
  DEBUG_Val(calibrationData.customer.ref_spad_char__total_rate_target_mcps);
  DEBUG_Val(calibrationData.customer.algo__part_to_part_range_offset_mm);
  DEBUG_Val(calibrationData.customer.mm_config__inner_offset_mm);
  DEBUG_Val(calibrationData.customer.mm_config__outer_offset_mm);

  DEBUG_Val(calibrationData.add_off_cal_data.result__mm_inner_actual_effective_spads);
  DEBUG_Val(calibrationData.add_off_cal_data.result__mm_outer_actual_effective_spads);
  DEBUG_Val(calibrationData.add_off_cal_data.result__mm_inner_peak_signal_count_rtn_mcps);
  DEBUG_Val(calibrationData.add_off_cal_data.result__mm_outer_peak_signal_count_rtn_mcps);

  DEBUG_Val(calibrationData.optical_centre.x_centre);
  DEBUG_Val(calibrationData.optical_centre.y_centre);

  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.zone_id);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.time_stamp);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.VL53L4CX_p_019);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.VL53L4CX_p_020);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.VL53L4CX_p_021);
  
  for(uint8_t i = 0; i < VL53L4CX_XTALK_HISTO_BINS; i++){
	  DEBUG_Arr(calibrationData.xtalkhisto.xtalk_shape.bin_data, i);
  }
  
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.phasecal_result__reference_phase); 
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.phasecal_result__vcsel_start); 
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.cal_config__vcsel_start);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.vcsel_width);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.VL53L4CX_p_015);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_shape.zero_distance_phase);

  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.cfg_device_state);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.rd_device_state);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.zone_id);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.time_stamp);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.VL53L4CX_p_019);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.VL53L4CX_p_020);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.VL53L4CX_p_021);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.number_of_ambient_bins);
  for(uint8_t i = 0; i < VL53L4CX_MAX_BIN_SEQUENCE_LENGTH; i++){
	  DEBUG_Arr(calibrationData.xtalkhisto.xtalk_hist_removed.bin_seq, i);
  }
  for(uint8_t i = 0; i < VL53L4CX_MAX_BIN_SEQUENCE_LENGTH; i++){
	  DEBUG_Arr(calibrationData.xtalkhisto.xtalk_hist_removed.bin_rep, i);
  }
  for(uint8_t i = 0; i < VL53L4CX_HISTOGRAM_BUFFER_SIZE; i++){
	  DEBUG_Arr(calibrationData.xtalkhisto.xtalk_hist_removed.bin_data, i);
  }
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.result__interrupt_status);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.result__range_status);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.result__report_status);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.result__stream_count);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.result__dss_actual_effective_spads);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.phasecal_result__reference_phase);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.phasecal_result__vcsel_start);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.cal_config__vcsel_start);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.vcsel_width);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.VL53L4CX_p_005);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.VL53L4CX_p_015);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.total_periods_elapsed);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.peak_duration_us);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.woi_duration_us);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.min_bin_value);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.max_bin_value);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.zero_distance_phase);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.number_of_ambient_samples);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.ambient_events_sum);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.VL53L4CX_p_028);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.roi_config__user_roi_centre_spad);
  DEBUG_Val(calibrationData.xtalkhisto.xtalk_hist_removed.roi_config__user_roi_requested_global_xy_size);

  DEBUG_Val(calibrationData.gain_cal.standard_ranging_gain_factor);
  DEBUG_Val(calibrationData.gain_cal.histogram_ranging_gain_factor);

  DEBUG_Val(calibrationData.cal_peak_rate_map.cal_distance_mm);
  DEBUG_Val(calibrationData.cal_peak_rate_map.cal_reflectance_pc);
  DEBUG_Val(calibrationData.cal_peak_rate_map.max_samples);
  DEBUG_Val(calibrationData.cal_peak_rate_map.width);
  DEBUG_Val(calibrationData.cal_peak_rate_map.height);
  for(uint8_t i = 0; i < VL53L4CX_NVM_PEAK_RATE_MAP_SAMPLES; i++){
	  DEBUG_Arr(calibrationData.cal_peak_rate_map.peak_rate_mcps, i);
  }

  DEBUG_Val(calibrationData.per_vcsel_cal_data.short_a_offset_mm);
  DEBUG_Val(calibrationData.per_vcsel_cal_data.short_b_offset_mm);
  DEBUG_Val(calibrationData.per_vcsel_cal_data.medium_a_offset_mm);
  DEBUG_Val(calibrationData.per_vcsel_cal_data.medium_b_offset_mm);
  DEBUG_Val(calibrationData.per_vcsel_cal_data.long_a_offset_mm);
  DEBUG_Val(calibrationData.per_vcsel_cal_data.long_b_offset_mm);
}

void loop() {

}

Comments powered by CComment

Who’s online

We have 508 guests and no members online