| Contents | Index |
| On this page… |
|---|
Normally the code generated by Embedded Coder software runs in the context of a timer interrupt. Model blocks run in a periodical fashion clocked by the periodical interrupt whose period is tied to the base sample time of the model.
This execution scheduling model, however, is not flexible enough for many systems, especially control and communication systems, which must respond to external events in real time. Such systems require the ability to handle various hardware interrupts in an asynchronous fashion.
Embedded Coder software lets you model and generate code for such systems by creating tasks driven by Hardware Interrupt blocks in addition to the tasks that are left to be handled in the context of the timer interrupt.
For code that runs in the context of the timer interrupt, each iteration of the model solver is run after an interrupt has been posted and serviced by an interrupt service routine (ISR). The code generated for the C280x, C281x, and C28x3x uses CPU_timer0.
The timer is configured so that the model's base rate sample time corresponds to the interrupt rate. The timer period and prescaler are calculated and set up to produce the desired rate as follows:
![]()
The minimum achievable base rate sample time depends on the model complexity. The maximum value depends on the maximum timer period value (232-1 for the F2812, F2808, and F28x35) and the CPU clock speed. The CPU clock speed is 100 MHz for the F2808, and 150 MHz for the F2812 and F28335.
If all the blocks in the model inherit their sample time value, and no sample time is explicitly defined, the default value is 0.2 s.
The Event Managers and their general-purpose timers, which drive PWM waveform generation use the high-speed peripheral clock (HISCLK). By default, this clock is always selected in Embedded Coder software. This clock is derived from the system clock (SYSCLKOUT):
HISCLK = [SYSCLKOUT / (high-speed peripheral prescaler)]
The high-speed peripheral prescaler is determined by the HSPCLK bits set in SysCtrl. The default value of HSPCLK is 1, which corresponds to a high-speed peripheral prescaler value of 2.
For example, on the F2812, the HISCLK rate becomes
HISCLK = 150 MHz / 2 = 75 MHz
Simulink and Simulink Coder software facilitate the modeling and generation of code for asynchronous event handling, including servicing of hardware-generated interrupts, by using the following special blocks:
Hardware Interrupt block
This block enables selected hardware interrupts, generates the corresponding interrupt service routines (ISRs), and connects them to the corresponding interrupt service vector table entries. When you connect the output of the Hardware Interrupt block to the control input of a triggered subsystem (for example, a function-call subsystem), the generated subsystem code is called from the ISRs.
Embedded Coder software provides a Hardware Interrupt block for each of the supported processor families.
Rate Transition blocks
These blocks support data transfers between blocks running with different sample rates. The built-in Simulink Rate Transition blocks can be used for this purpose.
The following diagram illustrates a use case where a Hardware Interrupt block triggers two tasks, connected to other blocks that run periodically in the context of the synchronous scheduler.

In the preceding figure, the Hardware Interrupt block is set to react on two interrupts. Since only one Hardware Interrupt block is allowed in a model and the output of this block is a vector of length two, you must connect the Hardware Interrupt block to a Demux block to trigger the two function-call subsystems. The function-call subsystems contain the blocks that are executed asynchronously in the context of the hardware interrupt.
The following example shows how to build and configure a model to react on an eCAN message using a hardware interrupt and an asynchronous scheduler:
Place the eCAN Receive block in a function-call subsystem.

On the eCAN Receive block dialog, check the box labeled Post interrupt when message is received.

Set the Sample Time of the eCAN Receive block to -1 since the block will be triggered by the ISR, as shown in the preceding figure.
Add the C281x Hardware Interrupt block to your model.

The eCAN interrupt on C281x chips is on CPU line 9 and PIE line 5 for module 0. These parameters can be found in the C281x Hardware Interrupt block, C281x Peripheral Interrupt Vector Values figure. Set the hardware interrupt parameters CPU interrupt number(s): to 9, and PIE interrupt number(s): to 5 as shown in the following figure.

Connect the output of the Hardware Interrupt block to the function-call subsystem containing the eCAN block.
At execution time, when a new eCAN message is received, the eCAN interrupt is triggered, and the code you placed in the function-call subsystem is executed. In this example, the eCAN Receive block is placed in the function-call subsystem, which means that the message is read and is passed to the rest of the code.
For more information, see the section on Asynchronous Support in the Simulink Coder documentation.
![]() | Data Type Support | Sharing General Purpose Timers between C281x Peripherals | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |