fix(ltr390): stuck ALS values when configured for ALS+UV readings #6723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
I have been experiencing stuck values for ALS readings when the sensor was configured to provide ALS & UV readings. By stuck values, I mean that only the first sample of ALS readings is taken and subsequent values are always exactly the same as the first while UV readings were changing as expected.
(ALS at the top, UV at the bottom)
If the sensor is configured for ALS only, the problem isn't there. So the issue isn't the sensor itself but how we interact with it.
I have made multiple experiments but it's still not exactly clear why the sensor behaves likes it does. The datasheet does mention a few interesting facts.
The datasheet is very vague. But my theory is the following:
update
method is triggered, setting the FSM to ALS modeupdate_interval
update
method is triggered again, setting FSM to ALS modeThe "error" would be somewhere between step 5 and 8. After step 5, the device is still in measurement mode and would produce an UV measurement that we won't read before changing the mode to ALS.
The device only clears the
UVS/ALS Data Status
after a read.So we're actively reading
MAIN_STATUS
, possibly preventing the sensor from updating the stored measurement. Then we're possibly assuming that the 'UVS/ALS Data Status' is reset after changing measurement modes.To boil it down:
I am not sure this is exactly what happens but I have experimented with a few fixes and the most elegant one is pretty obvious: when we're done with measurements, just put the sensor in standby.
This is done by setting
LTR390_CTRL_EN
to 0. When we want to take new measurements, we set it to1
in addition to the measurement mode. I have added two extra delays: one for wakeup and one for the ADC settle time (taken from the datasheet)In addition to fixing stuck values for ALS, the sensor is only pulling 1uA (in standby) compared to 100-110uA.
Data after the fix
Types of changes
Test Environment
Example entry for
config.yaml
:Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: