Execute subsystems with phase shift, without impacting code generation

Hello,
I am about to design multi-phase controller for the DC-DC converter.
Idea is to have multiple phases, let's say 4 of them, in this example.
There would be an overall model (controller_overall) which would contain 4 subsystems, one per phase. Code generation should be done over the top model (controller_overall).
These subsystems (ctrl_phaseN, N=0..3) should run on the rising edge of the corresponding phase. Phases would be phase shifted for a quarter of the whole period, comparing to each other. Frequency of all phases is equal.
Problem description
Problem comes between having model with shifted phases and code generation. I've tried to add pulse generators and make ctrl_phaseN subsys as "Triggered subsystem". Phase offset is added to the pulse generators, and each of them connected to the corresponding ctrl_phaseN subsystem. But, when I generate code, there is code from "Triggered subsystem" part, which I want to avoid. These phase controllers would be integrated on the microcontroller interrupt service routine, which will call the subsystem in appropriate timing without any need for intervention of the subsystem itself, in terms of timings.
Is there a way to provide this "phase shifted" execution of those controller subsystems, and avoid having additional source code after code generation?
Generated code:

 Accepted Answer

Hi @Djordje ,

After reviewing your comments, I will suggest create a top-level model named controller_overall. It should contain four subsystems, each representing a phase controller (ctrl_phase0, ctrl_phase1, ctrl_phase2, ctrl_phase3). In this case, each subsystem will be responsible for controlling its respective phase of the DC-DC converter. Instead of using triggered subsystems, I would recommend utilizing pulse generators to create the phase-shifted signals. Set the frequency of all pulse generators to match the desired switching frequency of the converter. For example, if the switching frequency is f, the period T is 1/f. Each pulse generator should be configured to output a pulse with a duration that corresponds to the desired duty cycle.The phase offsets for each generator can be set as follows:

ctrl_phase0: 0 seconds
ctrl_phase1: T/4 seconds
ctrl_phase2: T/2 seconds
ctrl_phase3: 3T/4 seconds

Also, instead of using triggered subsystems, convert each ctrl_phaseN subsystem into a function-call subsystem. This allows you to call the subsystems directly from the main model without generating additional triggered subsystem code. Connect the output of each pulse generator to the corresponding function-call subsystem. This way, the function-call subsystem will execute when the pulse generator outputs a signal. In the Simulink model, navigate to the Configuration Parameters and ensure that the code generation settings are optimized for your target microcontroller.

  • Set the "System target file" to match your microcontroller's requirements (e.g., ert.tlc for Embedded Coder).
  • Under "Code Generation", ensure that "Generate function calls" is selected to facilitate the function-call subsystem execution.

In your microcontroller code, implement an ISR that will call each of the function-call subsystems based on the timing dictated by the phase shifts. This can be done using a timer interrupt that triggers at the frequency of the pulse generators. Using this approach avoids any additional generated code associated with triggered subsystems and allows you to implement precise timing control based on the microcontroller's clock. Example Implementation:

   void ISR_Handler() {
       if (check_time_for_phase(0)) {
           ctrl_phase0();
       }
       if (check_time_for_phase(1)) {
           ctrl_phase1();
       }
       if (check_time_for_phase(2)) {
           ctrl_phase2();
       }
       if (check_time_for_phase(3)) {
           ctrl_phase3();
       }
   }

Hope this helps.

4 Comments

Hi @Umar,
I switched phase controller model to the function call.
Added pulse generator, and connected it to the "function()" port of the Function-Call Subsystem.
But, Simulink still complains about the source. It says that "Pulse Generator" does not procude a function call signal.

Hi @Djordje,

The root cause of this issue is the misunderstanding of the types of signals produced by different blocks in Simulink. Function-call signals are special types of signals that trigger the execution of a block when they are received. Blocks that can produce function-call signals include:

  • Stateflow charts
  • Root-level Inport blocks with the parameter 'Output function-call signal' enabled

In contrast, the Pulse Generator block is designed to output regular time-based signals, not function-call signals. To resolve this issue, you need to ensure that the block connected to the function-call port is capable of producing function-call signals. Here are the steps to fix the error:

Identify the Function-Call Source: Replace the Pulse Generator with a block that can produce function-call signals. For example, you can use a Stateflow chart or a root-level Inport block configured to output function-call signals.

For more information on Stateflow chart block, please refer to

https://www.mathworks.com/help/stateflow/gs/stateflow-charts.html

Modify the Connection: Connect the function-call port to the new block that produces function-call signals. Ensure that the new block is properly configured to trigger the desired behavior in your model.

Test the Model: After making the changes, run the model to verify that the error is resolved and that the function-call mechanism works as intended.

Hope this helps.

Hello Umar,
I found a valid combination of components.
There was missing component "Async Interrupt".
After adding this component in the chain, and configuring for one phase, model is now running properly, and there are is no additional timing related code. Next steps would be introducing new phases.
--
So, connection is the following:
Pulse Generator -> Async Interrupt -> Asynchronous Task Specification -> Trig Input of the Function-Call Subsystem
Thank you for your support and guidances,
BR,
Djordje
Hi @Djordje,
If your problem is resolved, please don’t forget to click “Accept Answer” and vote.
Thank you for your update regarding the model configuration. I am pleased to hear that you successfully identified and integrated the missing "Async Interrupt" component, and that the model is now functioning properly without any additional timing-related code.
Your outlined connection sequence—Pulse Generator -> Async Interrupt -> Asynchronous Task Specification -> Trig Input of the Function-Call Subsystem—provides a clear overview of the current setup. I appreciate your diligence in configuring it for one phase.
As you move forward with introducing new phases, please do not hesitate to reach out if you require further assistance or guidance.

Sign in to comment.

More Answers (0)

Asked:

on 11 Oct 2024

Commented:

on 15 Oct 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!