cancel
Showing results for 
Search instead for 
Did you mean: 

Timing budget not kept in VL53L1X

MRoso.1
Associate II

I am trying to get consecutive measurements from the VL53L1X sensor but the timing budget is only kept on the first measurement with the below code

VL53L1X_BootState(dev, &sensorState);
VL53L1X_SensorInit(dev);
VL53L1X_SetDistanceMode(dev, 2);
VL53L1X_SetTimingBudgetInMs(dev, 500);
VL53L1X_SetInterMeasurementInMs(dev, 500); 
VL53L1X_StartRanging(dev);
 
    while (count<5) {
        count++;
        dataReady = 0;
        while (!dataReady) {
           VL53L1X_CheckForDataReady(dev, &dataReady);   
            Delay(2);
        }        
        VL53L1X_GetRangeStatus(dev, &status);
        aLidarCurrValueValid = !VL53L1X_GetDistance(dev, &aLidarCurrValue);
        
    }
    VL53L1X_StopRanging(dev);

So in the first measurement the timing budget is kept but in the consecutive ones the dataready byte is instantly 0 which seems to be wrong.

0693W00000Y8L5PQAV.png 

What am I doing wrong?

thanks

8 REPLIES 8
John E KVAM
ST Employee

I think you need a 'clear_interrupt' call. Even if you don't use interrupts, you need that call to tell the sensor that you have the data and are ready to go again.

VL53L1X_ERROR VL53L1X_ClearInterrupt(VL53L1_Dev_t dev)


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'

Hi John,

When I add this:

while (count<5) {
        count++;
        dataReady = 0;
        while (!dataReady) {
           VL53L1X_CheckForDataReady(dev, &dataReady);   
            Delay(2);
        }        
        VL53L1X_GetRangeStatus(dev, &status);
        aLidarCurrValueValid = !VL53L1X_GetDistance(dev, &aLidarCurrValue);
        VL53L1X_ClearInterrupt(dev);
    }

The sensor hangs at the second while(count<5) iteration (sensor measurement) with dataready being 0 indefinitely.

BTW all function calls return 0 as they should.

thanks

John E KVAM
ST Employee

Try clearing the interrupt immediately after issuing the start command. I seem to remember an issue where the clears and the readys get out of sync. The sensor apparently starts with an interrupt on. And that's causing you an issue.

=- john


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'

This is how my code looks like now and it's not working:

VL53L1X_BootState(dev, &sensorState);
VL53L1X_SensorInit(dev);
VL53L1X_SetDistanceMode(dev, 2);
VL53L1X_SetTimingBudgetInMs(dev, 500);
VL53L1X_SetInterMeasurementInMs(dev, 500); 
VL53L1X_StartRanging(dev);
VL53L1X_ClearInterrupt(dev);
 
    while (count<5) {
        count++;
        dataReady = 0;
        while (!dataReady) {
           VL53L1X_CheckForDataReady(dev, &dataReady);   
            Delay(2);
        }        
        VL53L1X_GetRangeStatus(dev, &status);
        aLidarCurrValueValid = !VL53L1X_GetDistance(dev, &aLidarCurrValue);
        VL53L1X_ClearInterrupt(dev);
    }
    VL53L1X_StopRanging(dev);

The sensor now gets stuck at the second iteration again.

So basically whenever I clear the interrupt the sensor gets stuck.

I have made it work by starting and then stopping the ranging to get a single measurement (EDIT the timing budget is still not being kept by starting-stopping for one measurement) but I'd like to do it the continuous way.

  

thanks

John E KVAM
ST Employee

this is how my code looks:

	VL53L1X_SensorInit(Dev1);	/* Initialize sensor  */
 
	VL53L1X_SetDistanceMode(Dev1, 1);
	VL53L1X_SetTimingBudgetInMs(Dev1, 100);
	VL53L1X_SetInterMeasurementInMs(Dev1, 100);
	//VL53L1X_SetROI(Dev1, MAX_SPADS_X, MAX_SPADS_Y);
	//VL53L1X_SetOffset(Dev1,20);
	//VL53L1X_SetDistanceThreshold(Dev1,100,300,3,1);   /* In window threshold */
	/* Choose polarity, 0=High (default), 1=Low  */
	//VL53L1X_SetInterruptPolarity(Dev1,0);
	//VL53L1X_SetROI(Dev1, 4, 5);
	UART_Print(MSG_START);
	snprintf(VL53L1X_BUFFER, sizeof(VL53L1X_BUFFER),
		 "Dist, stat, Signal, #Spad, Amb, SigPerSpad, AmbPerSpad\n");
	UART_Print(VL53L1X_BUFFER);
 
	while (1) {
		if (UART_Ready) {	/* Check for new command */
			UART_GetCommandFromUser(Dev1, UartComm_RXBuffer);
			/* Reboot RX to get new command */
			UART_Reboot(&Uart_RxIndex, &UART_Active, &UART_Ready,
				    Uart_RXBuffer);
		}
		/* Check for new data available  */
		if (VL53L1X_CheckForDataReady(Dev1))
		{
			VL53L1X_ClearInterrupt(Dev1);
			/* Get data and save it */
			Distance = VL53L1X_GetDistance(Dev1);
			RangeStatus = VL53L1X_GetRangeStatus(Dev1);
			SignalRate = VL53L1X_GetSignalRate(Dev1);
			SpadNb = VL53L1X_GetSpadNb(Dev1);
			AmbientRate = VL53L1X_GetAmbientRate(Dev1);
			SignalPerSpad = VL53L1X_GetSignalPerSpad(Dev1);
			AmbientPerSpad = VL53L1X_GetAmbientPerSpad(Dev1);
 
			snprintf(VL53L1X_BUFFER, sizeof(VL53L1X_BUFFER),
				 "%6u,%2u,%6u,%4u,%6u,%6u,%6u\n",
				 Distance,
				 RangeStatus,
				 SignalRate,
				 SpadNb,
				 AmbientRate,
				 SignalPerSpad,
				 AmbientPerSpad
				 );
			UART_Print(VL53L1X_BUFFER);
		}
	}

I call UART_GetCommandFromUser() to get the Start command, but assume it's called at that point.

But everything else looks the same.

It's really odd.

Couple of things to check...

Is the VCSEL light flashing. (Check with a web-cam or non-IPhone. IPhones have a very good IR filter that makes in impossible to see.)

if you have a scope, check the interrupt line. It toggles even if you don't use it.


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'

When the Start command is given the VCSEL flashes once and the interrupt line goes high.

Then when I clear the interrupt the interrupt line goes low and never high again.

If I use the Start-Stop technique for a single measurement and clear the interrupt, the timing budget is being kept and the interrupt line goes low upon clearing and then high when I Start ranging again. If I don't clear it, the timing budget is not kept the second measurement on.

I see your functions are a bit different. Did you change them yourself or am I using an older version of the library?

I got the library from here: STSW-IMG009 - VL53L1X ULD API (Ultra Lite Driver Application Programming Interface) - STMicroelectronics

John E KVAM
ST Employee

You are probably using a newer version. The VL53L3CX, L4CX, L4CD, L5CX and just now the L7CX variants have been released since the VL53L1X. But the L1X is still my favorite.

As a test, could your make measurement period just slightly longer than the TB as in:

  1. VL53L1X_SetTimingBudgetInMs(dev, 490);
  2. VL53L1X_SetInterMeasurementInMs(dev, 500);

A one-half second integration period is VERY long. I don't think there is much advantatage to it.

Probably get the same result with as few as 300ms.

(longer integration period means better accuracy, but there are deminishing returns.)

I just don't see anything else.


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'
MRoso.1
Associate II

I've tried with budget 200ms and inter measurement of 500ms with the same results.

Ok I guess I'll have to try and search for a bug in my code somewhere then and the Start Stop method works fine.

thanks