Multi-rate control on Simulink with ACG SDK
This document provides instructions on how to implement Multi-rate control on Simulink with ACG SDK. It allows running part of the control at a slower rate, without impacting the real-time control running at the base rate. This is typically useful for implementing a finite state machine or running a tracking algorithm.
Enable MultiTasking
- Make sure the imperix CONFIG block mode is set as code generation
- Go in the Model Configuration Parameters -> Solver -> Solver details
- Check Treat each discrete rate as a separate task (for older MATLAB version: for the option Tasking mode for periodic sample times select MultiTasking)
![Product notes > PN145: Multi-rate control with Simulink > image-20200507-133252.png Enable multi-tasking in the model configuration parameters](https://imperix.com/doc/wp-content/uploads/2021/03/image-106.png)
Using MultiTasking
The base rate frequency is set using the CONFIG block and defines the interrupt frequency. The resulting sample time is available through the global variable CTRLPERIOD
.
To enable colors to display sample time do Right-click on the model ā Sample Time Display ā Colors
![Product notes > PN145: Multi-rate control with Simulink > image-20200507-133422.png Display sample times as colors](https://imperix.com/doc/wp-content/uploads/2021/03/image-108.png)
To interface logic running at a different rate, add Rate Transition blocks. In the block parameters:
- set the output port sample time (for instance 0.1 for a 10 Hz frequency)
- check Ensure data integrity during data transfer so the generated code will use an intermediate variable (and thus avoid data corruption)
![Product notes > PN145: Multi-rate control with Simulink > image-20200507-133906.png Rate transition block to define a slower task](https://imperix.com/doc/wp-content/uploads/2021/03/image-109.png)
An example of use is presented in Maximum Power Point Tracking (MPPT) (TN117). It shows how one part of the control (in red in the figure below) can be executed at a slower rate than the main control code.
![Product notes > PN145: Multi-rate control with Simulink > image-20200514-135836.png Multi-rate maximum power point tracking example](https://imperix.com/doc/wp-content/uploads/2021/03/image-111-1024x435.png)