cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple VL53L1X interrupt mode

Talex.1
Associate II

For my project, I need to use 2 Vl53L1X on the same I2C bus. The setup is good and i can use them sequentially. But I would like use them in interrupt mode (for have a maximum speed).

In short/interrupt mode with one sensor i have 20ms time beetween 2 measurements.

But with two sensors the minimum time is about 45ms.

Timming congiguration :

    status = VL53L1_SetDistanceMode(Device01, VL53L1_DISTANCEMODE_SHORT);

    status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Device01, 20000);

    status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Device01, 24);

    status = VL53L1_SetDistanceMode(Device02, VL53L1_DISTANCEMODE_SHORT);

    status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Device02, 20000);

    status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Device02, 26);

Main loop

do{

        status = VL53L1_StartMeasurement(Device01);

        status = VL53L1_StartMeasurement(DeviceSol);

        __WFI();

       if(IntCount2 !=0 ){

             IntCount2=0;

             if (firstTimeInterrupt ==0){

                status = VL53L1_GetRangingMeasurementData(Device01, &RangingDataPneu);

                if(status==0){

                   end = (int)HAL_GetTick();

                   printf("Temps PNEU %i ms \n\r",end-start);

                   printf("Mesure PNEU = %d\n\r",RangingDataPneu.RangeMilliMeter);

                   start = (int)HAL_GetTick();

                }

                status = VL53L1_ClearInterruptAndStartMeasurement(Device01);

             }

             else{ //Must not read data at the first interrupt, must clear interrupt and start measurement

                status = VL53L1_ClearInterruptAndStartMeasurement(Device01);

                firstTimeInterrupt = 0;

                //printf("[else ] \n\r");

             }

          }

        if(IntCount !=0 ){

              IntCount=0;

              if (firstTimeInterrupt2 ==0){

                 status = VL53L1_GetRangingMeasurementData(Device02, &RangingDataSol);

                 if(status==0){

                    end1 = (int)HAL_GetTick();

                    printf("Temps SOL %i ms \n\r",end1-start1);

                    printf("Mesure SOL = %d\n\r",RangingDataSol.RangeMilliMeter);

                    start1 = (int)HAL_GetTick();

                 }

                 status = VL53L1_ClearInterruptAndStartMeasurement(Device02);

              }

              else{ //Must not read data at the first interrupt, must clear interrupt and start measurement

                 status = VL53L1_ClearInterruptAndStartMeasurement(Device02);

                 firstTimeInterrupt2 = 0;

                 //printf("[else ] \n\r");

              }

           }

       }while(1);

Interrupt configuration

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

      if (GPIO_Pin==VL53_PIN_Pin)

      {

         IntCount++;

      }

      if (GPIO_Pin==GPIO_PIN_9)

      {

         IntCount2++;

      }

}

I would like to know if it's possible and how configure a programm to have the maximum speed.

Thanks

Best Regards

5 REPLIES 5
John E KVAM
ST Employee

Try putting you VL53L1_ClearInterruptAndStartMeasurement() BEFORE your prints.

my guess is by delaying the interrupt clear, you are missing the start trigger of the Intermeasurement period.

If you miss the start, it will not start again until the next Intermeasurement period, effectively doubling your period.

You could also try making the Intermeasurement period slightly longer than the timing budget to account for the delays.

  • john

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question. It helps the next guy.
Talex.1
Associate II

I tried your recommendation to clear the interruption before prints. I set differents intermeasurement period and timming budget for the two sensors but there are wrong time. he is never the same... It's doesen't work

Thanks

Best Regards

John E KVAM
ST Employee

so let's try this:

Set the timing budget to 20 and the intermeasurement period to 21 for both sensors. Then call L53L1_ClearInterruptAndStartMeasurement() even before you call VL53L1_GetRangingMeasurementData(Device02, &RangingDataSol);

there are two separate clocks - one governing the Timing budget and the other the Intermeasurement period. It could be the clocks are skewed just enough that you miss the start. If this happens you will get 2X the intermeasurement period.

I'm going to guess (and it's only a guess) that the two different Intermeasurement periods make the timing too hard to evaluate. So it's not obvious that you are seeing the 2X period.

good luck - we will fix this.

Are you running with an operating system?

There isn't some other process interfering with the timely reaction to the interrupt is there?

If a separate process got in and help off your VL53L1_ClearInterruptAndStartMeasurement() that would throw off the timing as well.


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question. It helps the next guy.
Talex.1
Associate II

Sometimes i have good results and the two VL works in interrupts modes. But sometime the value of GPIO1 Stay at 0.

On the Datasheet the value of GPIO1 goes from 0 to 1 with VL53L1_ClearInterruptAndStartMeasurement() function. But sometimes the return of VL53L1_ClearInterruptAndStartMeasurement() function equals 0 but the value of GPIO1 stay block at 0

John E KVAM
ST Employee

I hate problems that happen 'sometimes'. Those are the hardest to find.

One customer had an issue solved by clearing the initial interrupt twice. His assumption that the pin was floating and needed to be cleared before he really got going. Perhaps you could try that if by 'sometimes', you mean 'sometimes at startup'.

But if the interrupts just stop during ranging I can only think of 3 reasons:

1) you are using thresholds and will not get an interrupt until you meet the condition of the threshold

2) the chip somehow got reset

3) You need an extra clear_interrupt command.

If this happens during ranging, and the system just 'stops' for some reason, I'm guessing #[2 above.]​ 

A reset - even a partial one - can occur if the XShut pin glitches. That pin is VERY sensitive to noise. Perhaps you could put a really strong pull up on that line - or a large cap.

One thing you can check.

While running, use a cellphone camera to see if you can see the red flash of the laser. (iPhones don't work for this - their lens has a really good I/R filter). But laptop cameras work as well. Then check to see if the red flash stops when you get into this condition. That will tell you if the chip is running.

Good luck.

  • john

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question. It helps the next guy.