-
Notifications
You must be signed in to change notification settings - Fork 18
Microsecond Timing? #9
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
Comments
I don't recommend using AceRoutine (or any cooperative multitasking framework for that matter) for sub-millisecond timing. Once your coroutine gives up control, there is no guarantee that it will regain control within any timeframe because the other coroutines may take arbitrary amounts of time. I suppose if ALL your coroutines take much less than the desiredMicroSeconds that you are waiting for, then it MIGHT work, but I don't know, this seems too fragile to be robust. My guess is that if you need this level of accurate timing, you probably want to a timer, and use an interrupt service routine instead. |
Well, I'm taking care to keep my coroutines really, really tight, and I was going to |
Wow, that Teensy 4.0 is super fast. If you use only a handful of coroutines, and make sure that they yield within a few microseconds, then maybe AceRoutine could work for you. With regards to adding a convenience macro |
I guess I have a couple of points about this.
|
No need to be frustrated. :-) The building blocks for what you want are already there. The convenience macro is something like: #define COROUTINE_DELAY_MICROS(microCounter, delayMicros) \
do { \
microCounter = micros(); \
COROUTINE_AWAIT(micros() - microCounter >= delayMicros); \
} while (false) To use this, you need to provide the const uint16_t DELAY_MICROS = 200;
COROUTINE(foo) {
static uint16_t microCounter;
COROUTINE_LOOP() {
...
COROUTINE_DELAY_MICROS(microCounter, DELAY_MICROS);
}
} I don't have any program that needs microsecond resolution to be able to test this. Let me know if it works for you. Edit: There's a problem with integer overflow in the above code. Change the COROUTINE_AWAIT((uint16_t)(micros() - microCounter) >= delayMicros); \
``` |
Thanks very much for those, my original question was really if there was a fundamental reason they wouldn't work. |
…void ambiguity with global millis() method (#9)
…INE_DELAY(), COROUTINE_DELAY_MILLIS() and COROUTINE_DELAY_MICROS() (#9)
I had some idle time, so I implemented a |
I've been playing around, and came to similar conclusions. However, I have to say that's great! |
Cool, sounds like a lot of fun. This feature has been released with v0.3, so I'm going to close this issue. If you run into trouble feel free to reopen, or create a new issue. |
Thanks again! |
Pity you dropped official support for microsecond timing, although I understand why. |
That's a great video. Just out of curiosity, because I get no feedback on how my libraries are used, what hardware stack did you use, what does the The fundamental problem with The other problem that I find myself constantly struggling with is the tension between 8-bit processors (with little memory) and 32-bit processors (with lots of memory). Things would be so much easier if I didn't have to worry about the constraints of 8-bit processors. Maybe having 2 versions of the library would make sense, then but I'd have to maintain both versions. Sometimes, adding a bunch of Hmm, I think got an idea about supporting |
The board was a stock Arduino Mega, running a set of solid state relays in turn switching pneumatic valves. Each pop had its own separate air tank so one didn't suck air from the others. I agree with you about minority cases hindering the general library user BTW. In one of my other lives, I find myself trying to explain why a coroutine is so much nicer than callbacks! And thanks for such a great piece of software! |
Thanks for the info. Sounds like a lot of fun. Ok, I have reimplemented |
+1 |
I find myself needing sub-millisecond timings.
Presumably COROUTINE_AWAIT(microSeconds() > somestaticvariable)
will work, however, is there a better way, or is it worth making a new
convenience macro?
The text was updated successfully, but these errors were encountered: