Using different PWM implementations for faster simulation of converters | Simscape Electrical Modeling Practices for Fast Simulation
From the series: Simscape Electrical Modeling Practices for Fast Simulation
Learn what you must consider when you build up a model for fast PWM switching. This video shows the dependency of execution speed from the solver selection, the converter fidelity variant and from different PWM block implementations. Additionally, the modeling of switching dead times for fast simulation is considered too.
Published: 7 May 2024
Hello, in this video I want to show you techniques how you can model fast-running simulations of electrical circuits that contain Pulse-Width Modulation, PWM. This is very often the case if you have power switches in use for motor drive or for converters.
I want to also give you the information that all the material I'm using for the demonstration you can download with the link below, such that you can reproduce those things and copy out those blocks or elements for your specific purpose in your model.
My name is Gernot Schraberger. I'm an application engineer at The MathWorks in Munich. So let's start here in this project.
You can see here we are going to 0.6 modeling techniques, six underline one is fast PWM simulation. And we start here with a live script. This fast PWM simulation dot MLX. MLX stands for the live script.
And you can see here in a live script, it's a combination of documentation and executable file. You can see here an explanation what the demo is about. It's about fast-running PWM.
And I think the first and the important question is, what is the objective or the goal of the simulation? Because it makes a big difference if you want to run a PWM together with the analysis of trajectories, switching trajectories of MOSFETs or IGBTs, we'll need a high-accuracy simulation. That's one thing.
The other thing is if you have, for example, interest only in the harmonics but not in power losses during the switching. In that case, you can use ideal switching behavior of the IGBT or a MOSFET. And, optionally, you often have a diode, as well.
In a third case, you might use average models in case of control design purposes. Here is also an option for a so-called subcycle averaging, if you are interested in harmonics but with lower fidelity. And if you have to run that, for example, on the real time system.
So the first thing I have to do here is I have to open a reference model. So I click here on Run At Once.
And the next step then is to show sample time colors. And you see the colors of the model blocks will change. You can see here that all the blocks and input signals to the PWM generator are indicated in green color, which means we have an update rate here of 50 microseconds.
On the other side, for the gate pulses and also the calculation done within the IGBTs or ideal-switching system is done with 100 nanoseconds, so with a much higher accuracy. We are using here fixed step solver, OD4.
I will now explain you what the model is about. Here at the beginning, we start with a generation of three-phase sine waves. This can be controller outputs in the real setup.
So they are generated here with a specific magnitude and frequency. We use a vectorized signal here to go to the next block, which is PWM timing and waveform generator.
Here, PWM waveforms are generated in the sense that we generate switching on and switching off times per phase. We have an additional output here for the mod wave, which is expressing a duty cycle.
But we use here for the PWM generation this switch-on and switch-off times. And because these times can have any value, any floating point value but in reality, you might program a digital PWM generator with that. And that means if you have a digital PWM generator, you will have to switch at specific intervals in a specific raster. And that's what I show here in this diagram, as well.
So if we want to use the raster, we have to synchronize the PWM to the raster. Let's go to the next block. This is the PWM generator itself.
I have also variant subsystem here. And if I look into this block, you can see the actual variant is a default three-phase PWM generator. We can look under the mask here.
And what you can see here is that this PWM generator block is using internally an integrator, which is implemented as a time-discrete integrator. So even if we would use a variable step solver now on the global level, we will still have this discrete integrator in here, which might slow down our simulation.
But there are also other options in here. I have options where I consider time delays between the high and the low side to prevent short circuits. So have always got this variant, as well, but I have also other implementations of the generator.
For example, this one here is using single blocks that convert a duty cycle to PWM. There's another one I will show later where we use a fast Simulink PWM generation variant.
So far, to the PWM generator block, we then come out here with the gate pulses to a gate interface. So we convert the logical signals to voltages. And we then drive the gate inputs of either the ideal switching plus diode converter, or a MOSFET, or IGBT converter, or even an average converter.
So all these are variants that can be found in here in the variant subsystem. And this blog is finally done driving an RL circuitry in a Y configuration that's representing a simple motor.
Well, now the point is that, of course, not all combinations of solvers, of PWM implementations, and inverter models make sense.
Therefore, I have created variant configurations with the Variant Manager. And I can load these configurations here in the next step.
So we have now ideal switching OD4, default three-phase generator that we've seen before. I can then override the PWM accuracy and delay setting, as I've explained.
And the last step here will be closing the Simulation Data Inspector for having comparable runtimes. Start of the model, collecting the timing information, and plotting the output signals here. And they will also update the name of the single plots and code in the execution time so that you can see how long this execution took. So let's do that here.
So now, automatically, the Simulation Data Inspector appears with this run. You can see the runtime that I've coded in here and the solver settings, as well as the type of PWM and model fidelity.
So let's go up here again and change the configuration. I now choose, for example, ideal switching, but OD's 20-3T, a variable step solver but with the same PWM generator.
I go down here again and execute this section. So the model is updated now.
We see other colors here. We see continues because of variable step solver. We see also fixed in minor step. But we still have the 100 nanoseconds in here. The reason is, as I mentioned before, that within this PWM generation block, we have got time discrete integrators.
Simulation is faster with 11 seconds. So we have a benefit here. But let's see if we can go further.
So the next setup I want to choose here is ideal switching, but now with the fast PWM generator and ODN. That's a special solver for switching events. I once again go down here and execute this section. And you can see here now that we have only continuous timing, fixed a minor step and some variables.
And you see, if only 50 microsecond as the shortest timing, which is the timing of the input signals coming from the controller. Execution was done now in 1.43 seconds, so much faster compared to the 11 seconds we had before.
The last thing I want to show you here is the configuration with subcycle averaging. In case of subcycle averaging, the main cycle is divided by 8, in this case. So we will have a subcycle of 6.25 microseconds.
I can also execute the model here. And we do a fixed-step simulation. And here we reach an execution time of 0.57 seconds.
The only thing that you will see here in the signal output-- and we do some comparison now between subcycle averaging and, for example, the fast Simulink simulation here with ODN. And if I go here, for example, to the gates, and I click on gate 1 and 2 here, also for subcycle averaging.
You will see that subcycle averaging is not only using zero and 1 as output values, but also intermediate values to express a switching, not in sense of different times but in the sense of different amplitudes. That's the concept of subcycle averaging.
And the same thing we will see here on the current side if we activate here the currents in the display and compare it to the currents of the former simulation. You will also see differences here if you zoom in.
You can see here the triangle shape of the signals and the step-wise simulation in case of subcycle averaging. Subcycle averaging is just using the average value of a certain period. That means we'll have at least the same first harmonic frequency if we do an FFT analysis.
So we get information about the harmonics, also, and subcycle averaging. But, of course, we don't have this high accurate time solution here in the simulation.
I hope you can use what you've seen today in your models. And I hope to see you soon in another video.