cancel
Showing results for
Did you mean:

# VL6180x ECE Threshold, negative convergence time

Associate

Hello,

We want to set the ECE threshold of the VL6180x.

We are following the document DT0034 - VL6180X early convergence estimate implementation.

SAMPLE = 119 (reg 0x10A)

MAX_CONV = 15 (reg 0x01C)

PERIOD = 48 (reg 0x10A)

TIME = (SAMPLE + 1) * (24 + 70 + (PERIOD*10)) + 200

TIME = 69080

CONV_TIME = MAX_CONV * 1000 - TIME

CONV_TIME = -54080

Is it possible to have a negative convergence time and how to handle it?

Thomas

1 ACCEPTED SOLUTION

Accepted Solutions
ST Employee

A while back we had a lot of questions like this. So instead of reading complex manual and trying to figure it all out, we wrote an API that does it all for you.

That API can be found at:

STSW-IMG003

Even if you don't use the API, there is a function in there that will set the max convergence time for you.

And look it over for other routines you might need.

And if you are so inclined - just use the API in your project. All the functions have been validated.

The following is what that API does. Compare it to yours.

good luck

``````static int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev)
{
int status;

const uint32_t cMicroSecPerMilliSec  = 1000;
const uint32_t cEceSampleTime_us     = 500;
uint32_t ece_factor_m          = VL6180xDevDataGet(dev, EceFactorM);
uint32_t ece_factor_d          = VL6180xDevDataGet(dev, EceFactorD);
uint32_t convergTime_us;
uint32_t fineThresh;
uint32_t eceThresh;
uint8_t  u8;
uint32_t maxConv_ms;
int32_t AveTime;

LOG_FUNCTION_START("");

do {
status = VL6180x_RdByte(dev, SYSRANGE_MAX_CONVERGENCE_TIME, &u8);
if (status) {
VL6180x_ErrLog("SYSRANGE_MAX_CONVERGENCE_TIME rd fail");
break;
}
maxConv_ms = u8;
AveTime = _GetAveTotalTime(dev);
if (AveTime < 0) {
status = -1;
break;
}

convergTime_us = maxConv_ms * cMicroSecPerMilliSec - AveTime;
status = VL6180x_RdDWord(dev, 0xB8, &fineThresh);
if (status) {
VL6180x_ErrLog("reg 0xB8 rd fail");
break;
}
fineThresh *= 256;
eceThresh = ece_factor_m * cEceSampleTime_us * fineThresh / (convergTime_us * ece_factor_d);

status = VL6180x_WrWord(dev, SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, (uint16_t)eceThresh);
} while (0);

LOG_FUNCTION_END(status);
return status;
}``````

ST Employee

A while back we had a lot of questions like this. So instead of reading complex manual and trying to figure it all out, we wrote an API that does it all for you.

That API can be found at:

STSW-IMG003

Even if you don't use the API, there is a function in there that will set the max convergence time for you.

And look it over for other routines you might need.

And if you are so inclined - just use the API in your project. All the functions have been validated.

The following is what that API does. Compare it to yours.

good luck

``````static int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev)
{
int status;

const uint32_t cMicroSecPerMilliSec  = 1000;
const uint32_t cEceSampleTime_us     = 500;
uint32_t ece_factor_m          = VL6180xDevDataGet(dev, EceFactorM);
uint32_t ece_factor_d          = VL6180xDevDataGet(dev, EceFactorD);
uint32_t convergTime_us;
uint32_t fineThresh;
uint32_t eceThresh;
uint8_t  u8;
uint32_t maxConv_ms;
int32_t AveTime;

LOG_FUNCTION_START("");

do {
status = VL6180x_RdByte(dev, SYSRANGE_MAX_CONVERGENCE_TIME, &u8);
if (status) {
VL6180x_ErrLog("SYSRANGE_MAX_CONVERGENCE_TIME rd fail");
break;
}
maxConv_ms = u8;
AveTime = _GetAveTotalTime(dev);
if (AveTime < 0) {
status = -1;
break;
}

convergTime_us = maxConv_ms * cMicroSecPerMilliSec - AveTime;
status = VL6180x_RdDWord(dev, 0xB8, &fineThresh);
if (status) {
VL6180x_ErrLog("reg 0xB8 rd fail");
break;
}
fineThresh *= 256;
eceThresh = ece_factor_m * cEceSampleTime_us * fineThresh / (convergTime_us * ece_factor_d);

status = VL6180x_WrWord(dev, SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, (uint16_t)eceThresh);
} while (0);

LOG_FUNCTION_END(status);
return status;
}``````