Repository navigation
Relate clocks in Integer/Boolean AssignClockToSquareWaveHold as in the Real version - #4849
Open
hubertus65 wants to merge 1 commit into
Open
hubertus65 wants to merge 1 commit into
hubertus65 wants to merge 1 commit into
Conversation
…e Real version
The Integer and Boolean versions of AssignClockToSquareWaveHold relate the
clock of their input u to the internal square wave y2 through a "dummy
condition" with identical branches:
y2 = if u > 0 then not previous(y2) else not previous(y2);
A tool may simplify this to y2 = not previous(y2), which drops the clock
relation. OpenModelica 1.27.1 does, and assigns the default clock (1 s)
to y2: the output toggles once per second instead of at every tick of u.
Use the clocked when-equation with a dummy assignment that the Real
version already uses:
when Clock() then
uu = u "Dummy assignment to relate clock of u with y2";
y2 = not previous(y2);
end when;
With this change, both outputs toggle at every tick of a 20 ms input clock
in OpenModelica, and the Real example AssignClockToSquareWaveHold is
bit-identical. Dymola 2026x translates the changed blocks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Integer and Boolean versions of
Modelica.Clocked.*Signals.Sampler.Utilities.AssignClockToSquareWaveHoldrelate the clock of their inpututo the internal square wavey2through a "dummy condition" with identical branches:A tool may legitimately simplify this to
y2 = not previous(y2), which removes the only relation betweenuandy2. OpenModelica 1.27.1 does exactly that and assigns the default clock (1 s) toy2. With a 20 ms input clock, the output then toggles once per second instead of at every tick.The Real version of the block does not have this problem. It ties the two signals with a clocked when-equation and a dummy assignment. This PR uses the same pattern in the Integer and Boolean versions:
Verification (OpenModelica 1.27.1)
Test: an Integer and a Boolean signal sampled with a 20 ms periodic clock, each converted with
AssignClockToSquareWaveHold, simulated for 1 s.yin 1 s, beforeModelica.Clocked.Examples.Elementary.RealSignals.AssignClockToSquareWaveHoldis bit-identical before and after. Dymola 2026x translates the changed blocks; the local license limit prevented simulation. The test model is part of the ModelicaTest coverage work on branchcoverage-improvement.🤖 Generated with Claude Code
https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT