The Simulink® Real-Time™ software includes support for asynchronous events in response to an interrupt from I/O boards. In response to these interrupts, the CPU can suspend normal execution and jump to another section of code called an Interrupt Service routine (ISR).
When developing an Simulink Real-Time model, you can model an Interrupt Server Routine (ISR) by using a Function-Call Subsystem. Also, add an IRQ Source block connected to the Function-Call Subsystem block. This subsystem is then executed when an interrupt occurs and the CPU is ready to accept it.
After you install an I/O board with interrupt support into your target computer, you can add Simulink Real-Time asynchronous blocks to your Simulink model.
In the MATLAB® Command Window, type
The Simulink Real-Time Library opens.
Double-click the Asynchronous Event group block.
The Library: slrtlib/Asynchronous Event window opens.
Drag the Simulink Real-Time IRQ block into your Simulink model and connect the output to this block to the input of a Function-Call Subsystem. For more information on Function-Call subsystems, see the Simulink and Simulink Coder™ documentation.
In the setup shown above, the CPU executes the contents of the Function Call-Subsystem whenever IRQ 5 occurs.
Double-click the IRQ Source block.
The Block Parameters: IRQ Source dialog box opens.
To determine and use the IRQ that the BIOS assigned to the board, from the
IRQ line number list, select
Alternatively, select one of the values
3–15 for this number. To determine
the available IRQ line numbers on the target computer, use the function
From the I/O board generating the interrupt drop-down list, select an interrupt board.
In the PCI slot (-1: autosearch)
or ISA base address field, enter the PCI slot number or
-1 to let the
Real-Time software determine
For more information about the IRQ Source block, see Async IRQ Source.
To transfer data from your ISR, add an Async Transition block or Async Read/Write block to your Simulink model. See Asynchronous Interrupt Example.
If you are using a CAN field bus with interrupts, see Asynchronous Interrupt Example.
xpcasynctrans model uses an external TTL signal to trigger
an interrupt on the parallel port. Data is exchanged between an asynchronous task
and a rate monotonic task by using an Async Rate Transition block. For more
information, see the annotations in the model that document its purpose.
If you installed the MATLAB software in the default location, the example model is located in this folder: