MATLAB: Maximum step size or automatic timing

MATLABmaximum step timeSimscape Electricalsimulation timesimulink

Hi,
First time here, so please bear with me while I get the hang of this.
I am modelling a dc-dc converter at high frequency using peak current control using SimPowerSystems. I know that simulink uses a variable time steps to speed up the simulation time. Now, my model relies on a set pulse to activate an SR flip flop. The trick here is that the set action only needs to happen at the beginning of the period and begone as soon as possible thereafter to give the control signal the time to reset it when necessary during the period. But with variable timing this does not always happen; i.e. the pulse sets the flipflop but does not quickly disappear because of the large step size.
Now, I was wondering what the best way to over come this is: I could set the maximum step size to for example, 1e-6 seconds or I can set my pulse generator to a period of 1e-4 and the percentage of the duty cycle to 0.01.
I noticed that there is a timing difference between the 2 methods and want to know which method (or any other that people might know) works best (i.e. fastest with highest accuracy).
Regards,
Dirk

Best Answer

Hi Dirk,
This is very good question.
There are 2 ways in Simulink to force a variable-time step solver to take a step at a specific time.
The most common one is zero crossing. In that case, the solver detect that some signal passed a certain threshold and goes back and forth in time t find the exact time when it happened.
I recommend looking at this doc section:
or a at demos like the one titled "Accurate Zero-Crossing Detection"
The other method is variable sample time. this is what the pulse generator block does. Every time it runs, the Pulse Generator block knows when it should run next. For example if you set it to a period of 10sec and a pulse width of 20%, it will run at 0,2,10,12,20,22,...
This doc page should help with that:
Typically, you need to write an s-function for that. This is a bit more complex to implement, but can be more efficient since you do not need to go back and forth in time to bracket the event like with zero-crossing.
If you are interested, I have a blog post where I use a variable sample time s-function here:
In your case, this will probably be simpler than the example in this post.
I think I will write another post on this topic soon.