When to use:
When to use:
When NOT to use:
| Parameter | Variable | Option | Behavior | Use Case | Risk |
|---|---|---|---|---|---|
| On sub-task Overload | TaskOverloadBehaviour | 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 | • 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 |
// 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)
| Sample Time | Priority Level | Can Preempt | Example Use |
|---|---|---|---|
| Base rate (fastest) | 40 (highest) | All slower tasks | Fast current loop (50 µs) |
| 2× base rate | 30 | Slower tasks | Speed controller (100 µs) |
| 10× base rate | 20 | Even slower tasks | Position controller (500 µs) |
| 100× base rate | 10 | Background tasks | Communication (5 ms) |
| Triggered subsystems | Configurable | Based on config | Interrupt-driven tasks |
Configuration Parameters → Solver
Type: Fixed-step
Solver: discrete (no continuous states)
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
Configuration Parameters → Code Generation → Interface
Multi-instance code: off
Single output/update function: off
⚠️ Let MCHP blockset manage tasking automatically
// Simplified scheduler pseudocode
execute_task(highest);
mark_complete(highest);
ready_tasks = check_triggered_tasks();
}
}
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%
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%)
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)
| Device Family | Context Switch Time | Notes |
|---|---|---|
| dsPIC30F/33F | ~100 cycles | Register save/restore |
| dsPIC33E/C/A | ~80 cycles | Optimized context save |
| PIC32 (MIPS) | ~150 cycles | Shadow register set available |
| SAM (ARM) | ~20 cycles | Hardware-assisted context switch |
% 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)');
% 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
% 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
% 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
| Problem | Cause | Solution |
|---|---|---|
| Tasks executing out of order | Incorrect sample time configuration | Verify all sample times are integer multiples of base rate |
| Timing jitter observed | Overload with Queue option | Change to Skip or reduce task execution time |
| System becomes unresponsive | Overload with Delay option causing cascade | Reduce CPU load or change to Skip option |
| Data loss in logging | Skip option losing samples | Change to Queue or reduce overload frequency |