A question on how clocks fire

Dear all,
I've found in the community a simple tutorial (by Alaqmar_Bohori) on clocks use, but I have still a doubt:
if a clock period is shorter than its execution time, does it add its period to the execution time, or it fires immediately after its blocks have been completed (since the period should be already elapsed again, like in a HW timer automatically retriggered) ?
In numbers:
App with 1! clock ;
Clock period = 10 ms;
Its execution time = 50 ms;
Which one of below statements is true ?

  • the clock fires every 60 ms.
  • the clock fires every 50 ms
    Thanks a lot and sorry for the "stupid question" :innocent:


Avoid such a scenario by only firing the clock after the execution has finished (e.g. set a clock enabled = true block at the end of your blocks in the clock timer)

1 Like

Hi Tim, thanks for your answer. It's definitely true, to have a "more precise" timings the best way is to avoid such overlap of periods. But my question was due to my poor knowledge on how events can arise in Ai2.
Let me try to say what is behind the scene: I have a clock that manages a BT connection sending and receiving many messages to an ELM327; It stays into the clock blocks 'till the complete set of messages is treated (for "real time" operations I don't want that any other activity can interrupt this messages exchange).
After the completion of this (main) clock, in order to leave time to other tasks, allocated to other timers, I supposed to let them the time to fire by leaving some tenth of milliseconds free, by considering that the clock period of the main timer starts to count at the end of its execution.

BUT while writing the above and reading again your suggestion, now is clear to me : I'm really stupid. :slight_smile: I can disable the main timer when it fires and enable it at the end. So the time period (the gap between two subsequent ticks) is precise, provided that the other timers last less than the main period.

Tim you're GREAT as usual !!!
(I cannot use any longer my old Mégane, due to pollution limitation, even if I inscribe her to an Old Car Club ... Italy is a mess... :rage:)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.