ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

startTime of (SignalPWM) -> ZeroOrderHold

Open dietmarw opened this issue 3 years ago • 7 comments

When using the startTime parameter of the Modelica.Electrical.PowerConverters.DCDC.Control.SignalPWM block I would expect the output "fire" to stay "false" until the block activates after startTime has passed. However, it starts "true" which causes issues when one wants to use the component to model two interlock switches with a time delay where they definitely should not be active simultaneously. Of course, one could also add an additional logic outside but I think the sane default should be that the output until startTime has passed should be "false".

Here is the behaviour: image

dietmarw avatar Sep 19 '22 16:09 dietmarw

Digging deeper into this issue, the problem has its origin in Modelica.Blocks.Discrete.ZeroOrderHold. The first trigger instance occurs at initial(): when {sampleTrigger, initial()} then instead at time>=startTime: when {sampleTrigger, time>=startTime} then Provided no one opposes, I'll provide a PR and prove that this cures the bug @dietmarw reported. @MartinOtter @christiankral @dietmarw @beutlich @HansOlsson any objections? I expect the same issue in Modelica.Blocks.Discrete.Sampler (where ySample.start is not defined). 1

AHaumer avatar Sep 20 '22 16:09 AHaumer

Digging deeper into this issue, the problem has its origin in Modelica.Blocks.Discrete.ZeroOrderHold. The first trigger instance occurs at initial(): when {sampleTrigger, initial()} then instead at time>=startTime: when {sampleTrigger, time>=startTime} then

I agree it makes sense that it triggers at time>=startTime, but it seems normal that startTime=0, and in that case the initial logic for when makes it more complicated (only when-clauses explicitly enabled with initial() are run initially).

Thus I believe it should be:

when {sampleTrigger,initial()} then
  if time>=startTime then 

Due to the definition of sampleTrigger I think that when {sampleTrigger, time>=startTime} then would be redundant.

HansOlsson avatar Sep 20 '22 17:09 HansOlsson

I tested the change as suggested by @HansOlsson in ZeroOrderHold:

when {sampleTrigger, initial()} then
    if time>=startTime then
      ySample = u;
    else
      ySample = pre(ySample);
    end if;
  end when;

And now it works as expected. I agree with @AHaumer that the start time should probably also be recognised in Sampler since it seems strange to be able to specify startTime which then is simply ignored or has no function.

dietmarw avatar Sep 21 '22 11:09 dietmarw

Isn't the functionality of Sampler and ZeroOrderHold the same (despite the fact we have improved ZeroOrderHold)? Shouldn't Sampler extend from ZeroOrderHold to increase maintenability (not taking the Icon into acoount)?

AHaumer avatar Sep 21 '22 14:09 AHaumer

Isn't the functionality of Sampler and ZeroOrderHold the same (despite the fact we have improved ZeroOrderHold)?

There are two differences:

  • ZeroOrderHold adds an infinitesimal delay, so it will be messy to merge them.
  • Conceptual difference: Sampler is intended to sample a continuous signals, whereas ZeroOrderHold holds the signal (and indicates that it is sort of intended for discrete signals).

HansOlsson avatar Sep 21 '22 14:09 HansOlsson

So better to also apply the same change to Sampler as part of #4037 ?

dietmarw avatar Sep 21 '22 15:09 dietmarw

There are two differences: * ZeroOrderHold adds an infinitesimal delay, so it will be messy to merge them.

Right.

* Conceptual difference: Sampler is intended to sample a continuous signals, whereas ZeroOrderHold holds the signal (and indicates that it is sort of intended for discrete signals).

That's the point I don't understand: Both blocks sample the input u at the trigger time instances, so the outputs are both discrete with respect to time. 1

Regarding @dietmarw 's remark: Yes I agree it's better to apply the same change to Sampler.

AHaumer avatar Sep 22 '22 16:09 AHaumer

@dietmarw HI!!! I have recently assumed the role of MAP-lib Project Deputy, I have read through the discussion threads guess that you have the fix for the ticket. Would you commit the fix, We can process the ticket further for review and merge it?

TManikantan avatar Mar 08 '23 12:03 TManikantan

@TManikantan As you can see from the ticket, the fix is already provided in #4045 which is still waiting for agreement from this ticket which in turn is waiting on the input from the library officer @AHaumer which this ticket is also assigned to.

dietmarw avatar Mar 08 '23 12:03 dietmarw

@TManikantan As you can see from the ticket, the fix is already provided in #4045 which is still waiting for agreement from this ticket which in turn is waiting on the input from the library officer @AHaumer which this ticket is also assigned to.

@dietmarw Thankyou and Excuse me for my negligence ,i missed it.

TManikantan avatar Mar 08 '23 12:03 TManikantan