- Replace the 20 kHz atomic subsystem with a Function-Call Subsystem.
- Drive it using a Hardware Interrupt block (configured for 20 kHz).
- Set the Function-Call Subsystem to use inherited sample time (-1).
- Keep your 100 kHz subsystem as the base rate task.
Model Base rate issue in multiple atomic block system
5 views (last 30 days)
Show older comments
I have set up a nested interrupt control architecture on an embedded MCU, and i am using simulink Ebmbedded Code Generator to compile executable functions. One subsystem runs at 100kHz and the other at 20kHz. The issue i'm facing is that the 20kHz model, even though it's a separate subsystem with its own atomic sample time, has a rate scheduler function that's indexing the 100kHz rate. The trouble is that the ISR in the MCU is already at 20kHz, this makes it run at 4kHz (20 divided by 5).
I don't now how to set its as its own independednt sample time within the simulink model.
/*
* This function updates active task flag for each subrate.
* The function is called at model base rate, hence the
* generated code self-manages all its subrates.
*/
static void rate_scheduler(void)
{
/* Compute which subrates run during the next base time step. Subrates
* are an integer multiple of the base rate counter. Therefore, the subtask
* counter is reset when it reaches its limit (zero means run).
*/
(M_Slow->Timing.TaskCounters.TID[1])++;
if ((M_Slow->Timing.TaskCounters.TID[1]) > 4) {/* Sample time: [5.0E-5s, 0.0s] */
M_Slow->Timing.TaskCounters.TID[1] = 0;
}
}
0 Comments
Accepted Answer
Sameer
on 9 Jul 2025
Hi @Federico
To make the 20 kHz subsystem run independently and not get scheduled as a subrate of the 100 kHz base rate, you need to avoid relying on the default rate scheduler that Simulink generates. By default, Simulink sets the fastest sample time (100 kHz in your case) as the base rate, and slower rates (like 20 kHz) get scheduled relative to it. That’s why you’re seeing the 20 kHz code running every 5th tick (effectively 4 kHz if your MCU ISR is at 20 kHz).
To fix this, you should use Function-Call Subsystems triggered by hardware interrupts instead of relying on time-based sample rates. For example, if you're using a supported MCU (like TI C2000), you can use the Hardware Interrupt block to drive the 20 kHz subsystem. This way, Simulink generates a separate ISR for it, and it won't be tied to the 100 kHz scheduler.
This will generate truly independent functions for each rate, and the 20 kHz task will run exactly when your ISR fires, not based on the 100 kHz base rate.
Hope this helps!
0 Comments
More Answers (0)
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!