2021-07-17 05:17 AM
Dear Sirs,
I have some problems with VL53L1 and VL53L1X sensors which i'm using in my project.
Now i'm trying to figure out how to switch them to different modes and apply different settings in accordance with API manuals and datasheets. I'm also using STM32F3DISCOVERY board to control sensors.
After i configured I2C bus and other stuff in CubeMX, i included driver files using this instruction: https://forum.digikey.com/t/adding-the-vl53l1x-driver-to-an-stm32cube-project/13276
After that i'm able to receive range data in single ranging mode for both sensors (VL53L1 and VL53L1X) with the same code. I'm sending single range data via UART and it's correct.
After that i've tried to set my sensors in threshold mode (Autonomous mode for VL53L1) and nothing happened. I used UM2356 API Manual for VL53L1X (and also manual for VL54L1). Both sensors still works in signle ranging mode. Code example in the attachment.
Checking the status of the sensor pins with oscilloscope showed that I2C is working (I can see messages sending to 0x29 address, even if i'm specified sensor address as 0x52 in my code). Anyway i guess I2C is working because single ranging works correct. But I continue to see interruptions occurring on the corresponding sensor pin, regardless of the distance (threshold) settings at which the object must be located for the measurement to be triggered.
I've seen the thame question on this forum, but it's still without answer: https://community.st.com/s/question/0D53W00000N9zBpSAJ/vl53l1setthresholdconfig-api-not-working-when-setting-up-threshold-in-vl53l1x-sensor
I've checked all fucntions in debug mode using CebeIDE and everything returns '0' ERROR CODE. I also tried to add delays between functions but still no effect.
Can you please help me to understand where i'm wrong? If you need more information, i'll be glad to answer. Thank you.
2021-07-19 07:20 AM
Thresholds only work in Autonomous mode. (It's the only mode that run autonomously. The other modes expect that MCU is going to help them do the work.)
In the other modes, the raw histogram data is sent to the host for processing. It can do a better job than the tiny logic in the sensor, but it does have to deal with every range.
So put the Autonomous line back in and you should be all set.
2021-07-19 01:36 PM
Hello John, thanks for your answer.
Unfortunately, uncommenting the line with the function that takes the sensor to autonomous mode changes nothing. Moreover autonomous mode is specified only for VL53L1 sensor (in it's datasheet).
As i understand VL53L1X sensor has only one mode. VL53L1X API manual says that "The sensor performs the ranging continuously and autonomously with a programmable inter-measurement period." No other modes specified. For VL53L1 sensor there are 4 modes in accordance with datasheet (Ranging mode, Autonomous mode, Multizone scanning mode, Lite ranging mode).
It's seems that autonomous mode for VL53L1X is a default mode (and it doesn't have any others). And it says that i can use only one function: VL53L1_SetThresholdConfig() i don't need to call any other function for e.g. to choose autonomous mode.
Also VL53L1X API manual says that "It is possible to set a threshold of distance and/or signal detection criteria, then an interrupt is raised when the criteria is met. The device can be configured to operate in distance and/or signal threshold detection mode. The ranging data is reported to the host when the pre-configured criteria are matched." But i can see measuerement interrupt (Interrupt pin switches from HIGH to LOW state) even criteria doesn't met.
You are right that I can specify my thresholds using variables and compare these values with the measured ones using MCU. But I would like to try the capabilities described in the documentation and find out is it my or documentation mistake.
2021-07-19 02:05 PM
Everything you said is true.
But only in autonomous mode - the only mode for the VL53L1X - do thresholds work.
In every other mode, the sensor sends back the raw histogram data, which need intreprataion by the host.
however in all the modes WITHOUT thresholds being sent, you will get the interrupt when the sensor finishes processing the range data.
VL53L1_SetThresholdConfig() is only valid in Autonomous mode.
But as odd as it sounds, instead of enabling interrupts setting the Threshold actually disables them until your threshold critera is met.
You can of course use the P-NUCLEO-53L1A1 or A2 to prove this works.
2022-08-26 02:41 AM
Hello John,
I've the same problem as DBlok.1. We are seeing an interrupt after every measurement (1.5s in our case). We have tried to force the preset mode to VL53L1_PRESETMODE_AUTONOMOUS and distance mode to VL53L1_DISTANCEMODE_LONG. But there is not luck.
We need to have interrupt only when the distance exceeds the threshold (i.e. Distance.CrossMode = 1) as we need to minimise the MCU power consumption.
Below are the codes for initialise the sensor.
Thanks,
Arthur
vl53l1_status = VL53L1_WaitDeviceBooted(Dev);
vl53l1_status = VL53L1_DataInit(Dev);
vl53l1_status = VL53L1_StaticInit(Dev);
vl53l1_status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, 140*1000);
vl53l1_status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, 1.5*1000);
vl53l1_status = VL53L1_SetPresetMode(Dev, VL53L1_PRESETMODE_AUTONOMOUS);
vl53l1_status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_LONG);
detectionCfg.DetectionMode = 1; // 0 - no filter, 1 - filter on distance criteria
detectionCfg.Distance.CrossMode = 1; // 0 - threshold low, 1 - threshold high, 2 - out of window, 3 - inside window
detectionCfg.IntrNoTarget = 0; // 1 - no target detection mode
detectionCfg.Distance.Low = 800;
detectionCfg.Distance.High = 4000;
detectionCfg.Rate.CrossMode = 0;
detectionCfg.Rate.Low = 0;
detectionCfg.Rate.High = 0;
vl53l1_status = VL53L1_SetThresholdConfig(Dev, &detectionCfg);
vl53l1_status = VL53L1_StartMeasurement(Dev);