Checking the loop() cycle time

The more responsive your Arduino is, the quicker it is to react to external events such as switch actuation, and the quicker it is to trigger actions accordingly.

This is why it is always good practice to make the code inside the loop() as responsive and smooth as possible. To do that, keep the loop() cycle time as short and regular as you can. The loop() cycle time is the time your Arduino takes to complete one loop() cycle.

Refer to section Improving your Arduino responsiveness to learn more about how code responsiveness affects your performance and how to improve it.

This example illustrates how easy it is to monitor the loop() cycle time.

 

1) Sketch: 3_Debugging \ 3_LoopCycleTime

Loop() cycle time is automatically measured by function HC_communicate(). So, there is no additional code required.

#include <HITIComm.h>


// run once at power on
void setup()
{
    // initialize library
    HC_begin();
}


// run repeatedly after setup() 
void loop()
{
    // measure loop() cycle time
    HC_communicate();
}

 

2) Chart

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

  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 by function HC_communicate().
    image404.png

  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:
    • Averagevalue (when communication with HITIPanel is fluent) : around 476us
      image408.png

    • Minvalue (when no communication occurs): 20us
      image409.png

    • Maxvalue (when a peak of communication occurs): 2024us
      image410.png

 

Was this article helpful?
0 out of 0 found this helpful