-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
More accurate time reporting #519
Comments
I was attempting to work with a 433Mhz radio transmitter which required writing to a pin at 200 microsecond intervals. Even if a function similar to the Arduino |
@CameronDevine Interesting! How much data do you know you need to write ahead of time? Something like PulseOut might be adequate. It looks like it requires a carrier PWM signal though it could just be constant. |
came from here: asking there as well: https://forums.adafruit.com/viewtopic.php?f=60&t=129222 |
I too would like to see something better than monotonic, since it's not stable and loses precision as time goes on. Or maybe I just need to learn the CircuitPython way to do longer term ramping up/down of a NeoPixel, while not doing a busy wait, so I can handle other inputs that come in. Right now I just try to do: timetofire = timer.Monotonic() + delay continue on looking for keyboard input, etc.Does this make sense? I also wish it was more clearly documented what resolution monotonic is counting in, since it's not quite seconds, but maybe milliseconds? |
@l8gravely On the SAMD21 it is millisecond. I'm still unsure we want to provide precise timing because we pause the VM from time to time to do other things. I'm worried about making timing promises we don't always keep. If we did, I think we could introduce a @l8gravely also follow #619 for a different way to do things concurrently. |
Would it be possible to have a variable which states the approximate interval at which |
like @l8gravely I want a monotonic time source which doesn't lose precision. In my project, I want to show the seconds and fractions of seconds based on NTP time, but it starts to lose precision as the For me, directly exposing |
I was thinking we could add a |
I'm going to take a stab at this (pycon sprints) |
I'm trying to sample a 1kHz modulated light beam at 100µs intervals. About every 1/32 sec I go into a coma for almost 1/32 sec while the system does its other things. More precise timing would not help unless we also had a "suspend the other system things for a mo while I do this time-critical thing" function... |
@CBMalloch how is the light beam being interfaced to the microcontroller? We may be able to add a C helper for it. It's highly unlikely we'll ever allow for predictable timing in Python execution. There are too many critical things happening around the VM to do it. |
As
|
This is intended to be compatible with Python 3.7's time.monotonic_ns. The "actual resolution" is 1ms due to this being the unit at which common_hal_time_monotonic ticks. Closes adafruit#519
Hi all, I've been playing with this and just realized that time.monotonic() is only good to 1 decimal. But, learned that is dependent on time since last restarted or reset(?) Just wanted to chime in to say that I am also looking for the feature. Thanks, -Parsko |
I'll chime in on this too, since I recently ran into this limitation after switching a project from Arduino to CircuitPython. The project requires events triggered with at least 0.1 second resolution, but using monotonic() begins to fail. The only fix is to have the device reset as the resolution limit approaches. This is insufficient for my use case. I can't think of another way around it. Even a rollover counter like millis() is preferable to monotonic(), as at least I can keep track of the rollovers and manage my own counter. Helping people port from Arduino also would argue for a millis()-like function, even if such does not exist in CPython. Thanks for listening! |
So, I just put 4.0.0 alpha 5 on my Trinket M0 expecting to be able to use time.monotonic_ns() This is what I get in REPL:
I wonder why it's not enabled? |
We're only enabling |
Ah, that's unfortunate to hear. Thank you for explaining. |
>>>> "Dan" == Dan Halbert ***@***.***> writes:
Dan> We're only enabling time.monotonic_ns() on the Express builds. We
Dan> need Python long integers for monotonic_ns() or else the values
Dan> will wrap around after a few seconds. Unfortunately there's not
Dan> enough room in the Trinket or Gemma builds for long integers
Dan> (longints).
How about time.monotonic_ms() on the Gemmas, with a lower resolution?
I don't even care too much if it wraps, because if I know to check for
that, it's not too bad.
John
|
Hello, I am totally new to this circuitpython stuff. |
I was able to get this running on my Metro M0 Express, but it looks like Is there an equivalent to the |
@dhalbert Why does it make the builds bigger, is this just because literal ints end up with a larger representation in mpy files? Would having yet another function to return (seconds, milliseconds) as an (int,int) tuple be another option to support all boards? (Discussion/issue in https://forums.adafruit.com/viewtopic.php?f=60&t=158501 reminded me of this) |
@kevinjwalters The builds are bigger because we need longints to support We have talked about adding another function, but it would not be in |
Several users have asked for time reporting that's more precise than the millisecond ticks provided by
time.monotonic()
. Use cases and proposals welcome here.The text was updated successfully, but these errors were encountered: