Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up transfers #26

Merged
merged 1 commit into from
Jun 5, 2022
Merged

Conversation

markisch
Copy link
Contributor

An I2C transmission has a significant overhead of ~10+1 I2C clock cycles.
Reducing the number of beginTransmission()/endTransmission() pairs
from twice every nibble to once per _send() hence speeds up transmission
times significantly.

The specified I2C clock rate speed of the PCF8574 chip is 100KHz.
Transmitting a single byte over I2C takes 9 clock ticks or 90us.
Even if the I2C bus is operated beyond the chip's spec in fast mode
at 400 kHz, any additional delays during transmission shorter than this
are unnecessary.

Commands are only executed after the second nibble is transmitted.
The 37us delay after the first nibble is hence unnecessary.

We now omit any additional delays and perform a transmission only once
per _send() command. This reduces the time from 4x(11+9) = 80 cycles to
4x9 + 11 = 47 cycles. Taking the delays into account, this changes the
time per command from 800us + 4*38us = 952us to 470us at the default
100kHz bus speed.

An I2C transmission has a significant overhead of ~10+1 I2C clock cycles.
Reducing the number of beginTransmission()/endTransmission() pairs
from twice every nibble to once per _send() hence speeds up transmission
times significantly.

The specified I2C clock rate speed of the PCF8574 chip is 100KHz.
Transmitting a single byte over I2C takes 9 clock ticks or 90us.
Even if the I2C bus is operated beyond the chip's spec in fast mode
at 400 kHz, any additional delays during transmission shorter than this
are unnecessary.

Commands are only executed after the second nibble is transmitted.
The 37us delay after the first nibble is hence unnecessary.

We now omit any additional delays and perform a transmission only once
per _send() command. This reduces the time from 4x(11+9) = 80 cycles to
4x9 + 11 = 47 cycles. Taking the delays into account, this changes the
time per command from 800us + 4*38us = 952us to 470us at the default
100kHz bus speed.
@markisch
Copy link
Contributor Author

Note that the changes by Pierre Henry @net234 implement something very similar and predate my commits. My own fork implements further optimisations on the 20% level elimating duplicated calculations at the expense of duplicating code. So for the general use case this might be better.
Resolves issue #12.

@mathertel
Copy link
Owner

Great pull request !
I did some testings and reading the manuals to verify.
Thanks a lot !

@mathertel mathertel merged commit 6e3b436 into mathertel:master Jun 5, 2022
@markisch markisch deleted the feature-faster branch June 5, 2022 19:16
@markisch
Copy link
Contributor Author

markisch commented Jun 5, 2022

Thanks! Theres yet one or two smaller pull requests to come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants