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

Implement DelayUs #23

Open
FoxyHawk opened this issue Aug 26, 2019 · 4 comments
Open

Implement DelayUs #23

FoxyHawk opened this issue Aug 26, 2019 · 4 comments

Comments

@FoxyHawk
Copy link

FoxyHawk commented Aug 26, 2019

let ticks = (ms as u64) * (self.clock_freq as u64) / 1000;

Changing 1000 by 1000000 could do it for Sleep ?

@Disasm
Copy link
Member

Disasm commented Aug 26, 2019

Yes, but no. DelayUs is often used for sub-ms delays, so it's better to use something more precise. You can see one of the examples here: https://github.com/riscv-rust/riscv-rust-quickstart/blob/5ff7048687e807b52d3df0d05dd0729a7c52bf79/examples/spi_wifi.rs#L106-L113, but I'm not sure it works correctly.

@FoxyHawk
Copy link
Author

At this point it relies more on the frequency than anything else. I suppose >10MHz is a non issue to get the us accuracy on a busy loop. Although it is not the same for sub MHz...

@Disasm
Copy link
Member

Disasm commented Aug 27, 2019

I agree that this approach works good for >10MHz (and timer works even better for core frequency <32kHz). However, I do not see how to achieve better precision in general than with counting core clock ticks.

@almindor
Copy link
Collaborator

this PR kinda solves this but as mentioned it's low res and anything < ~30us value will just be a slight NOOP slowdown. I think we should keep this open until a higher precision DelayUs is implemented.

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

No branches or pull requests

3 participants