How can I use a mask to switch between internal and external clock in a referenced subsystem?

2 visualizzazioni (ultimi 30 giorni)
Here's my situation:
I have a subsystem saved as its own file, let's call it "DDS.mdl"
I use a Referenced Subsystem block to use DDS.mdl in other models.
I have a model, "example1.mdl" which uses "DDS.mdl" in a Referenced Subsystem block. It works just fine.
I have another model, "example2.mdl" which uses "DDS.mdl" in a Referenced Subsystem block inside of a Triggered Subsytem block.
"example2.mdl" does not run, because one of the blocks inside of "DDS.mdl" is a "Clock" block and because of that I get the error:
(Path to Block) has sample time 0. Sample time of block must be inherited (-1) because blocks in a triggered subsystem must run only when the triggered subsystem runs.
"Clock" of course, does not have a "sample time" block that I can use to inherit.
I had a "great idea" in that I created an additional inport named "EXT_CLK" and I added a mask to "DDS.mdl" with a checkbox for "Use External Block" and associated parameter UseExtClk. I feed "EXT_CLK" into the top of a Switch Block and the "Clock" block into the bottom of the switch block, and my mask parameter, UseExtClk as the trigger for the switch. If it's true, it will pass EXT_CLK instead of "Clock".
Except, that doesn't work because the mere presence of the "Clock" block in the subsytem generates this error, because its code still tries to run.
So, here's what I would like to do:
When UseExtClk is true, the EXT_CLK inport appears on my subsystem and the "Clock" block is disabled
When UseExtClk is false, the EXT_CLK inport disappears from my subsystem and the "Clock" block is enabled.
How can I accomplish this?
Is there a way to make "DDS.mdl" itself a variant subsystem? If so, what is it and how would I hide the unused inport?
I know I could make a variant subystem inside of "DDS.mdl" - one with the "clock" block and one without - but I don't believe that would eliminate the EXT_CLK inport - it would be a useless inport to my subsystem still showing.
I know I could also make a second file. DDS2.mdl and create a variant subsystem in "example2.mdl" that would have two different referenced subsystem blocks inside, controlled by the block parameters of the variant subsystem - but I would like to avoid this as it would duplicate a lot of effort and if I make future edits I now have to edit both files.
What is the best path forward here?

Risposte (1)

Yatharth
Yatharth il 5 Set 2023
Hi,
I understand that while using "Clock Block" in your subsystem and calling it using a "Subsystem Reference" within a “Triggered subsystem” you are getting the following error: "Sample time of block must be inherited (-1) because blocks in a triggered subsystem must run only when the triggered subsystem runs”.
Also, the “Clock Block” doesn’t have sample time property.
"Clock" Block cannot be used in a Triggered Subsystem. The solution is mentioned in the documentation:
"When you need the current time within a discrete system, use the Digital Clock block."
You can learn more about the "Digital Clock" here
Also please note this in the documentation about Digital Clock:
"Also, avoid specifying -1 (inheriting the sample time) because this block is a source."
I hope this helps.

Categorie

Scopri di più su Subsystems in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by