Skip to content

How to Set a Phase Shift Using Simulink

Overview

This page explains how to shift the operating timing of switches within a period, as in a phase-shift full bridge. In co-simulation of Scideam and Simulink, the phase shift amount calculated in Simulink is passed to Scideam with an SLC script. This page shows two methods with code examples.

Method Description
Use the initial time of a sub frequency Register the part to be shifted to a sub frequency, and change the initial time Tini according to the phase shift amount
Shift the state change times of a PWM switch Set T0 and T1 of two PWM Switch parts to the same values, and shift T0 and T1 of one of them according to the phase shift amount

For details on SLexport(), SLsync(), and SLimport(), see Editing an SLC script file. For a complete example of phase shifting with a Scideam script, see Script control of the phase-shift full-bridge circuit.

Note

The code examples on this page assume a phase-shift full bridge and handle the phase shift amount in the range of 0 to 180 deg. To handle negative phases (lead and lag), as in a DAB converter, see the DAB converter sample.


Example of Shifting the Phase with the Initial Time of a Sub Frequency

Create a sub frequency in advance, and register the part whose phase you want to shift as its target (in a phase-shift full bridge, the Pulse that drives one leg). The initial time represents the phase difference time relative to the main period and is set in the range 0 ≦ initial time < main period. The parameter name of the initial time of a sub frequency is Tini. Receive the phase shift amount Phase [deg] from Simulink, convert it to a time relative to the main period T, and set it.

// Get the voltage of R1 in the Scideam circuit model
Vout = output("R1", "V", "AVE");

// Set the Scideam simulation result to the output of the SCIDEAM block in Simulink
SLexport(1, Vout);

// Synchronize with Simulink
SLsync();

// Receive the phase shift amount [deg] from Simulink
Phase = SLimport(1);

// Guard the input
if(Phase < 0) Phase = 0;
if(Phase > 180) Phase = 180;

// Get the main period and convert the phase shift amount to a time
T = param("Ts", "Value");
Shift = Phase/360*T;

// Apply the received phase shift amount to the initial time of the sub frequency SubFreq
setparam("SubFreq", "Tini", Shift);

Note

A change to the initial time of a sub frequency is applied at the end of the main period, not at the moment setparam is executed.

Note

The symbol names in the code (R1 and SubFreq) are examples. Specify the symbol name of the sub frequency registered in the config editor for SubFreq, and the symbol name in your actual circuit for R1.


Example of Shifting the State Change Times of a PWM Switch

This method directly shifts the state change times T0 and T1 of a PWM switch without using a sub frequency.

Set two PWM Switch parts (the reference side Q1 and the shifted side Q3) to the same settings as follows. In this state, the two switches operate at the same timing.

Item Setting
Mode Ratio
Initial State OFF
T0 (turn-on time) 0
T1 (turn-off time) 0.5

Convert the phase shift amount Phase [deg] received from Simulink to the ratio Shift relative to the period, and shift T0 and T1 of the shifted side Q3 by the same amount. The duty ratio stays at 0.5, and only the turn-on position shifts later.

// Get the voltage of R1 in the Scideam circuit model
Vout = output("R1", "V", "AVE");

// Set the Scideam simulation result to the output of the SCIDEAM block in Simulink
SLexport(1, Vout);

// Synchronize with Simulink
SLsync();

// Receive the phase shift amount [deg] from Simulink
Phase = SLimport(1);

// Guard the input (limit to 0 to 180 deg so that T1 does not exceed 1)
if(Phase < 0) Phase = 0;
if(Phase > 180) Phase = 180;

// Convert the phase shift amount to a ratio relative to the period
Shift = Phase/360;

// Shift the on and off times of the shifted side Q3 while keeping the duty ratio at 0.5
setparam("Q3", "T0", Shift);
setparam("Q3", "T1", Shift + 0.5);

Note

When Mode is Ratio, T0 and T1 must be set in the range of 0 to 1 and in monotonically increasing order. Because the guard in the script limits the phase shift amount to 0 to 180 deg, T0 stays in the range of 0 to 0.5 and T1 in the range of 0.5 to 1.

Note

The symbol names in the code (R1 and Q3) are examples. Change them to match the symbol names in your actual circuit.