Skip to content

Suggested improvements for micros() and the timer0 overflow ISR #48

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aweatherguy
Copy link

This is a suggestion for speeding up micros() a bit and a slight reduction in overall system interrupt latency.

There are a lot of comments added about the changes to help understand the intent. These may be cleaned up and/or removed as desired (if the pull request is accepted).

  1. The 32-bit timer0_overflow_count has been renamed to timer0_micros and now counts in microseconds directly. The rename might be okay as no other parts of the core refer to it. However, since timer0_overflow_count was not static, it is possible that clients (i.e. sketches) are referring to it in which case the old name s/b kept.

  2. With the change above, micros() no longer needs a 32-bit multiply to compute the result. Since the 32-bit counter is now directly in microseconds, all that is required is a 16-bit multiply of TCNT0 to add to the counter. This saves well over 20 instructions (call to 32-bit multiply library function) during execution, but the overall code is a few bytes larger.

  3. micros() keeps interrupts disabled for a shorter length of time now, resulting in slightly improved overall
    interrupt latency for other interrupts.

1) The 32-bit timer0_overflow_count has been renamed to timer0_micros and now counts in microseconds directly.
   The rename should be okay as none of the rest of the core refers to it.
   Since it was not static, it is possible that clients are referring to it in which case the old name s/b kept.

2) micros() no longer needs a 32-bit multiply to compute the result. Since the 32-bit counter is now directly
   in microseconds, all that is required is a 16-bit multiply of TCNT0 to add to the counter. This saves well over
   20 instructions during execution, but he overall code is a few bytes larger.

3) micros() keeps interrupts disable for a shorter length of time now, resulting in slightly improved overall
   interrupt latency for other interrupts.
@aweatherguy
Copy link
Author

Regarding (1) above, I realized that if clients (sketches) are referring to timer0_overflow, it doesn't really matter if that's renamed or not -- changing the units from overflow count to microseconds would break them anyway. The validity of this whole idea depends on whether clients are using timer0_overflow_count or not (or if they are, is it okay to break them).

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zoltan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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