Skip to content

[Time] delayMicroseconds() accuracy + Fix ticks per ms value used to compute micros #620

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

Merged
merged 2 commits into from
Sep 2, 2019

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Aug 29, 2019

This PR mainly fixes issue with delayMicroseconds() on Cortex-M0 as for other series it uses DWT->CYCCNT which is more accurate.

Then OneWire is now functional on all series.

GPIO toggling at 5µs on a NUCLEO-L053R8:

With old implementation:
image
With new implementation:
image

Fixes #412

@fpistm fpistm added enhancement New feature or request fix 🩹 Bug fix labels Aug 29, 2019
@fpistm fpistm added this to the 1.7.0 milestone Aug 29, 2019
@fpistm fpistm self-assigned this Aug 29, 2019
@fpistm fpistm requested a review from ABOSTM August 30, 2019 06:41
fpistm added 2 commits August 30, 2019 15:39
The timer interrupt or COUNTFLAG bit (in the SysTick Control
and Status register) is activated on the transition from 1 to 0,
therefore it activates every n+1 clock ticks.
So, ticks per ms is SysTick->LOAD +1.

Signed-off-by: Frederic Pillon <[email protected]>
delayMicroseconds() should not rely to getCurrentMicros()
and should only compute required ticks for the delay
requested.

This allow to use it even if interrupts are disabled.
Example for OneWire library.

Fixes stm32duino#412

Signed-off-by: Frederic Pillon <[email protected]>
Copy link
Contributor

@ABOSTM ABOSTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fpistm fpistm merged commit d2db949 into stm32duino:master Sep 2, 2019
@fpistm fpistm deleted the TimeFix branch September 2, 2019 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix 🩹 Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support OneWire device (ex: DS1822)
2 participants