Main Content

Detect and Fix Task Overruns on Arduino Hardware

You can configure a Simulink® model running on the target hardware to detect and notify you when a task overrun occurs. A task overrun occurs if the target hardware is still performing one instance of a task when the next instance of that task is scheduled to begin. You can fix overruns by decreasing the frequency with which tasks are scheduled to run, and/or by reducing the number of tasks defined by your model.

To enable overrun detection:

  1. In the Configuration Parameters dialog window, select your Arduino® board from the Hardware board parameter.

  2. In the Hardware Implementation pane that opens, select the Overrun detection > Enable overrun detection check box.

  3. Use the Digital output to set on overrun parameter to specify the pin number of a digital output.

  4. Click OK.

To create a visual overrun indicator for your board, connect an appropriate resistor in series with an LED between the GND and the hardware pin specified by the Digital output to set on overrun parameter. Orient the LED so the longer leg (positive) is connected to the digital output pin.

When a task overrun occurs:

  • The state of the digital output pin specified by the Digital output to set on overrun parameter changes from low (0 Volts) to high (Vref Volts).

  • The model continues running, but the effective sample time will be longer than specified.

To fix an overrun condition, reduce the processing burden of the model by applying one or more of the following solutions:

  • Increase the sample times for the model. For example, increase the values of the Sample time parameters in all of your data source blocks.

  • Simplify the model.

If you are using External mode, and the preceding solutions do not fix the task overrun condition, consider disabling External mode. External mode adds a lightweight server to the model running on the target hardware. This server increases the processing burden upon the target hardware, which can contribute to a task overrun condition.