I wonder if it's normal that (in my opinion) using a "pure discrete S-function" (Matlab - Level 2) with variable sample times, the outputs are calculated before the update, so that the outputs are only visible the next sample.
An example is the following:
I wanted to make my own pwm output function, with the PWM signal as an output, and period and "high time" as inputs. I have no problems making it. But it doesn't do exactly what I want to do. I'm sampling only at the toggling points (which I find logical). And trying to get what I want to do I see 2 options:
- In the Update-function, the output is toggled in a discrete state, and this state is used in the Output function.
- I move the toggling to the Output function (also meaning that I don't need a state, since the output-value can be used to toggle.
Both don't do what I want:
- In the first case, the output is only changed in the next sample.This works, except that there is a delay in using the inputs (although DirectFeedTrhough is true), and is seems unlogical that the state is different from the output.
- In the second case, it works in soms sense better, except that the output changes effectively the next sample, and when this next sample is taken depends on the rest of the model. As an example: if "Outputs" is called at t=0, and the OutputPort value is changed (I know that this could be solved by adding extra sample points, but this doesn't "feel right".) One of the consequences is that the effective frequency and duty cycle (as used by the rest of the system) depends on the sampling of that "rest of the system".
My question is:
Is it possible to have a change in a discrete state value direct influence to the output?
(I can send code, but the code that I currently have is more than what I explain here.)