0

Making a time slicer
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Making a time slicer

by deleng on Fri Dec 14, 2018 11:22 am

There seems to be a possible way to use time.monotonic() to make a time slicer. BUT , is there a way to reset the float number from time.monotonic() to prevent an overflow condition?

deleng
 
Posts: 10
Joined: Sat Jan 12, 2013 2:29 pm

Re: Making a time slicer

by danhalbert on Fri Dec 14, 2018 11:43 am

time.monotonic() is not going overflow, because it counts seconds in floating point, and 1e38 seconds is very large. However, it will of course lose precision as the number of seconds increases.

On boards with longint turned on, you can use time.monotonic_ns(), recently added. There's a lot of discussion about that here:
https://github.com/adafruit/circuitpython/issues/519

danhalbert
 
Posts: 1737
Joined: Tue Aug 08, 2017 12:37 pm

Re: Making a time slicer

by deleng on Sat Dec 15, 2018 11:37 am

OK, same issue. I need a way to have an incrementing variable that I can have count from 0 to 99 that is time based. Is there a way to do that????

Without that there does NOT seem to be a way to make a time slicer using the D21 based boards and Circuitpython. Unless that can be done these boards cannot be easily adapted to do realtime embedded tasks. Perhaps a simple reset to time.monotonic() is the simplest path out of this issue. Any thoughts anyone????

deleng
 
Posts: 10
Joined: Sat Jan 12, 2013 2:29 pm

Re: Making a time slicer

by adafruit_support_bill on Sat Dec 15, 2018 1:37 pm

Without that there does NOT seem to be a way to make a time slicer using the D21 based boards and Circuitpython. Unless that can be done these boards cannot be easily adapted to do realtime embedded tasks.

Time slicing far from the only - or best - approach for implementing real-time embedded systems.

adafruit_support_bill
 
Posts: 74627
Joined: Sat Feb 07, 2009 10:11 am

Re: Making a time slicer

by deleng on Sat Dec 15, 2018 2:52 pm

OK, so what WILL work.

deleng
 
Posts: 10
Joined: Sat Jan 12, 2013 2:29 pm

Re: Making a time slicer

by danhalbert on Sat Dec 15, 2018 3:20 pm

The SAMD21 boards with an SPI flash chip (Feather M0 Express, Metro M0 Express, etc.) do have longint support in CircuitPython 3.x.

We are trying not to add new features to standard "regular Python" (CPython) modules such as `time`, to maintain compatibility. So we're unlikely to add a reset function to the clocks there.

At this time we don't promote CircuitPython as a tool for high-speed real-time embedded programming. Due to garbage collection and the general speed of running Python, precise timing or speedy real-time response are difficult. Concurrency and asynchronous programming are also difficult concepts, and we're reluctant to add interrupts and the like. We're thinking about safer and simpler asynchronous programming models, but we haven't added anything yet.

danhalbert
 
Posts: 1737
Joined: Tue Aug 08, 2017 12:37 pm

Re: Making a time slicer

by adafruit_support_bill on Sat Dec 15, 2018 3:24 pm

OK, so what WILL work.

There are various forms of cooperative multitasking, including the basic 'round-robin' approach described here: https://learn.adafruit.com/multi-taskin ... 1/overview
If you wanted to get fancy, you could implement a simple rate-monotonic prioritization scheme on top of that.

adafruit_support_bill
 
Posts: 74627
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.