how to make parameters valid in components of ssc documentaion?

4 views (last 30 days)
this code is from the SPICE cir after subcircuit2ssc,but it cannot ssc_build for the error :Invalid use of value 'node_2.v'. All entities referenced in this expression must be valid parameters.
• In mylibrary.rc1 (line 58)
the version I tried includes 2021a and 2023b
  1 Comment
yh shang
yh shang on 8 Nov 2023
this is my code:
component rc1
% rc1
% Component automatically generated from a SPICE netlist for subcircuit RC1.
% MATLAB version: 23.2.
% Simscape Electrical version: 23.2.
% Simscape code generated on: 07-Nov-2023 18:37:14
nodes
node_1 = foundation.electrical.electrical; % node_1
end
nodes(Access=protected, ExternalAccess=none)
node_2 = foundation.electrical.electrical;
end
annotations
UILayout = [
UIGroup('Parasitic elements', ...
specifyParasiticValues, capacitorSeriesResistance)
UIGroup('Smoothing functions', ...
specifySmoothValues, aWarning, expXh, expXl)
]
end
parameters
specifyParasiticValues = ee.enum.include.no; % Specify parasitic values
end
parameters(ExternalAccess=none)
capacitorSeriesResistance = {0, 'Ohm'}; % Capacitor parasitic series resistance
end
if specifyParasiticValues == ee.enum.include.yes
annotations
[capacitorSeriesResistance] : ExternalAccess=modify;
end
end
parameters
specifySmoothValues = ee.enum.include.no; % Specify function smooth parameters
end
parameters(ExternalAccess=none)
aWarning = ee.enum.include.no; % Include warning
expXh = {Inf, '1'}; % Upper boundary of linear extrapolation for exp(x), typical x=80
expXl = {-Inf, '1'}; % Lower boundary of linear extrapolation for exp(x), typical x=-80
end
if specifySmoothValues == ee.enum.include.yes
annotations
[aWarning, expXh, expXl] : ExternalAccess=modify;
end
end
components(ExternalAccess=observe)
R1 = foundation.electrical.elements.resistor(R={(1*1000),'Ohm'});
C_CGD1 = foundation.electrical.elements.capacitor(c={(0.5*simscape.function.expm(value(node_2.v,'V'), ...
expXl, expXh, aWarning)),'F'},r=capacitorSeriesResistance,g={0,'1/Ohm'},vc.priority=priority.none);
end
connections
connect(R1.p,node_1);
connect(R1.n,node_2);
connect(C_CGD1.p,node_2);
connect(C_CGD1.n,*);
end
end

Sign in to comment.

Answers (1)

Pramil
Pramil on 10 Oct 2024
Edited: Pramil on 10 Oct 2024
Hi Shang,
I am not a expert on SPICE but I can help you with the SSC code.
In the "components" attribute, you cannot use a variable whose value changes during simulation and since "node_2.v" changes during simulation, it results into an error.
Here is the updated code which works on MATLAB R2023b. Since the value of "C_CGD1" depends on "node_2.v", you can set it up in "equations" attribute.
component rc1
% rc1
% Component automatically generated from a SPICE netlist for subcircuit RC1.
% MATLAB version: 23.2.
% Simscape Electrical version: 23.2.
% Simscape code generated on: 07-Nov-2023 18:37:14
nodes
node_1 = foundation.electrical.electrical; % node_1
end
nodes(Access=protected, ExternalAccess=none)
node_2 = foundation.electrical.electrical;
end
annotations
UILayout = [
UIGroup('Parasitic elements', ...
specifyParasiticValues, capacitorSeriesResistance)
UIGroup('Smoothing functions', ...
specifySmoothValues, aWarning, expXh, expXl)
]
end
parameters
specifyParasiticValues = ee.enum.include.no; % Specify parasitic values
end
parameters(ExternalAccess=none)
capacitorSeriesResistance = {0, 'Ohm'}; % Capacitor parasitic series resistance
C_CGD1 = {1,'F'};
end
if specifyParasiticValues == ee.enum.include.yes
annotations
[capacitorSeriesResistance] : ExternalAccess=modify;
end
end
parameters
specifySmoothValues = ee.enum.include.no; % Specify function smooth parameters
end
parameters(ExternalAccess=none)
aWarning = ee.enum.include.no; % Include warning
expXh = {Inf, '1'}; % Upper boundary of linear extrapolation for exp(x), typical x=80
expXl = {-Inf, '1'}; % Lower boundary of linear extrapolation for exp(x), typical x=-80
end
if specifySmoothValues == ee.enum.include.yes
annotations
[aWarning, expXh, expXl] : ExternalAccess=modify;
end
end
components(ExternalAccess=observe)
R1 = foundation.electrical.elements.resistor(R={(1*1000),'Ohm'});
C1 = foundation.electrical.elements.capacitor(c=C_CGD1,r=capacitorSeriesResistance,g={0,'1/Ohm'},vc.priority=priority.none);
end
equations
C_CGD1 == {(0.5*simscape.function.expm(value(node_2.v,'V'), expXl, expXh, aWarning)),'F'};
C1.c == C_CGD1;
end
connections
connect(R1.p,node_1);
connect(R1.n,node_2);
connect(C1.p,node_2);
connect(C1.n,*);
end
end
Hope it helps.

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!