Minimize CPU usage and jitter in your application by creating a time budget for each task in your application. To create a time budget, you must determine the amount of time required to execute each task and set the rates of the loops accordingly.
Determine the required period of each task in your application.
Benchmark your application to determine the duration of each task in your application. Allow the benchmark to run for several thousand iterations and record the worst-case execution time as the duration.
Record the duration and period of each task in a time budget table, as shown in the following example.
Use the following formula to target CPU usage at well below 100%:
By plugging the numbers from the table into this formula, you can see that the CPU usage in this example is
To decrease CPU usage, you can increase the period of one or more loops while ensuring that each loop executes at the requested rate.
For example, by increasing the period of the monitoring loop to
and increasing the period of the logging loop to
80,000 µS, the theoretical CPU usage becomes