Execute subsystems with phase shift, without impacting code generation

2 views (last 30 days)
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

Umar
Umar on 12 Oct 2024

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
Djordje
Djordje on 15 Oct 2024
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
Umar
Umar on 15 Oct 2024
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)

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!