| Contents | Index |
| On this page… |
|---|
In certain applications, the model (target application) execution is driven by the pace of an incoming CAN message. The standard behavior of the xPC Target kernel is to drive the model (target application) in time monotonic fashion (time interrupt). However, the driving interrupt can be replaced by any other hardware interrupt. Because the three supported CAN boards permit the firing of a hardware interrupt upon reception of a specific CAN message, you can replace the timer interrupt line in the kernel by the interrupt line assigned to a CAN board. This leads to a CAN-message-driven execution of the target application.
To set this up, two independent steps are necessary:
Both steps are slightly different for each of the three supported CAN boards.
The CAN-AC2 is an ISA board, and the hardware interrupt line is set by means of hardware jumpers on the board. Refer to the Softing user manual for the board on how to set a certain interrupt line. Select an interrupt line that is not used by any other hardware device in the xPC Target system (for example by the Ethernet card).
In the Simulink window, and from the Tools menu, point to Code Generation, and then click Options.
The Configuration Parameters dialog box is displayed.
In the Target selection section, set the System target file field to xpctarget.tlc.
In the Real-time interrupt source field, select the interrupt line number that you have set using the jumpers on the board.
Open the dialog box of the CAN Receive block in the model that defines the CAN message (identifier) to be used to fire the interrupt. Select the Generate interrupts check box. Selecting this box declares all CAN messages defined in this Receive block instance through their identifiers as messages that fire an interrupt. In other words, it is not possible to define a single CAN message within the set of defined identifiers to be the only one to fire an interrupt. In most cases only the reception of one specific message is used to drive the application execution. Therefore use at least two instances of the Receive block. One to receive the CAN message that drives the execution (Generate Interrupts selected) and the other for all other normal CAN messages to be received (Generate Interrupts cleared).
The CAN-AC2 is a PCI board, and the hardware interrupt line is automatically assigned by the PCI BIOS during the initialization of the target system. At the model level, open the Simulation > Configuration Parameters dialog box. At the xPC Target options node, set Real-time interrupt source Auto (PCI only). This option enables the xPC Target software to automatically determine the IRQ that the BIOS assigned to the board and use it. Alternatively, use the xPC Target function getxpcpci (see help getxpcpci) at the MATLAB command prompt to query the target system for installed PCI devices and the assigned resources. Write down the interrupt line number assigned to the CAN-AC2-PCI board.
In the Simulink window, and from the Tools menu, point to Code Generation, and then click Options.
The Configuration Parameters dialog box is displayed.
In the Target selection section, set the System target file field to xpctarget.tlc.
In the Real-time interrupt source field, select the interrupt line number that you retrieved with the getxpcpci command.
Alternatively, select Auto (PCI only) to enable the xPC Target software to automatically determine the IRQ that the BIOS assigned to the board and use it.
In the I/O board generating the interrupt field, select Softing_CAN-AC2-PCI.
Open the dialog box of the CAN Receive block in the model that defines the CAN message (identifier) to be used to fire the interrupt. Select the Generate interrupts check box. Selecting this box declares all CAN messages defined in this Receive block instance through their identifiers as messages that fire an interrupt. In other words, it is not possible to define a single CAN message within the set of defined identifiers to be the only one to fire an interrupt. In most cases only the reception of one specific message is used to drive the application execution. Therefore use at least two instances of the Receive block. One to receive the CAN message that drives the execution (Generate Interrupts selected) and the other for all other normal CAN messages to be received (Generate Interrupts cleared).
The CAN-AC2-104 is an ISA board (PC/104), and the hardware interrupt line is set by means of a software setting within the CAN Setup driver block. Note a free interrupt line that is not used by any other hardware device in the xPC Target system (for example by the Ethernet card).
In the Simulink window, and from the Tools menu, point to Code Generation, and then click Options.
The Configuration Parameters dialog box is displayed.
In the Target selection section, set the System target file field to xpctarget.tlc.
In the Real-time interrupt source field, select the free interrupt line number that you chose.
In the I/O board generating the interrupt field, select Softing_CAN-AC2-104.
In the model open the dialog box of the CAN Setup block for the CAN-AC2-104 board. Select the chosen interrupt line in the Interrupt Line pop-up menu and close the dialog box. Open the dialog box of the CAN Receive block in the model that defines the CAN message (identifier) to be used to fire the interrupt. Select the Generate interrupts check box. Selecting this box declares all CAN messages defined in this Receive block instance through their identifiers as messages that fire an interrupt. In other words, it is not possible to define a single CAN message within the set of defined identifiers to be the only one to fire an interrupt. In most cases only the reception of one specific message is used to drive the application execution. Therefore use at least two instances of the Receive block. One to receive the CAN message that drives the execution (Generate Interrupts selected) and the other for all other normal CAN messages to be received (Generate Interrupts cleared).
After you complete these two steps, you are ready to build the model. After the downloading has succeeded and the target application execution has been started, the execution is now driven by the selected CAN messages. The execution time information displayed on the target screen is now directly dependent on the reception of the corresponding message. If no message is received, the time does not advance. The corresponding CAN message on the other CAN node should only be generated if the xPC Target application is running, otherwise unexpected interrupt messages might be displayed on the target screen.
![]() | Introduction to CAN | Defining Initialization and Termination CAN Messages | ![]() |

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 |