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)
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
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)
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.