Why is the ADS1115 on I2C so ultra slow ? (solved)
# help
f
Can you define what "slow" means?
How many measurements do you see?
I don't have any ads1115 yet, so can't test the code, but the
test.toit
itself looks good.
k
slow means 1 measure per second. In the example the led toggles each step without sleep.
f
That's really slow...
I'm wondering if we are stuck in the sleep loop of the driver (waiting for the value to be ready)
k
i changed the ads1115 and measure now ~140ms !
f
Interesting
k
the lowest is slowest

https://cdn.discordapp.com/attachments/1125432091543347255/1125451214193176697/ads1115.png

f
Weird
Would be interesting to know whether it's faster with other systems or if Toit does something different
k
I will check it out
f
Thanks
k
=> 34ms with Arduino SW
f
Even for the 1s one?
k
yes measure with the slow ADS1115, the faster one does it in 12 ms
f
Strange.
k
I guess the used i2c implementation could be improved
f
Not that much
It's mapped to the hardware I2C. Shouldn't be that slow.
Need to go now, but something that I will need to investigate. I should get the same sensor soon.
k
GPIO Speed test (fast DO toggle): toit: 5,72 µs, ~ 175kHz Arduino : 7.6 µs, ~ 132 kHz
f
Nice.
There is one thing that Toit currently doesn't do very well:
sleep
for very short periods. We are using the Freertos timer underneath and that one only has a granularity of 10ms. So the driver's
sleep --ms=1
will only come back after 10ms. But that doesn't explain the delays of ~1s.
k
it | know works | why -------+------- NO | NO : usually NO | YES ==> knowing what to do YES | NO : still learning YES | YES : asymtote
so for hw close driver hacking small delays are needed
f
It would be nice to make
sleep
work better with less granularity. It shouldn't be an issue here, though. As I said: I should get an ADS1115 soon, and will investigate then. Can you confirm that it's the sleep loop that takes so much time? Would be interesting to count the number of iterations of that loop. Checking how often the device responds with "not ready yet".
I finally got my Ads1115 sensors. After a bit of testing I figured out the problem. The constructor is setting the
config
register. It directly ors in the
RATES_DR_475SPS_
constant. However, the location of the data rate is bits 5-7. So there is a shift needed:
Copy code
| RATES_DR_475SPS_ << 5
Alternatively, the
RATES_DR_475SPS_
constant should have the bits already shifted. (That would actually be more consistent with the rest of the code). Once I fixed that, I also changed the
sleep --ms=1
to
yield
. The driver should probably remember the samples-per-second, and then either just
yield
(if it's less than 10ms), or
sleep
otherwise. With that change the driver is nicely computing new values close to the speed that it should.
@kaxori let me know if you want to do the change yourself, or if you prefer a PR.
k
👍🏻 good job, i prefer PR (you has the last look at it)
f
Sounds good. Don't hesitate to ping me if it looks like I forgot.
k
I just tried it out 🤩