cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L5 Can't get 4x4_CONTINUOUS mode to run faster than 17Hz.

MVand.3
Associate II

My use case would benefit from high speed but I'm having trouble getting it to run at 60Hz. I'm using the X-NUCLEO-53L5A1 on an NUCLEO-L476RG board with the XCUBE-TOF1 software. I'm using the SimpleRanging example program: XCUBE-TOF1\Projects\NUCLEO-L476RG\Examples\53L5A1\53L5A1_SimpleRanging

I have tried this in polling mode with a short polling period and also in interrupt mode. Neither will go faster than 17Hz.

I edit this line in app_x-cube-tof1.c to increase the speed:

Profile.Frequency = 60;

I inserted a simple HAL_GetTick() and calculate the actual frequency and it wont run faster than 16.67Hz. 5Hz and 10Hz work great but then it maxes out as shown here:

Profile.Frequency = 5; /* Actually runs at 4.97Hz */
Profile.Frequency = 10; /* Actually runs at 9.95Hz */
Profile.Frequency = 20; /* Actually runs at 16.59Hz */
Profile.Frequency = 30; /* Actually runs at 16.61Hz */
Profile.Frequency = 60; /* Actually runs at 16.67Hz */

Any ideas what is limiting it or where I should optimize the code to speed things up? Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
MVand.3
Associate II

Thanks John! I got it running at 60Hz! I'll post what I did so others may learn from it. I was able to increase the I2C speed by setting the I2C mode to "Fast Mode Plus" in CubeMX and the frequency to 1MHz. Somehow I still only measure 850kHz on the I2C clock line (SCL) with my scope but I suppose that's fast enough. That got me up to 19.18Hz. I also turned off some of the data that the sensor returns with this code in /Drivers/BSP/Components/vl53l5cx/porting/platform.h

//To ensure data consistency, ST recommends to always keep ‘number of target detected’ and ‘target status’ enabled
#define VL53L5CX_DISABLE_AMBIENT_PER_SPAD
#define VL53L5CX_DISABLE_NB_SPADS_ENABLED
//#define VL53L5CX_DISABLE_NB_TARGET_DETECTED
#define VL53L5CX_DISABLE_SIGNAL_PER_SPAD
#define VL53L5CX_DISABLE_RANGE_SIGMA_MM
//#define VL53L5CX_DISABLE_DISTANCE_MM
//#define VL53L5CX_DISABLE_TARGET_STATUS
#define VL53L5CX_DISABLE_REFLECTANCE_PERCENT
#define VL53L5CX_DISABLE_MOTION_INDICATOR

That got it up to 20.36Hz. Then I realized that the USART serial bus was the bottleneck so I eliminated most of the text output by the app so it just sends out the distance. Now I can get 60Hz reliably. By the way I didn't need to adjust Profile.TimingBudget=30 because as stated in the manual that setting is only used in autonomous mode. Here's what my new serial output looks like:

|1936|1886|1848|1825|
|1885|1815|1798|1760|
|1819|1788|1757|1713|
|1774|1738|1711|1393|
uptime(ms):63962
frequency(Hz):60.00

Thank you for your quick reply. It definitely put me on the right path! -Martin

View solution in original post

2 REPLIES 2
John E KVAM
ST Employee

Humm, that's a good one.

If you use:

  Profile.RangingProfile = RS_PROFILE_4x4_CONTINUOUS;
  Profile.TimingBudget = 30; /* 5 ms < TimingBudget < 100 ms */
  Profile.Frequency = 5; /* Hz */
  Profile.EnableAmbient = 0; /* Enable: 1, Disable: 0 */
  Profile.EnableSignal = 0; /* Enable: 1, Disable: 0 */

You should get up to 33 Hz. After that, you would need to lower the TimingBudget.

I'm going to guess it's a limitation of your I2C.

The sensor will run a second time after the initial run, but to prevent loss of data it stalls until you read out all the data. And there is potentially a lot of data.

So change the I2C speed. You can either go back to CubeMX or you can simply change it in your initialization code.

If that doesn't do it, have a look at what information you are asking the sensor to return.

Perhaps you can lower that.

  • john

If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
MVand.3
Associate II

Thanks John! I got it running at 60Hz! I'll post what I did so others may learn from it. I was able to increase the I2C speed by setting the I2C mode to "Fast Mode Plus" in CubeMX and the frequency to 1MHz. Somehow I still only measure 850kHz on the I2C clock line (SCL) with my scope but I suppose that's fast enough. That got me up to 19.18Hz. I also turned off some of the data that the sensor returns with this code in /Drivers/BSP/Components/vl53l5cx/porting/platform.h

//To ensure data consistency, ST recommends to always keep ‘number of target detected’ and ‘target status’ enabled
#define VL53L5CX_DISABLE_AMBIENT_PER_SPAD
#define VL53L5CX_DISABLE_NB_SPADS_ENABLED
//#define VL53L5CX_DISABLE_NB_TARGET_DETECTED
#define VL53L5CX_DISABLE_SIGNAL_PER_SPAD
#define VL53L5CX_DISABLE_RANGE_SIGMA_MM
//#define VL53L5CX_DISABLE_DISTANCE_MM
//#define VL53L5CX_DISABLE_TARGET_STATUS
#define VL53L5CX_DISABLE_REFLECTANCE_PERCENT
#define VL53L5CX_DISABLE_MOTION_INDICATOR

That got it up to 20.36Hz. Then I realized that the USART serial bus was the bottleneck so I eliminated most of the text output by the app so it just sends out the distance. Now I can get 60Hz reliably. By the way I didn't need to adjust Profile.TimingBudget=30 because as stated in the manual that setting is only used in autonomous mode. Here's what my new serial output looks like:

|1936|1886|1848|1825|
|1885|1815|1798|1760|
|1819|1788|1757|1713|
|1774|1738|1711|1393|
uptime(ms):63962
frequency(Hz):60.00

Thank you for your quick reply. It definitely put me on the right path! -Martin