Interrupt Block Icon
The Interrupt block creates interrupt-driven subsystems by connecting peripheral interrupt sources to Simulink triggered subsystems. The block automatically manages interrupt vector configuration, priority levels, and timing synchronization. Key Capabilities: - Automatic interrupt detection - Discovers all peripheral interrupts in model - Dynamic interrupt list - Popup shows only available interrupts from active peripherals - Priority management - Configure interrupt priority levels (device-dependent) - Multiple timing modes - Base rate, periodic trigger, or hardware timer-based - Context preservation - Automatic FPU context save/restore (PIC32 with FPU)

When to use:

When to use:

  • Hardware event must trigger Simulink subsystem (ADC done, UART RX, encoder overflow)
  • Need lowest latency response to peripheral event (faster than polling)
  • PWM-synchronized control loop (ADC interrupt after PWM trigger)
  • Asynchronous communication (UART/SPI/I2C receive events)
  • Extending encoder range with overflow/underflow interrupts

When NOT to use:

  • Timer-based periodic tasks suffice โ€” use Simulink sample times instead
  • Polling peripheral status is fast enough for application timing
  • Adding complexity without latency benefit โ€” interrupts add overhead
  • Peripheral block does not define interrupt source (check dropdown list)

Block Dialog

Interrupt โ€” Main Tab
Advanced TabInterrupt โ€” Advanced Tab

Parameters

Interrupt Selection

ParameterVariableDescriptionValues
InterruptionInterruptionSelect interrupt source from dynamic list of available peripheral interrupts.โ€ข Not defined | โ€ข ADC1 | โ€ข PWM1 Period | โ€ข QEI1 Position | โ€ข UART1 RX | โ€ข SPI1 RX | โ€ข (device/model-dependent)
Interrupt PriorityIntPriorityInterrupt priority level (if configurable). Higher number = higher priority.1-7 (dsPIC/PIC24) | 1-7 (PIC32) | 0-15 (ARM - 0=highest)
Disable FPU Context SaveFPUNoSave(PIC32 with FPU only) Disable automatic FPU context save if ISR does not use floating-point operations (optimization).on / off
Execute at StartupStartupExecuteExecute subsystem once during initialization (before first interrupt).on / off

Changed in v3.63.x โ€” The legacy fire-every-step fallback has been removed. A triggered subsystem connected to an Interrupt block whose source is never raised at run-time is now reported as a build-time configuration error instead of silently firing at the model base rate. If an older model relied on that behaviour, connect the subsystem to a Timer-based trigger instead, or mark StartupExecute=on when a one-shot initialisation is all that is needed. The Change Notification (CN) callback also emits a warning when EVT_EN is empty but at least one channel is configured, to catch the same misconfiguration on CN-driven interrupts.

Timing Configuration

ParameterVariableDescriptionUse Case
Time SourceTriggered_Sub_TimeSourceTiming reference for triggered subsystem sample time.โ€ข Base rate: Synchronized to model base rate | โ€ข Periodic trigs: User-specified period | โ€ข Hardware timer: Dedicated timer resource
Trigger PeriodTrigsPeriod(Periodic trigs mode) Subsystem sample time when using periodic trigger mode.Any value matching trigger rate (e.g., 100e-6 for 10 kHz)
Timer ResolutionTIMER_Resolution(Hardware timer mode) Select timer prescaler for desired resolution and max period.Dynamic list based on device: | โ€ข dsPIC: 1, 8, 64, 256 prescalers | โ€ข PIC32: 1, 2, 4, 8, 16, 32, 64, 256 | โ€ข SAM: 8, 32, 128 divisors

Interrupt Sources

Peripheral Interrupts (Auto-detected)

The block automatically detects interrupts from peripheral blocks in your model:

PeripheralInterrupt TypesExample Usage
ADCโ€ข Conversion completeโ€ข Individual converter done
PWMโ€ข Period matchโ€ข Trigger event
QEIโ€ข Position counter overflowโ€ข Index pulse
UARTโ€ข RX data readyโ€ข TX buffer empty
SPIโ€ข Transfer completeโ€ข Buffer full/empty
I2Cโ€ข Master/slave eventsโ€ข Address match
CANโ€ข Message receivedโ€ข TX complete
Timerโ€ข Period matchโ€ข Compare match

User-Defined Interrupts

Peripheral blocks advertise themselves to the Interrupt block through the MCHP_USER_INTERRUPTS mask parameter. The Interrupt block scans every block in the model with a non-empty MCHP_USER_INTERRUPTS field and aggregates the entries into the Interruption popup.

Declaration format โ€” one or more semicolon-separated entries, each with four {โ€ฆ} fields:

{InterruptFlagRef}{ShortDescription}{LongDescription}{Parameters};
FieldPurposeExample
InterruptFlagRefC symbol used to reference the interrupt enable bit (e.g. CN1IE, U1RXIE, AD1IE).CN1IE
ShortDescriptionShort label shown in the Interrupt block popup.CN1
LongDescriptionDescriptive label shown in the tooltip.Change Notification - 1
ParametersSpace-separated Name(Value) tokens โ€” see below. For backward compatibility, a bare numeric value is accepted and treated as Priority(N).VectorName(U1RXInterrupt) Config_BitSet(IEC0bits.U1RXIE=1) RegisterReadClear(IFS0bits.U1RXIF) Priority(-1)

Parameter tokens (inside the fourth field)

TokenMeaning
VectorName(txt)Name of the ISR vector. If empty, no new vector is generated โ€” the peripheral driver already owns the ISR and the Interrupt block generates a callable user function invoked by the driver via MCHP_CallUserISR() (see Driver / User ISR Coexistence below). If non-empty, the Interrupt block emits the full __attribute__((interrupt)) vector itself.
Config_BitSet(txt)Register bit(s) to set in order to enable the interrupt (e.g. IEC0bits.U1RXIE=1).
RegisterReadClear(txt)Register / bit to read-clear to acknowledge the interrupt flag.
Priority(N)Fixed priority, or -1 to let the Interrupt block mask expose a user-editable Interrupt Priority field. Priority ownership rule โ€” whichever block sets Priority is responsible for programming the associated IPC bits; other blocks must leave priority at -1.

Example โ€” Change Notification (single channel) (from MCHP_CN_Callback.m):

NewMask.Values.MCHP_USER_INTERRUPTS = ...
    ['{CN1IE}{CN1}{Change Notification - 1}{' NewMask.Values.IntPriority '};'];

Because the fourth field is just a number, it is treated as Priority(N); VectorName is therefore empty โ†’ the Interrupt block does not emit a duplicate vector for this entry.

Driver / User ISR Coexistence (dsPIC / PIC32)

Peripheral drivers and user-defined Interrupt blocks can request the same vector. The blockset resolves this with a three-tier architecture that is selected automatically from the MCHP_USER_INTERRUPTS declaration:

TierTriggerWhat is generatedUsed by
Tier 1 โ€” InlineVectorName empty, Priority present (numeric)The peripheral TLC emits the ISR directly; the Interrupt block content is inlined at the end of the ISR.Change Notification (CN).
Tier 2 โ€” Function callVectorName non-empty and Priority โ‰  -1The peripheral driver owns the __attribute__((interrupt)) function and calls MCHP_CallUserISR(IE_ref) at the end of its ISR; the Interrupt block emits a plain callable function with the user subsystem’s body.Most peripherals โ€” ADC, UART, Timer, QEI, PWM events, etc.
Tier 3 โ€” HardcodedVectorName empty, fixed Priority(0)Driver has an embedded ISR with a hardcoded call-site; the Interrupt block simply supplies the body.SPI, I2C.

Why it matters โ€” mixing up the rules produces either (a) a linker error from two symbols claiming the same vector, or (b) a silent failure where the user subsystem is never called because the driver ISR does not know about it. The callback enforces this automatically โ€” no user action required โ€” but when writing a new peripheral TLC you must follow the same conventions.

Device-Specific Interrupt Configuration

dsPIC30F/33F/33E/33C/33A

FeatureConfigurationNotes
Priority Levels1-7 (7 = highest)Default is level 4
NestingAutomatic if priorities differHigher priority can preempt lower
Vector TableAuto-managed by blocksetIVT and AIVT support
Context SaveW0-W15, RCOUNT, SRAutomatic register preservation

PIC32 (MIPS)

FeatureConfigurationNotes
Priority Levels1-7 (7 = highest)Sub-priority 0-3 also available
Shadow RegistersAutomatic if configuredFast context switch (no save)
FPU ContextOptional save/restoreOnly if FP ops used in ISR
Multi-Vector ModeEnabled by blocksetEach peripheral has dedicated vector

SAM (ARM Cortex-M)

FeatureConfigurationNotes
Priority Levels0-15 (0 = highest)NVIC priority grouping
Tail-ChainingAutomatic hardware optimizationBack-to-back ISRs without full context restore
Late ArrivalHardware-managed preemptionHigher priority can preempt during stacking
FPU Lazy StackingConditional FP context saveOnly saved if FP registers used

Timing Modes Explained

Mode 1: Derived from Model Base Rate

  • Subsystem sample time = model base rate
  • Timing analysis uses base rate for schedulability
  • Best for interrupts synchronized with main control loop
  • Example: ADC conversion complete after PWM trigger

Mode 2: Derived from Periodic Trigs

  • User specifies expected interrupt rate in TrigsPeriod
  • Allows timing analysis for asynchronous interrupts
  • Subsystem scheduled assuming periodic behavior
  • Example: UART receive (assume max message rate)

Mode 3: Hardware Timer-Based

  • Dedicated timer resource automatically allocated
  • Timer configured with selected prescaler
  • True periodic interrupt independent of Simulink rates
  • Example: Custom 1 kHz update loop

Examples

Programmatic Setup

% Add block to model
add_block('MCHP_Blockset/System Functions/Interrupt', [mdl '/ISR']);

% Configure key parameters
set_param([mdl '/ISR'], 'Interruption', 'ADC1 Interrupt');
set_param([mdl '/ISR'], 'IntPriority', '6');

Example 1: ADC Interrupt-Driven Current Loop

// PWM triggers ADC, ADC interrupt executes control loop

Simulink Model:
1. Add PWM_HS block with ADC trigger output
2. Add ADC block with interrupt enabled
3. Add Interrupt block
4. Configure interrupt block:
   Interruption: 'ADC1 - Conversion Complete'
   Triggered_Sub_TimeSource: 'is derived from model base rate'
   IntPriority: 7  (highest - critical for motor control)

5. Create triggered subsystem connected to interrupt block
6. Add current control algorithm inside subsystem

Result: Current loop executes synchronously with PWM/ADC

Example 2: UART Receive Interrupt

// Process received data asynchronously

Configuration:
   Interruption: 'UART1 - RX'
   Triggered_Sub_TimeSource: 'is derived from trigs; trigs must be periodic'
   TrigsPeriod: 1e-3  % 1 ms assumed for timing (actual rate is async)
   IntPriority: 3  (medium priority)
   StartupExecute: on  (initialize buffers)

Subsystem:
- Read UART data from peripheral block
- Parse protocol
- Update command registers

Example 3: Hardware Timer Periodic Interrupt

// Custom periodic task independent of base rate

Configuration:
   Interruption: 'User Timer1'  (created by peripheral block)
   Triggered_Sub_TimeSource: 'is derived from a hardware timer'
   TIMER_Resolution: 'Resol: 32us - MaxPer: 2.1s'  (prescaler 256)
   IntPriority: 5

Result:
- Dedicated timer allocated automatically
- Interrupt triggers at specified rate
- Independent of Simulink sample times

Example 4: QEI Position Overflow Event

// Extend encoder range with software counter

Configuration:
   Interruption: 'QEI1 - Position Counter Overflow'
   Triggered_Sub_TimeSource: 'is derived from model base rate'
   IntPriority: 6  (high - timing critical)

Subsystem Logic:
if (QEI_DIR == FORWARD)
    ExtendedPosition += 65536;
else
    ExtendedPosition -= 65536;
end

Troubleshooting

ProblemCauseSolution
Interrupt not listedPeripheral block not in model or interrupt not enabledAdd peripheral block, enable interrupt in peripheral config
Subsystem never executesInterrupt source not configured correctlyVerify peripheral interrupt enable, check flag register
System hangs in ISRInterrupt flag not clearedEnsure RegisterReadClear is correct in peripheral definition
Priority not workingArchitecture limitation or incorrect settingCheck device datasheet for valid priority range
FPU corruption (PIC32)FPUNoSave enabled but FP ops in ISRDisable FPUNoSave or remove FP operations from ISR
        Keep ISR execution time short - long ISRs can cause overload
        Higher priority ISRs can preempt lower priority - ensure reentrancy
        Hardware timer mode consumes one timer resource
        StartupExecute useful for initializing communication protocols