Hardware Interrupt
R2026bTrigger downstream function-call subsystems from interrupt service routine for Teensy 4.0 and 4.1 boards
Since R2024b
Hardware Interrupt Teensy4 block
To add a block to a model, double-click the canvas and start typing the block name. Then, select the block from the list.
Libraries:
Simulink Support Package for Arduino Hardware /
Advanced /
TEENSY4
Description
Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.
Use the Hardware Interrupt block to create an interrupt service routine (ISR) in the generated code of your Simulink® model. The ISR executes the downstream function-call subsystem associated with event ports of the block. The function call subsystem runs at the same priority as the ISR.
Using this block, you can:
Create an ISR on the Arduino® board.
Set priority for an ISR.
Enable or disable interrupt preemption.
This block generates code only for the ISR and events that you select or specify. To change the configuration, enable the interrupt, and specify triggering options, use the blocks associated with the selected peripherals. For example, to create an ISR for the CAN communication peripheral on the Hardware Interrupt block, your Simulink model must have an On-board CAN Receive or On-board CAN Transmit block.
Supported Arduino Boards
Teensy 4.0 (Arduino Compatible)
Teensy 4.1 (Arduino Compatible)
Examples
Configure the Teensy Hardware Interrupt block to handle CAN interrupts generated by the On-board CAN Receive and On-board CAN Transmit blocks.

Add the Teensy Hardware Interrupt block and a Function-Call subsystem block to your model. To handle the CAN receive interrupts, add an On-board CAN Receive block inside the Function-Call subsystem block. To configure the hardware interrupt to trigger the subsystem, connect the function-call output of the Teensy Hardware Interrupt block to the trigger port of the Function-Call subsystem block.
In the model settings, set Hardware board to either
Teensy 4.0 (Arduino Compatible) or Teensy 4.1
(Arduino Compatible).
Configure the On-board CAN Receive block with the appropriate CAN module, bus speed, and message ID for your application.
In the Teensy Hardware Interrupt block parameters, set the Interrupt
group to either Controller area network (CAN1),
Controller area network (CAN2), or Controller
area network (CAN3).
Configure the Teensy Hardware Interrupt block to handle interrupts
generated by the same CAN module as the CAN blocks. To do so, set the Interrupt
name that corresponds to the CAN module used by the model. For example,
use CAN1_Handler when the On-board CAN Receive
or On-board CAN Transmit block is configured for Controller
area network.
In the Events to serve table, select the CAN receive event. Set the Simulink task priority parameter to control the execution priority of the function-call subsystem.
Enable Run interrupt service routine as atomic unit to prevent preemption by other interrupts while servicing the CAN interrupt.
Configure the Teensy Hardware Interrupt block to handle ADC conversion-complete interrupts generated by the Teensy Analog Input block. The Teensy Hardware Interrupt block responds to the ADC conversion-complete interrupt generated by the ADC peripheral and triggers a function-call subsystem to execute the interrupt-driven action.

Add the Teensy PWM, Teensy Analog Input, Teensy Hardware Interrupt, and Function-Call subsystem blocks to your model. Connect the function-call output of the Teensy Hardware Interrupt block to the trigger port of the Function-Call Subsystem.
In the model settings, set Hardware board to either
Teensy 4.0 (Arduino Compatible) or Teensy 4.1
(Arduino Compatible).
In the Teensy PWM block parameters, set Pin number to a PWM-capable Teensy pin. Identify the FlexPWM timer module associated with the selected pin. For more information, see Map PWM Pins to FlexPWM Timer Modules.
In the Teensy Analog Input block parameters, set Pin number 1 to a valid Teensy analog input pin.
Set ADC trigger timer to match the FlexPWM timer used by the Teensy PWM block.
Set ADC trigger event to select when the ADC conversion occurs relative to the PWM cycle.
Select Enable ADC conversion complete interrupt.
In the Teensy Hardware Interrupt block parameters, set Interrupt
group to Analog to digital converter
(ADC).
Set Interrupt
name to ADC_EOC_Channel_1 (or the channel
that corresponds to the ADC channel used by the Teensy Analog Input
block).
In the Events to serve table, select the ADC RESRDY event to trigger the function-call subsystem when the ADC conversion result is ready.
To prevent preemption by other interrupts while servicing the ADC interrupt, enable Run interrupt service routine as atomic unit.
Configure the Teensy Hardware Interrupt block to handle PWM interrupts generated by the Teensy PWM block. The PWM block configures the FlexPWM peripheral. The Teensy Hardware Interrupt block responds to selected FlexPWM events by triggering function-call subsystems in response to PWM-synchronized events.

Add the Teensy PWM, Teensy Hardware Interrupt, and Function-Call subsystem blocks to your model. Connect the function-call output of the Teensy Hardware Interrupt block to the trigger port of the Function-Call subsystem.
In the model settings, set Hardware board to either
Teensy 4.0 (Arduino Compatible) or Teensy 4.1
(Arduino Compatible).
In the Teensy PWM block parameters, set Pin number to a PWM-capable Teensy pin. Identify the FlexPWM timer module associated with the selected pin. For more information, see Map PWM Pins to FlexPWM Timer Modules.
Depending on which FlexPWM events you want to handle, enable either Enable overflow/underflow (OVF) interrupt or Enable compare match interrupt in the Teensy PWM block.
In the Teensy Hardware Interrupt block parameters, set Interrupt
group to either PWM Interrupt FLEXPWM1_X,
PWM Interrupt FLEXPWM2_X, PWM Interrupt
FLEXPWM3_X, or PWM Interrupt
FLEXPWM4_X.
Set Interrupt
name to the handler that corresponds to the FlexPWM module used by the
Teensy PWM block. For example, use
FLEXPWM2_0_Handler when the Teensy PWM
block is configured to use a pin mapped to FlexPWM module 2, sub-channel 0.
In the Events to serve table, select the required FlexPWM events. For example, select FlexPWM2_0_Overflow to handle the PWM overflow interrupt or FlexPWM2_0_A_RisingEdge to handle the PWM rising-edge interrupt.
To prevent preemption by other interrupts while servicing the ADC interrupt, enable Run interrupt service routine as atomic unit.
Extended Examples
Run PMSM Motor in Open Loop on Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to run a permanent magnet synchronous motor (PMSM) using open-loop voltage-frequency (V/F) control on a Teensy® development board.
- Since R2026b
- Open Model
Measure Phase Currents of PMSM Motor in Open Loop Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to measure three-phase currents of a permanent magnet synchronous motor (PMSM). The example deploys an open-loop voltage-frequency (V/F) control algorithm on a Teensy® development board.
- Since R2026b
- Open Model
Estimate Angle and Speed of PMSM Motor in Open Loop on Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to estimate the rotor angle and speed of a permanent magnet synchronous motor (PMSM) using an extended EMF observer. The example deploys an open-loop voltage-frequency (V/F) control algorithm and the observer on a Teensy® development board.
- Since R2026b
- Open Model
Sensorless Field-Oriented Control of PMSM Motor Using Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to implement a sensorless field-oriented control (FOC) of a permanent magnet synchronous motor (PMSM). The example deploys the control algorithm to a Teensy development board and drives the motor through the DRV8305EVM inverter.
- Since R2026b
- Open Model
Estimate Battery Current of PMSM in Open-Loop Control Using Arduino Hardware
Use Simulink® Support Package for Arduino® Hardware to estimate the battery current of a permanent magnet synchronous machine (PMSM) in open-loop control using Motor Control Blockset™. This example also shows how to actuate a PMSM motor and calculate phase currents that are indirectly used to estimate the current of the battery.
Ports
Output
The block outputs a function call. The number of function call outputs depends on the number of events you select to serve in an ISR. For example, if you select CAN rx and Custom event in the Events to serve section, the block enables CAN rx and Custom event output ports.
Parameters
This parameter lists all the available ISRs for a particular type of peripheral in an Arduino board. The values available in the Interrupt name parameter change depending on the interrupt group you select in this parameter.
The interrupt name specifies the ISR for the Hardware Interrupt block. This parameter corresponds to the specific entry in the interrupt vector table of the Arduino board. The available ISRs depend on the Interrupt group.
Dependencies
To enable a CAN handler interrupt, set Interrupt group to the corresponding CAN value.
To enable a FLEXPWM handler interrupt, set Interrupt group to the corresponding PWM interrupt FLEXPWM value.
To enable an ADC end-of-conversion handler interrupt, set Interrupt group to the corresponding ADC value.
This read-only parameter indicates the position of the ISR in the interrupt vector table of the Arduino board.
The value you specify in this parameter sets the priority of the downstream function-call subsystem. The task priority in Simulink for the ISR is relative to the priority of the base rate that you set in the Simulink model.
Note
The default priority of the base rate in the Simulink model is 40, with a lower priority value indicating
a higher priority. To achieve this, in the model settings, select
Higher priority value indicates higher task priority in
the Solver pane.
Select one or more events and their respective execution order from the Events to serve group to service events for the Interrupt name that you select. You can select custom events to execute along with the other events. You can also change the execution order of the events.
Select this parameter to block all other interrupts while executing the current ISR(s).
Select this option to clear all the interrupt status flags after servicing each event.
More About
Use this table to identify the available interrupt names, interrupt numbers, and events for each interrupt group when configuring the Teensy Hardware Interrupt block.
| Source Block | Interrupt Group | Interrupt Name | Interrupt Number | Available Events |
|---|---|---|---|---|
On-board CAN Receive On-board CAN Transmit | Controller area network (CAN1) | CAN1_Handler | 15 | CAN rx |
On-board CAN Receive On-board CAN Transmit | Controller area network (CAN2) | CAN2_Handler | 15 | CAN rx |
On-board CAN Receive On-board CAN Transmit | Controller area network (CAN3) | CAN3_Handler | 15 | CAN rx |
| Teensy PWM | PWM Interrupt FLEXPWM1_X | FLEXPWM1_3_Handler | 105 |
|
| Teensy PWM | PWM Interrupt FLEXPWM2_X | FLEXPWM2_0_Handler | 137 |
|
| Teensy PWM | PWM Interrupt FLEXPWM2_X | FLEXPWM2_1_Handler | 138 |
|
| Teensy PWM | PWM Interrupt FLEXPWM2_X | FLEXPWM2_2_Handler | 139 |
|
| Teensy PWM | PWM Interrupt FLEXPWM2_X | FLEXPWM2_3_Handler | 140 |
|
| Teensy PWM | PWM Interrupt FLEXPWM3_X | FLEXPWM3_1_Handler | 143 |
|
| Teensy PWM | PWM Interrupt FLEXPWM4_X | FLEXPWM4_0_Handler | 147 |
|
| Teensy PWM | PWM Interrupt FLEXPWM4_X | FLEXPWM4_1_Handler | 148 |
|
| Teensy PWM | PWM Interrupt FLEXPWM4_X | FLEXPWM4_2_Handler | 149 |
|
| Teensy Analog Input | Analog to digital converter (ADC) | ADC_EOC_Channel_1 | 118 | ADC RESRDY |
| Teensy Analog Input | Analog to digital converter (ADC) | ADC_EOC_Channel_2 | 119 | ADC RESRDY |
| Teensy Analog Input | Analog to digital converter (ADC) | ADC_EOC_Channel_3 | 120 | ADC RESRDY |
Consider reading this table as follows:
Identify the source block in your model that generates the interrupt (Teensy PWM, Teensy Analog Input, On-board CAN Receive, or On-board CAN Transmit).
Use the Source Block column to find the matching rows.
Select the Interrupt Group and Interrupt Name that match the specific peripheral module configured in the source block.
In the Events to serve table of the block, select the events listed in the Available Events column for that interrupt name.
Extended Capabilities
The Teensy Hardware Interrupt block supports C/C++ code generation using Embedded Coder®.
Version History
Introduced in R2024bThe Teensy Hardware Interrupt block now handles PWM interrupts generated by the Teensy PWM block and triggers downstream function-call subsystems.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)




