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

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

Block Parameters

Task Overload Behavior

OptionBehaviorUse CaseRisk
Queue 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
Skip this task execution once• If task is running, skip the triggered execution• Resume normal execution at next trigger• Overload does not accumulate
Delay all new tasksuntil end of overload• All task triggers are blocked during overload• Tasks resume when overloaded task completes

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)

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();
    }
}

Examples

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

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

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

See Also

  • [MCHP_Master] - Main configuration block
  • [MCHP_Interrupt] - Interrupt-driven task configuration
  • [MCHP_MCU_LOAD] - CPU utilization monitoring
  • [MCHP_MCU_OVERLOAD] - Overload detection
  • [MCHP_IdleTask] - Background task execution