cancel
Showing results for 
Search instead for 
Did you mean: 

BUG: VL53L1X API for uC where int is 16 bits (AVR)

pannagger
Associate

Hi, 

I asked for help because my measurements took >> 15 seconds (up to 30s) in:
https://community.st.com/t5/imaging-sensors/vl53l1-measurement-takes-up-to-30-seconds/td-p/843640

Now after hours of debugging i found a bug in the API at least for platforms where an Integer is not 32 bit, in:
vl53l1_core_support.c:114 
the code is:

pll_period_us = (0x01 << 30) / fast_osc_frequency;

 but on AVR uC like atmega644 0x01 is 16 bit wide. Which leads to pll_period_us = 0.

The wrong value messes up all tim_cfg and gen_cfg, and introduces weird behavior.

Fix:

pll_period_us = (0x01UL << 30) / fast_osc_frequency;

Telling the compiler to use unsigned long fixed the problem for me.

This bug should be fixed to be more platform independent I suggest.

Kind regards,
Philip

0 REPLIES 0