Skip to content

Fix timing bug in pulseIn()#76

Open
SpenceKonde wants to merge 2 commits intoarduino:masterfrom
SpenceKonde:master
Open

Fix timing bug in pulseIn()#76
SpenceKonde wants to merge 2 commits intoarduino:masterfrom
SpenceKonde:master

Conversation

@SpenceKonde
Copy link
Copy Markdown
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
Copy Markdown

CLAassistant commented Apr 9, 2021

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.
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