[previous] [index] [next]

Example 3: Variable-Period Scheduling of a Single Task

This example demonstrates a single task that toggles the speaker port with a continuously varying frequency. Since there is no identifiable base period for the timer, we'll put it in one-shot mode and change the task period each time it runs. This adds some minor overhead (about 2 microseconds) each cycle for timer reprogramming, but it avoids quantization of the speaker frequency to some base timer frequency. Refer to the commented source code of the example for the details.

Principle of Operation

Setting up the Timer

Setting up the Task

The Task Function and Timing

Running the Demo

To run the demo, change to the 'ex03_variable' subdirectory of the top-level tutorial directory, and run the 'run' script by typing
./run
Alternatively, change to the top-level tutorial directory and run the 'runall' script there by typing
./runall
and selecting the "Single Variable-Period Task" button.

You'll hear a continuously varying tone for about 10 seconds.

See the Code


Next: Example 4, FIFOs

Back: Example 2, Pure Periodic Scheduling of Two Tasks