Using fast implementations for variable frequency pulse generation | Simscape Electrical Modeling Practices for Fast Simulation - MATLAB & Simulink
Video length is 12:11

Using fast implementations for variable frequency pulse generation | Simscape Electrical Modeling Practices for Fast Simulation

From the series: Simscape Electrical Modeling Practices for Fast Simulation

Learn techniques to model a fast implementation of a variable frequency pulse generator for variable frequency converters. Additionally, the modeling of switching dead times for fast simulation is considered too.

Published: 7 May 2024

Hello, my name is Gernot Schraberger. I'm an application engineer at The MathWorks. And I want to show you in this video how you can speed up electric circuits modeled in Simscape that contain variable-frequency converters. Therefore, I open here live script that will lead us through the workflow and also give some basic description of the circuitry.

So the first thing here is that I have to open the reference model. I do that with a specific mode where I can step through the live script section by section. So you can see here this LLC resonance converter. We have got the main part, the resonance circuit here in the center, built up by a capacitor and by coils and the transformer.

And this one is driven here by an H bridge. So we either switch the bus voltage here to the capacitor or the ground. And that we do with a frequency of about 100 kilohertz up to 1 megahertz. And then the signal is transferred here to the secondary side. We have got a rectifier here. And we'll get out a DC voltage, which is smoothed here with a capacitor.

The voltage is measured and compared with the reference voltage and then fed to the controller. It's an I controller with the gain factor here. And this controller will output here a frequency as a value. This frequency then is driving the gate driver that contains a VCO, a Voltage-Controlled Oscillator.

Well, the frequency signal is integrated here. And then we have got a comparator that will compare the output value with pi. And that means 50% of the time, this output signal will be high, 50% it will be low. And that's driving the gate pulses. And of course, this output signal here is depending on the frequency signal we got in here.

Then we have got additional delays here for switching on the pulse that prevents short circuits in the H bridge. This H bridge here is modeled with two detailed MOSFETs. We can use that for the simulation of the transient and for analysis of power losses. But very often, that will not be needed in that detailed level. But let's start first here with a reference simulation just to measure the execution time. We do that once again here with the live script.

The model actually is using variable-step solver daessc. And down here, you see where execution has started. And we just wait for the end. I have added here a callback that will measure that execution time and also initialization time, as we'll see soon.

So you can see the execution time was 48 seconds, initialization time is 6.7 seconds, and termination time 0.5. I think it's important to compare the execution time, not the initialization time necessarily, because such models typically will run much longer. And that's the real time that counts. So in the next step, we can decide what can we do to speed up the simulation.

So probably, we will not need the detailed transient of switching because we are just interested in the harmonics, for example, for designing a filter. So we can replace that block with an ideal switch. That is done automatically by executing the next section.

Now you can see the updated model here. And the total execution just took 5.9 seconds now. So it's pretty much faster. Now, for further speedup, it will be necessary to further analyze the model. And there's a tool called Solver Profiler. I can go down here to the Solver settings. Click on here, on the symbol. And then Solver Profiler opens.

That's an app that allows me to access logged signal for detailed analysis of the model, especially if it's working with variable-step solver, which is the case here. I enable all these analysis options here. And then I click Run here in the Solver Profiler. That's important.

You see simulation is in progress. I even don't have to wait for the very end. I can stop it here now. So we see here the variable step size used with the variable-step solver over the execution time. And we can zoom in here just to see more details. Typically, we execute the model with a step size of about 100 nanoseconds up to 1 microsecond.

This information we can take from here. But there are always moments where a much higher accuracy is needed. So what we can do here now is we can analyze where is it coming from. I can click here on Zero-Crossings, for example. And we can see here all of these points have got zero-crossings in there.

We can also click on Solver Exception. That's also something that occurs several times. If we go down here to the tabs, we can see where the zero-crossings or solver exceptions are coming from. Most zero-crossings are coming from the VCO, from the comparator there, that will create the square wave.

But we also can see that we have zero-crossings because of the diodes D1, D2. These are these two tiles here. That's something we have to accept, we cannot change a lot. But then we have got also zero-crossings here from diodes in the switch in the half bridge-- diodes and the switch. So it's somewhere in here.

If we look in here, we can see how this block is built up. We've got an ideal switch here. We can open the block here. The ideal switch uses a closed resistance value and an open conductance value. So it's a piecewise linear component. And we've got also a diode that works with piecewise linear description.

Because we get several zero-crossings from these blocks, we can think about combining these two components to a single component just to further speed up the execution. Other zero-crossings are coming here from the delays. I can click here and go to Highlight Block. That will automatically open the block. And you can see here that's a block that we've seen before for the creation of the switch-on delays. So we also use zero-crossings here.

So now I would say let's have also a look to the solver exceptions, where they come from. And we see here once again that D1, D2. The dynamic behavior changes quite a lot when we do the switching here, the same for the half bridge. But we see also capacitors here in the half bridge. And that's the question. Well, can we prevent these solver exceptions here at the capacitor if we, for example, remove the capacitor. So let's further tune the model.

So in the next step, we combine the switch and the half bridge diode to a single component and remove the switch capacitors and also the rate limiter because I think that does not play a big functional role. So let's go here and also execute this section here. You see that the switch is changed here. That's a idealized component, combining the switch and that in a single block.

And we reach now an execution time of 0.93 seconds, so even much faster. In the next step, we will also change here the pulse generator that we have seen here before using the integrator and the comparator. And instead we will use here pulse generator that uses a fast Simulink VCO.

That's something from the Simulink library, and that's a concept that is not using zero-crossings. But therefore we have to use here a certain logic to include here the dead time for the switch on delay. So we also execute that here with Run and Advance. And we get execution time of 0.66 seconds, so even much faster.

In the last step, we can also take out here the scope block because scope blocks also need a certain execution time. And we use these logging signals that you can see here, all these points. And if we execute once again the model without the scope, well, we get a little bit faster. It is not that much because we don't have many scopes here, but it got a little bit faster.

So finally, we also have to compare, of course, the most important logging points if the system behavior did not change too much. And as you can see here, we always have logged the outputs here with different variables. And now we access them and show them in the Simulation Data Inspector just by executing the last section here.

So the first signal here is a reference. We just have to expand that. Then the simulation with the combined diode and switch and no capacitor and rate limiter. And the last one is the different form of variable-pulse generator that does not use zero-crossings. And we can see here output signals and also the reference signal. Of course, the reference signal must be the same.

So we can see here a certain deviation. That is something I expect because we started here. The first one is the detailed simulation. The other ones are simulations with ideal MOSFET behavior. And what you also can see here is the oscillation here coming from the resonance circuitry. So this is still here. And it's still here on all these simulations.

So even with the fast simulation, you see these frequencies here. There's a little bit of phase shift and also a little bit of different amplitude, but it's not too far off, as you can see here. Well, I hope you have learned something out of this video that you can use in your models to speed up circuitries with variable-frequency switching. Thanks for listening.