IoT-MBBR (masterthesis)
Masterthesis upgrading a Moving Bed BioReactor with extra sensors and cloud connectivity.
VL53L1X_calibration.c File Reference
#include "VL53L1X_api.h"
#include "VL53L1X_calibration.h"

Go to the source code of this file.

Macros

#define ALGO__PART_TO_PART_RANGE_OFFSET_MM   0x001E
 
#define MM_CONFIG__INNER_OFFSET_MM   0x0020
 
#define MM_CONFIG__OUTER_OFFSET_MM   0x0022
 

Functions

int8_t VL53L1X_CalibrateOffset (uint16_t dev, uint16_t TargetDistInMm, int16_t *offset)
 This function performs the offset calibration.
The function returns the offset value found and programs the offset compensation into the device. More...
 
int8_t VL53L1X_CalibrateXtalk (uint16_t dev, uint16_t TargetDistInMm, uint16_t *xtalk)
 This function performs the xtalk calibration.
The function returns the xtalk value found and programs the xtalk compensation to the device. More...
 

Macro Definition Documentation

◆ ALGO__PART_TO_PART_RANGE_OFFSET_MM

#define ALGO__PART_TO_PART_RANGE_OFFSET_MM   0x001E

Definition at line 69 of file VL53L1X_calibration.c.

◆ MM_CONFIG__INNER_OFFSET_MM

#define MM_CONFIG__INNER_OFFSET_MM   0x0020

Definition at line 70 of file VL53L1X_calibration.c.

◆ MM_CONFIG__OUTER_OFFSET_MM

#define MM_CONFIG__OUTER_OFFSET_MM   0x0022

Definition at line 71 of file VL53L1X_calibration.c.

Function Documentation

◆ VL53L1X_CalibrateOffset()

int8_t VL53L1X_CalibrateOffset ( uint16_t  dev,
uint16_t  TargetDistInMm,
int16_t *  offset 
)

This function performs the offset calibration.
The function returns the offset value found and programs the offset compensation into the device.

Parameters
TargetDistInMmtarget distance in mm, ST recommended 100 mm Target reflectance = grey17%
Returns
0:success, !=0: failed
offset pointer contains the offset found in mm

Definition at line 73 of file VL53L1X_calibration.c.

74 {
75  uint8_t i, tmp;
76  int16_t AverageDistance = 0;
77  uint16_t distance;
78  VL53L1X_ERROR status = 0;
79 
81  status = VL53L1_WrWord(dev, MM_CONFIG__INNER_OFFSET_MM, 0x0);
82  status = VL53L1_WrWord(dev, MM_CONFIG__OUTER_OFFSET_MM, 0x0);
83  status = VL53L1X_StartRanging(dev); /* Enable VL53L1X sensor */
84  for (i = 0; i < 50; i++) {
85  tmp = 0;
86  while (tmp == 0){
87  status = VL53L1X_CheckForDataReady(dev, &tmp);
88  }
89  status = VL53L1X_GetDistance(dev, &distance);
90  status = VL53L1X_ClearInterrupt(dev);
91  AverageDistance = AverageDistance + distance;
92  }
93  status = VL53L1X_StopRanging(dev);
94  AverageDistance = AverageDistance / 50;
95  *offset = TargetDistInMm - AverageDistance;
97  return status;
98 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
VL53L1X_ERROR VL53L1X_StopRanging(uint16_t dev)
This function stops the ranging.
Definition: VL53L1X_api.c:283
VL53L1X_ERROR VL53L1X_StartRanging(uint16_t dev)
This function starts the ranging distance operation The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
Definition: VL53L1X_api.c:275
int16_t offset
Definition: VL43L1X.c:52
#define MM_CONFIG__OUTER_OFFSET_MM
short int16_t
Typedef defining 16 bit short type. The developer should modify this to suit the platform being deplo...
Definition: vl53l1_types.h:93
VL53L1X_ERROR VL53L1X_GetDistance(uint16_t dev, uint16_t *distance)
This function returns the distance measured by the sensor in mm.
Definition: VL53L1X_api.c:546
#define ALGO__PART_TO_PART_RANGE_OFFSET_MM
#define MM_CONFIG__INNER_OFFSET_MM
VL53L1X_ERROR VL53L1X_CheckForDataReady(uint16_t dev, uint8_t *isDataReady)
This function checks if the new ranging data is available by polling the dedicated register...
Definition: VL53L1X_api.c:291
VL53L1X_ERROR VL53L1X_ClearInterrupt(uint16_t dev)
This function clears the interrupt, to be called after a ranging data reading to arm the interrupt fo...
Definition: VL53L1X_api.c:245
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_CalibrateXtalk()

int8_t VL53L1X_CalibrateXtalk ( uint16_t  dev,
uint16_t  TargetDistInMm,
uint16_t *  xtalk 
)

This function performs the xtalk calibration.
The function returns the xtalk value found and programs the xtalk compensation to the device.

Parameters
TargetDistInMmtarget distance in mm
The target distance : the distance where the sensor start to "under range"
due to the influence of the photons reflected back from the cover glass becoming strong
It's also called inflection point
Target reflectance = grey 17%
Returns
0: success, !=0: failed
xtalk pointer contains the xtalk value found in cps (number of photons in count per second)

Definition at line 100 of file VL53L1X_calibration.c.

101 {
102  uint8_t i, tmp;
103  float AverageSignalRate = 0;
104  float AverageDistance = 0;
105  float AverageSpadNb = 0;
106  uint16_t distance = 0, spadNum;
107  uint16_t sr;
108  VL53L1X_ERROR status = 0;
109  uint32_t calXtalk;
110 
111  status = VL53L1_WrWord(dev, 0x0016,0);
112  status = VL53L1X_StartRanging(dev);
113  for (i = 0; i < 50; i++) {
114  tmp = 0;
115  while (tmp == 0){
116  status = VL53L1X_CheckForDataReady(dev, &tmp);
117  }
118  status= VL53L1X_GetSignalRate(dev, &sr);
119  status= VL53L1X_GetDistance(dev, &distance);
120  status = VL53L1X_ClearInterrupt(dev);
121  AverageDistance = AverageDistance + distance;
122  status = VL53L1X_GetSpadNb(dev, &spadNum);
123  AverageSpadNb = AverageSpadNb + spadNum;
124  AverageSignalRate =
125  AverageSignalRate + sr;
126  }
127  status = VL53L1X_StopRanging(dev);
128  AverageDistance = AverageDistance / 50;
129  AverageSpadNb = AverageSpadNb / 50;
130  AverageSignalRate = AverageSignalRate / 50;
131  /* Calculate Xtalk value */
132  calXtalk = (uint16_t)(512*(AverageSignalRate*(1-(AverageDistance/TargetDistInMm)))/AverageSpadNb);
133  *xtalk = (uint16_t)(calXtalk*1000)>>9;
134  status = VL53L1_WrWord(dev, 0x0016, calXtalk);
135  return status;
136 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
VL53L1X_ERROR VL53L1X_StopRanging(uint16_t dev)
This function stops the ranging.
Definition: VL53L1X_api.c:283
VL53L1X_ERROR VL53L1X_StartRanging(uint16_t dev)
This function starts the ranging distance operation The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
Definition: VL53L1X_api.c:275
uint16_t xtalk
Definition: VL43L1X.c:53
VL53L1X_ERROR VL53L1X_GetSignalRate(uint16_t dev, uint16_t *signal)
This function returns the returned signal in kcps.
Definition: VL53L1X_api.c:581
VL53L1X_ERROR VL53L1X_GetDistance(uint16_t dev, uint16_t *distance)
This function returns the distance measured by the sensor in mm.
Definition: VL53L1X_api.c:546
VL53L1X_ERROR VL53L1X_GetSpadNb(uint16_t dev, uint16_t *spNb)
This function returns the current number of enabled SPADs.
Definition: VL53L1X_api.c:592
VL53L1X_ERROR VL53L1X_CheckForDataReady(uint16_t dev, uint8_t *isDataReady)
This function checks if the new ranging data is available by polling the dedicated register...
Definition: VL53L1X_api.c:291
VL53L1X_ERROR VL53L1X_ClearInterrupt(uint16_t dev)
This function clears the interrupt, to be called after a ranging data reading to arm the interrupt fo...
Definition: VL53L1X_api.c:245
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:78