VL53L0X Divide by Zero error in API
Hi all,
Got a divide-by-zero exception whilst porting the API to the ESP32. The error occurs at line ~1960 in vl53l0x_api_core.c in this bit of maths:
sigmaEstRef =
VL53L0X_isqrt((cDfltFinalRangeIntegrationTimeMilliSecs +
finalRangeIntegrationTimeMilliSecs/2)/
finalRangeIntegrationTimeMilliSecs);Here is where finalRangeIntegrationTimeMilliSecs comes from (a few lines before)
finalRangeIntegrationTimeMilliSecs =
(finalRangeTimeoutMicroSecs + preRangeTimeoutMicroSecs + 500)/1000;All values there are UINT32. It might be a problem with my porting, or how the ESP32 treats rounding, but finalRangeIntegrationTimeMillis = ( 0 + 53 + 500) / 1000 which the platform interprets as 0. Has anyone had this error before?
I've fixed this for the time being by checking for a zero value (and setting to 1) before doing the isqrt. The device seems to work pretty well, though I am getting sigma error response when reading measurements. I've only got a single module so not sure if this behaviour is related to the above.
Curious how this error has occured - both finalRange and PreRange seem to be taken from the device configuration - called after DataInit()
/* Calculate final range macro periods */
finalRangeTimeoutMicroSecs = VL53L0X_GETDEVICESPECIFICPARAMETER(
Dev, FinalRangeTimeoutMicroSecs);
/* Calculate pre-range macro periods */
preRangeTimeoutMicroSecs = VL53L0X_GETDEVICESPECIFICPARAMETER(
Dev, PreRangeTimeoutMicroSecs);Can anyone give suggestion what I'm doing wrong? Or Is this a genuine bug in the API?
