Scheduler Options Block Icon
The Scheduler Options block configures the behavior of the built-in Rate Monotonic Scheduler used for multitasking in MCHP Blockset models. The scheduler manages execution of multiple tasks at different sample rates with preemptive priority-based scheduling. Rate Monotonic Scheduling Principle: - Highest rate = Highest priority - Faster tasks automatically get higher priority - Preemptive execution - Higher priority tasks interrupt lower priority tasks - Deterministic behavior - Guaranteed timing if schedulability conditions are met - Automatic priority assignment - No manual priority configuration needed

When to use:

When to use:

  • Model has multiple sample times (fast current loop + slow position loop)
  • Need to control task overload behavior (queue, skip, or delay)
  • Timing jitter observed — change from Queue to Skip mode
  • Critical task must never be skipped — use Delay mode
  • Tasks occasionally overrun — configure graceful handling

When NOT to use:

  • Single-rate model with one sample time — default scheduler suffices
  • All tasks complete well within their period (no overload risk)
  • Default overload behavior (Queue) works for your application

Parameters

Task Overload Behavior

ParameterVariableOptionBehaviorUse CaseRisk
On sub-task OverloadTaskOverloadBehaviourQueue the task (queue length is 1)• If task is still running when next trigger occurs, queue ONE additional execution | • Task executes twice back-to-back when current run completes | • Further triggers are lost• Occasional overloads acceptable | • Important to catch up after brief overload⚠️ May cause timing jitter
Skip this task execution once• If task is running, skip the triggered execution | • Resume normal execution at next trigger | • Overload does not accumulate• Non-critical periodic tasks | • Data logging, monitoring | • Tasks that can tolerate missed samples⚠️ Data loss on overload
Delay all new tasks until end of overload• All task triggers are blocked during overload | • Tasks resume when overloaded task completes | • Timing shifts but no execution is skipped• Critical tasks that must complete | • Safety-related operations | • Tasks where every execution matters⚠️ Can cause cascading delays

Overload Behavior Comparison

// Task with 10 ms period, execution takes 12 ms (overload)

Option 1: Queue (queue length = 1)
t=0ms:   Task starts
t=10ms:  Trigger → QUEUED (1 pending)
t=12ms:  Task ends → immediately starts queued execution
t=20ms:  Trigger → LOST (queue full)
t=24ms:  Task ends
t=30ms:  Normal execution resumes

Option 2: Skip once
t=0ms:   Task starts
t=10ms:  Trigger → SKIPPED
t=12ms:  Task ends
t=20ms:  Normal execution
t=30ms:  Normal execution

Option 3: Delay all
t=0ms:   Task starts
t=10ms:  Trigger → DELAYED
t=12ms:  Task ends → delayed trigger executes immediately
t=24ms:  Task ends (ran at t=12)
t=30ms:  Back to normal (with 2ms delay accumulated)

Rate Monotonic Scheduler Architecture

Task Priority Assignment

Sample TimePriority LevelCan PreemptExample Use
Base rate (fastest)40 (highest)All slower tasksFast current loop (50 µs)
2× base rate30Slower tasksSpeed controller (100 µs)
10× base rate20Even slower tasksPosition controller (500 µs)
100× base rate10Background tasksCommunication (5 ms)
Triggered subsystemsConfigurableBased on configInterrupt-driven tasks

Multitasking Configuration

  • Solver Type: Fixed-step (required for code generation)
Configuration Parameters → Solver
Type: Fixed-step
Solver: discrete (no continuous states)
  • Sample Times: Define task rates as integer multiples
Base rate: 50e-6     % 50 µs (20 kHz)
Task 1:    100e-6    % 2× base rate
Task 2:    500e-6    % 10× base rate
Task 3:    5e-3      % 100× base rate
  • Tasking Mode: Enable multitasking in configuration
Configuration Parameters → Code Generation → Interface
Multi-instance code: off
Single output/update function: off
⚠️ Let MCHP blockset manage tasking automatically

Scheduling Algorithm

// Simplified scheduler pseudocode

        execute_task(highest);
        mark_complete(highest);
        ready_tasks = check_triggered_tasks();
    }
}

Schedulability Analysis

Liu & Layland Utilization Bound

For Rate Monotonic Scheduling, the system is schedulable if:

U = Σ(Cᵢ/Tᵢ) ≤ n(2^(1/n) - 1)

Where:
  U  = Total CPU utilization
  Cᵢ = Execution time of task i
  Tᵢ = Period of task i
  n  = Number of tasks

For n tasks:
  n=1: U ≤ 100%
  n=2: U ≤ 82.8%
  n=3: U ≤ 78.0%
  n→∞: U ≤ 69.3%

Example Calculation

Task 1: C₁=20µs, T₁=50µs   → U₁ = 20/50 = 0.40 (40%)
Task 2: C₂=80µs, T₂=500µs  → U₂ = 80/500 = 0.16 (16%)
Task 3: C₃=1ms,  T₃=10ms   → U₃ = 1/10 = 0.10 (10%)

Total: U = 0.66 (66%)
Bound for n=3: 0.78 (78%)

✓ System is schedulable (66% < 78%)

Advanced Topics

Interrupt-Driven Tasks

Tasks triggered by hardware interrupts (using MCHP_Interrupt block) have configurable priorities independent of sample time:

// Interrupt priority can override rate monotonic assignment
Interrupt priority: 1-7 (device-dependent)
Multiplied by -100 for scheduler priority

Example: Priority 7 interrupt → scheduler priority -700
         (higher than any rate monotonic task)

Context Switching Overhead

Device FamilyContext Switch TimeNotes
dsPIC30F/33F~100 cyclesRegister save/restore
dsPIC33E/C/A~80 cyclesOptimized context save
PIC32 (MIPS)~150 cyclesShadow register set available
SAM (ARM)~20 cyclesHardware-assisted context switch

Examples

Programmatic Setup

% Add block to model
add_block('MCHP_Blockset/System Configuration/Scheduler Options', [mdl '/Scheduler']);

% Configure key parameters
set_param([mdl '/Scheduler'], 'TaskOverloadBehaviour', 'Queue the task (queue length is 1)');

Example 1: Motor Control Application

% Three-level motor control hierarchy
% Base rate: 50 µs, Overload: Queue

Sample times:
- Current loop:    50e-6    (Priority 40 - highest)
- Speed loop:      500e-6   (Priority 30)
- Position loop:   5e-3     (Priority 20)
- Communication:   100e-3   (Priority 10 - lowest)

Scheduler Options:
TaskOverloadBehaviour: 'Queue the task (queue length is 1)'

% Result: Current loop can preempt all others
% Brief overloads are queued and caught up

Example 2: Data Acquisition System

% Robust data logging with guaranteed timing
% Base rate: 100 µs, Overload: Delay all

Sample times:
- Fast ADC:       100e-6   (Priority 40)
- Slow sensors:   10e-3    (Priority 30)
- Data logging:   100e-3   (Priority 20)
- Display update: 500e-3   (Priority 10)

Scheduler Options:
TaskOverloadBehaviour: 'Delay all new tasks until end of overload'

% Result: No samples lost, timing may shift temporarily

Example 3: Communication System

% Non-critical monitoring allows missed samples
% Base rate: 1 ms, Overload: Skip

Sample times:
- Protocol handler: 1e-3   (Priority 40)
- Data processing:  10e-3  (Priority 30)
- Status update:    100e-3 (Priority 20)

Scheduler Options:
TaskOverloadBehaviour: 'Skip this task execution once'

% Result: Skipped status updates acceptable

Troubleshooting

ProblemCauseSolution
Tasks executing out of orderIncorrect sample time configurationVerify all sample times are integer multiples of base rate
Timing jitter observedOverload with Queue optionChange to Skip or reduce task execution time
System becomes unresponsiveOverload with Delay option causing cascadeReduce CPU load or change to Skip option
Data loss in loggingSkip option losing samplesChange to Queue or reduce overload frequency