cancel
Showing results for 
Search instead for 
Did you mean: 

Time Of Flight calibration error (VL53L0X) with nRF52833

renanFazzani
Associate II

Hi, I'm trying to use the VL53L0X sensor driver with zephyr and nRF52833, but I'm getting errors when the driver is trying to calibrate.

Below are the errors returned by the log system:

renanFazzani_1-1718978444754.png

My question, how could I solve this, it seems to be a software problem right?

 

 

10 REPLIES 10
John E KVAM
ST Employee

At the factory the RefCal is set, but it changed during your reflow. The problem is that it's so far off that the correction fails. The trick in this case is to set the RefCal =2, then run the calibration again. 

That should fix it. 

- john


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.

Hello, where can I find RefCal inside the driver? After that do I need to perform manual calibration, or just setting RefCal = 2 is everything ok?

I'm sorry.  I was not clear.

Do the RefSpad calibration. Most will pass just fine.

if you get a failure, 

    Set the RefSpad calibration to 2. 

    Re-run the RefSpad calibration. It will pass.

Then move on.

The reason this works is the factory cal is so far off the calibration cannot adjust in a few rare cases.

Setting the RefSpad starting point to 2 allows the algo to adjust better.

- john 

 

 


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.

Hello, could you just tell me in which file this variable is in which I need to assign the value 2? because I'm still not finding this variable in the driver files. Awaiting return.

John E KVAM
ST Employee

When you reboot, you are going to need to write the calibration data to the sensor. When you get a failure, I'm asking you to use that same calibration write routine to put a 2 into the RefSpad. Then re-run the calibration. it will pass the second time. then you can read the result out, and use that result for all subsequent boots.

- john 


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.

Hi, As I am using the driver in the zephyr rtos system, the driver is closed, so it is more complicated to change the initialization flow. However, tracing the code, go to this function:

 

static int vl53l0x_setup_single_shot(const struct device *dev)
{
    struct vl53l0x_data *drv_data = dev->data;
    int ret;
    uint8_t VhvSettings;
    uint8_t PhaseCal;
    uint32_t refSpadCount;
    uint8_t isApertureSpads;

    ret = VL53L0X_StaticInit(&drv_data->vl53l0x);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_StaticInit failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_PerformRefCalibration(&drv_data->vl53l0x, &VhvSettings, &PhaseCal);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_PerformRefCalibration failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_PerformRefSpadManagement(&drv_data->vl53l0x, (uint32_t *)&refSpadCount,
                           &isApertureSpads);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_PerformRefSpadManagement failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetDeviceMode(&drv_data->vl53l0x, VL53L0X_DEVICEMODE_SINGLE_RANGING);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetDeviceMode failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetLimitCheckEnable(&drv_data->vl53l0x, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
                      1);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetLimitCheckEnable sigma failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetLimitCheckEnable(&drv_data->vl53l0x,
                      VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetLimitCheckEnable signal rate failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetLimitCheckValue(&drv_data->vl53l0x,
                     VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
                     VL53L0X_SETUP_SIGNAL_LIMIT);

    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetLimitCheckValue signal rate failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetLimitCheckValue(&drv_data->vl53l0x, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
                     VL53L0X_SETUP_SIGMA_LIMIT);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetLimitCheckValue sigma failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(&drv_data->vl53l0x,
                                 VL53L0X_SETUP_MAX_TIME_FOR_RANGING);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetMeasurementTimingBudgetMicroSeconds failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetVcselPulsePeriod(&drv_data->vl53l0x, VL53L0X_VCSEL_PERIOD_PRE_RANGE,
                      VL53L0X_SETUP_PRE_RANGE_VCSEL_PERIOD);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetVcselPulsePeriod pre range failed", dev->name);
        goto exit;
    }

    ret = VL53L0X_SetVcselPulsePeriod(&drv_data->vl53l0x, VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
                      VL53L0X_SETUP_FINAL_RANGE_VCSEL_PERIOD);
    if (ret) {
        LOG_ERR("[%s] VL53L0X_SetVcselPulsePeriod final range failed", dev->name);
        goto exit;
    }

exit:
    return ret;
}

How can I assign the spad ref value 2, as suggested by you, in the context I'm showing you? 

 

The code should look like this:

    ret = VL53L0X_PerformRefSpadManagement(&drv_data->vl53l0x, (uint32_t *)&refSpadCount,
                           &isApertureSpads);
    if (ret) {  // got a failure, reset the register and retry the calibration
        ret = VL53L0X_set_reference_spads(&drv_data->vl53l0x,2, 0);
        ret += VL53L0X_PerformRefSpadManagement(&drv_data->vl53l0x, (uint32_t *)&refSpadCount,
                           &isApertureSpads);
        if (ret) {
              LOG_ERR("[%s] VL53L0X_PerformRefSpadManagement failed"dev->name);
             goto exit;
       }
  }
When the RefSpad fails, it's because the factory setting is too far one way and the calibration cannot compensate.
Reset the starting point to 2 and it will pass. 
I don't have any failing chips so I can't test it. 
If you cannot get it running and have a failing part, perhaps you could contact me directly and we can debug it.
 

If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.

hello, I can't find the function you suggested: VL53L0_set_reference_spads(&drv_data->vl53l0x,2, 0); Could you tell me how to add it, or is it already part of the driver?

I think the function name is VL53L0X_set_reference_spads(...), it's in  VL53L0X API.