Table Of Contents

Creating a Time Budget

Version:
    Last Modified: April 18, 2016

    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.

    1. Determine the required period of each task in your application.
    2. 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.
    3. Record the duration and period of each task in a time budget table, as shown in the following example.
      Task Duration (µS) Period (µS)
      Control 400 1,000
      Monitor 3,000 10,000
      Log 16,000 30,000
    4. Use the following formula to target CPU usage at well below 100%: CPU Usage ( % ) = 100 × 1 n [ loop n × ( duration period ) ] . By plugging the numbers from the table into this formula, you can see that the CPU usage in this example is 100 × ( 400 1,000 + 3,000 10,000 + 16,000 30,000 ) = 123 % .
    5. 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 25,000 µS and increasing the period of the logging loop to 80,000 µS, the theoretical CPU usage becomes 100 × ( 400 1,000 + 3,000 25,000 + 16,000 80,000 ) = 72 % .

    Recently Viewed Topics