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

add subticks to RP2040 port_get_raw_ticks #9229

Merged
merged 2 commits into from May 13, 2024

Conversation

timchinowsky
Copy link

The RP2040 port of monotonic_ns() only has millisecond precision - the subtick value is not used:

uint64_t port_get_raw_ticks(uint8_t *subticks) {
uint64_t microseconds = time_us_64();
return 1024 * (microseconds / 1000000) + (microseconds % 1000000) / 977;
}

Added 7234375 to fill in the subtick field. Testing with this code to look at deltas between successive calls to monotonic_ns():

import time
def test_ns(n=200):
    t0 = time.monotonic_ns()
    for i in range(n):
        t1 = time.monotonic_ns()
        print(t1-t0)
        t0 = t1
test_ns()

Plotting the returned data from before and after the change:

image

Before the change, the data is granular to 1 ms, e.g.

976563
0
0
0
0
976562
0
0
0
0
976563

After, it does better:

244144
213613
183108
183108
213626
213626
213612
244144
152590
213626
244131

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

@tannewt tannewt merged commit d857738 into adafruit:main May 13, 2024
112 checks passed
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.

None yet

2 participants