Checking the loop cycle time

Modified on Fri, 30 Dec, 2022 at 4:43 PM

There are many tasks which requires the loop() to repeat as quickly as possible (e.g. communication with a device, control and monitoring from a software such as HITIPanel, sensor reading at fixed rate…).


This is why it is always good practice to keep the loop cycle time as short and regular as possible. (the loop cycle time is the time that your Arduino takes to complete one loop() cycle).


This example shows how to use the Chart to monitor the loop cycle time. 


Refer to article Make your Arduino more responsive to learn how to decrease the loop cycle time.



Sketch

Upload this sketch : 3_Debugging \ 3_LoopCycleTime


Loop cycle time is automatically measured by function HC_communicate().


#include <HITIComm.h>

void setup()
{
    // initialize library
    HC_begin();
}

void loop()
{
    // measure loop cycle time
    HC_communicate();
}



Chart

1) Open the Chart window (CTRL+T or Tools\Chart). The Chart is configured here to read the loop cycle time every 10ms.



2) Start data acquisition. After 10 seconds, stop data acquisition.

3) Look at the values you get from the chart. The following plot is what you typically get when the above code is loaded on an Arduino Uno. The loop cycle time is here only affected by the serial communication with HITIPanel performed.

4) Let’s analyze our data by zooming in area of interest (you can also export and analyze your data in Excel). We extract 3 characteristic values from our curve:

  • Average value (when communication with HITIPanel is fluent) : around476us. 


  • Min value (when no communication occurs): 20us


  • Max value (when a peak of communication occurs): 1764us



 

 


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article