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

Fix timing bug in pulseIn() #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SpenceKonde
Copy link
Contributor

Timeout ticked by at 16/11ths of the specified speed prior to the beginning of the pulse being measured (and, as far as I can tell, always has!)

update from arduino head
Prior to seeing the pulse start, the timeout would tick by at 16/11ths of the speed it should because the first two loops - the first two loops aren't also incrementing width, which requires 5 cycles, so of course they'll run faster! This change adds 5 cycles of nops to each loop (3 instructions - 2 rjmp+0, 1 nop). This cost 6 instruction words of flash - however, the compiler missed a chance to share the set of pop instructions between the two paths to return; doing this saved 6 instruction words, getting us back the flash the timing fix took away.
@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

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