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:
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.
t
you want. it has to be simulated. – Ander Biguri