0
votes

Question

Is there a way to make a block force a simulation step to occur at a given time(s)?

For instance, even though the user chose a simulation step size of 1e-2 in his model (fixed-step simulation), if he uses my block then a simulation step will occur at 2.5e-4 seconds?


Context

I'm developing a PWM generator block [1], and my initial approach has a big problem. To best explain this, I've drawn a simple diagram: as

The signal in black is what I want the block to generate (square signal, period T, has value 1 during D.T seconds, where D is a constant between 0 and 1). The blue asterisks are the points sampled at the simulation step times (assuming fixed step simulation). The blue line is what the block actually generates, since after the 5th and before the 6th simulation step the value 1 will be held.

This desynchronization of the step times with the signal's change of value introduces an error in the mean value of the signal (since it will stay more time than what was intended at 1). At the worst case scenario this error will be of s/T, where s is the simulation step size and T is the period of the signal to be generated (I could post the derivation, but I don't know how to write equations here and it is very simple). A straightforward way to resolve this problem would be to decrease the step size, but this is not always feasible, depending on the period of the PWM.

If there was a way to force a simulation step to occur at 0, D.T and T seconds, then the mean value of the blue and black signals would be exactly the same.

If this needs more clarification, please say so. Thanks in advance.

1 - PWM is a periodic square signal that, during its period, stays a given amount of time with the value 1 and the rest of the time at value 0, therefore having arbitrary mean value between 0 and 1.

1
NOTHING happens between simulations times...Thats... absolutely absurd. The computer simulates time t1 and then t2 and then t3... If you want to do what you want then you need to create a simulation ste in the t you want. it has to be simulated.Ander Biguri
Perfect, the question is exactly about that: "How to make a block force a simulation step (...)".JLagana
I dont hink you can change the simulation configuration from a bock. you can set up the simulation configuration manually and make the block do something in Tn time, therefore simulink will simulate that time because something i hapoening. However I am not sure. Check if you can do that.Ander Biguri
A fixed-step simulation is just that, fixed-step. You can't change it, period. If you want the solver to detect the changes in your PWM signal, you need to use a variable-step solver with zero crossing detection enabled.am304

1 Answers

1
votes

As I mentioned in the comments, if you are using a fixed-step solver, then the step size is, well... fixed for the duration of the simulation. So you (or the user) needs to set it appropriately before starting the simulation to make sure all effects are captured. There is no other way to go about it I'm afraid.

The only other option is to use a variable-step solver, which will adjust the step size dynamically based on the dynamics of the system, and to have zero-crossing detection enabled to capture the precise instant when the PWM is switching. For more details on zero-crossings, see the documentation.