I have a need for timing things in general, sometime particularly short durations. To this extent I have a couple of questions on best practices in this context
Suppose that I have something like the following
where I have 2 events (one dependent on the other) and an LED heartbeat.
I've picked up the habit of using elapsedMicros and elapsedMillis in such instances, where I use one of these objects for each event and set it to 0 during the event. My logic in this is that checking for ">=" is cheaper than "event1_timer - THRESHOLD1 >= 0"
Of course this means that each of this event timers can really only be used for one thing. So given 6 events with unique timing needs, I'll need 6 instances of elapsedMicros/Millis, depending on the durations.
My questions are:
Suppose that I have something like the following
Code:
void loop(){
if (event1_timer >= THRESHOLD1){
// do some stuff
event1_timer = 0;
event2_flag = 1;
}
if (event2 && (event2_timer >= THRESHOLD2){
// some other stuff
}
if (led_timer >= THRESHOLD_LED){
digitalToggleFast(_led_);
led_timer = 0
}
}
where I have 2 events (one dependent on the other) and an LED heartbeat.
I've picked up the habit of using elapsedMicros and elapsedMillis in such instances, where I use one of these objects for each event and set it to 0 during the event. My logic in this is that checking for ">=" is cheaper than "event1_timer - THRESHOLD1 >= 0"
Of course this means that each of this event timers can really only be used for one thing. So given 6 events with unique timing needs, I'll need 6 instances of elapsedMicros/Millis, depending on the durations.
My questions are:
- is there an explicit point where it begins to "cost more" to use so many instances vs making the subtraction and comparison
- does it even really make any difference to set to 0 to avoid this subtraction
- In what circumstances (given timing allows without overflow) does it make better sense to use something like ARM_DWT_CYCCNT as opposed to elapsedMicros?
- Obviously ARM_DWT_CYCCNT has better resolution, but does it have the same drift as elapsedMicros? I'm just unsure what the use case for ARM_DWT_CYCCNT over elapsedMicros would be, assuming both offer sufficient resolution and duration