How to implement the initial conditions SPICE command (.ic) into a Simscape component block (.ssc) file

10 views (last 30 days)
I converted the unencrypted PSPICE model for the TI (Texas Instruments) part UC1843A to a simscape block using the "subcircuit2ssc" function. Eventhough the conversion was successful, the generated .ssc file (simscape file) included the following comments:
% Users should manually implement the following SPICE commands in order to
% achieve a complete implementation:
% C_U1_C1: 0
% C_U1_C1: tc 0
% C_U2_C1: 0
% C_U2_C1: tc 0
% R_U1_R1: tc 0 0
% R_U2_R2: tc 0 0
% R_U2_R3: tc 0 0
% R_U4_R1: tc 0 0
% R_U4_R2: tc 0 0
% srlatchrhp_basic_gen: .ic value(qint.v,'V') {vss}
From the documentation of the "subcircuit2ssc" function I noticed that not all the SPICE commands are supported, and the documentation points out that the user should add some commands manually, which are the ones shown in the comments of the .ssc file. However, the documentation says nothing about how to add those unsoported commands, as for example the nodes initial conditions. The only thing I found was the following statement from the "Converting a SPICE Netlist to Simscape Blocks" article.
"The conversion assistant does not automatically convert initial conditions specified using the .IC statement. However, you can specify initial conditions for capacitors and inductors using the syntax IC=<value>. Also, you can manually convert any .IC statements from the generated Simscape component files."
Where on the generated .ssc file should that syntax go? I tried to add it in several places and matlab returned errors saying "function IC not supported". I would like to see a specific example of how to add those unsupported commands.
I believe those commands have to be added as the generated simscape block is not working properly. I tried to run a simulation with this simscape block using Simscape Electrical and I got a convergence error. I think the error is related to that initial condition that the function "subcircuit2ssc" could not add. A screenshot of the error is attached.
The PSPICE model I converted in text format is also attached. As this model has several subcircuits, matlab generated several simscape blocks, but the only ones with unsupported commands were the follwing:
component UC1843A_SP_TRANS
% UC1843A_SP_TRANS
% Component automatically generated from a SPICE netlist for subcircuit UC1843A_SP_TRANS.
% MATLAB version: 9.6.
% Simscape Electrical version: 7.1.
% Simscape code generated on: 10-Feb-2021 17:02:22
%
% Users should manually implement the following SPICE commands in order to
% achieve a complete implementation:
% C_U1_C1: 0
% C_U1_C1: tc 0
% C_U2_C1: 0
% C_U2_C1: tc 0
% R_U1_R1: tc 0 0
% R_U2_R2: tc 0 0
% R_U2_R3: tc 0 0
I
% R_U4_R1: tc 0 0
% R_U4_R2: tc 0 0
% srlatchrhp_basic_gen: .ic value(qint.v,'V') {vss}
nodes
comp = foundation.electrical.electrical; % comp
isense = foundation.electrical.electrical; % isense
vfb = foundation.electrical.electrical; % vfb
ground = foundation.electrical.electrical; % ground
output_1 = foundation.electrical.electrical; % output_1
pwr_gnd = foundation.electrical.electrical; % pwr_gnd
vref = foundation.electrical.electrical; % vref
rt_ct = foundation.electrical.electrical; % rt_ct
vc = foundation.electrical.electrical; % vc
vcc = foundation.electrical.electrical; % vcc
nc_0 = foundation.electrical.electrical; % nc_0
nc_1 = foundation.electrical.electrical; % nc_1
nc_2 = foundation.electrical.electrical; % nc_2
nc_3 = foundation.electrical.electrical; % nc_3
nc_4 = foundation.electrical.electrical; % nc_4
nc_5 = foundation.electrical.electrical; % nc_5
nc_6 = foundation.electrical.electrical; % nc_6
nc_7 = foundation.electrical.electrical; % nc_7
nc_8 = foundation.electrical.electrical; % nc_8
nc_9 = foundation.electrical.electrical; % nc_9
end
nodes(Access=protected, ExternalAccess=none)
u1_n16714588 = foundation.electrical.electrical;
u1_n00165 = foundation.electrical.electrical;
u2_n16728372 = foundation.electrical.electrical;
u2_rc_chg = foundation.electrical.electrical;
u2_n00256 = foundation.electrical.electrical;
u2_n16715325 = foundation.electrical.electrical;
u2_clk_on_ltch = foundation.electrical.electrical;
u2_n00308 = foundation.electrical.electrical;
clk = foundation.electrical.electrical;
n16716082 = foundation.electrical.electrical;
u2_n16727532 = foundation.electrical.electrical;
u3_n00322 = foundation.electrical.electrical;
u3_n00432 = foundation.electrical.electrical;
vcc_ok = foundation.electrical.electrical;
ref_ea = foundation.electrical.electrical;
u4_n00048 = foundation.electrical.electrical;
u4_n16712666 = foundation.electrical.electrical;
u4_n16713373 = foundation.electrical.electrical;
u4_n00188 = foundation.electrical.electrical;
u4_pwm = foundation.electrical.electrical;
n16714102 = foundation.electrical.electrical;
u4_n16723990 = foundation.electrical.electrical;
u4_n00052 = foundation.electrical.electrical;
end
variables
E_U1_E1 = {value={0,'A'},priority=priority.none};
E_U3_ABM1 = {value={0,'A'},priority=priority.none};
E_U3_E1 = {value={0,'A'},priority=priority.none};
E_U4_ABM3 = {value={0,'A'},priority=priority.none};
end
components(ExternalAccess=observe)
D_U1_D64 = ee.additional.spice_semiconductors.spice_diode(AREA={1,'m^2'},SCALE={1,'1'},IS={1e-15,'A/m^2'}, ...
RS={0.005,'Ohm*m^2'},N={0.001,'1'},C_param={2,'1'},CJO={0,'F/m^2'},VJ={1,'V'},M={0.5,'1'},FC={0.5,'1'}, ...
TT={1e-11,'s'},RevBrk={2,'1'},BV={Inf,'V'},IBV={1e-10,'A/m^2'},XTI={3,'1'},EG={1.11,'eV'});
V_U1_V2 = ee.sources.voltage_source(dc_voltage={10,'V'});
R_U1_R1 = ee.passive.instrumented_resistor(R={(10*1000),'Ohm'});
C_U1_C1 = foundation.electrical.elements.capacitor(c={(53.07*1e-09),'F'},r={0,'Ohm'},g={0,'1/Ohm'},vc.priority=priority.none);
D_U1_D65 = ee.additional.spice_semiconductors.spice_diode(AREA={1,'m^2'},SCALE={1,'1'},IS={1e-15,'A/m^2'}, ...
RS={0.005,'Ohm*m^2'},N={0.001,'1'},C_param={2,'1'},CJO={0,'F/m^2'},VJ={1,'V'},M={0.5,'1'},FC={0.5,'1'}, ...
TT={1e-11,'s'},RevBrk={2,'1'},BV={Inf,'V'},IBV={1e-10,'A/m^2'},XTI={3,'1'},EG={1.11,'eV'});
R_U2_R3 = ee.passive.instrumented_resistor(R={10,'Ohm'});
V_U2_V2 = ee.sources.voltage_source(dc_voltage={2.16,'V'});
D_U2_D64 = ee.additional.spice_semiconductors.spice_diode(AREA={1,'m^2'},SCALE={1,'1'},IS={1e-15,'A/m^2'}, ...
RS={0.005,'Ohm*m^2'},N={0.001,'1'},C_param={2,'1'},CJO={0,'F/m^2'},VJ={1,'V'},M={0.5,'1'},FC={0.5,'1'}, ...
TT={1e-11,'s'},RevBrk={2,'1'},BV={Inf,'V'},IBV={1e-10,'A/m^2'},XTI={3,'1'},EG={1.11,'eV'});
C_U2_C1 = foundation.electrical.elements.capacitor(c={(1.443*1e-09),'F'},r={0,'Ohm'},g={0,'1/Ohm'},vc.priority=priority.none);
R_U2_R2 = ee.passive.instrumented_resistor(R={35,'Ohm'});
X_U2_S1 = UC1843_PWMController.oscillator_u2_s1();
X_U2_U2 = UC1843_PWMController.one_shot(t=20);
X_U2_U7 = UC1843_PWMController.srlatchrhp_basic_gen(vdd=1,vss=0,vthresh=0.5);
X_U2_U1 = UC1843_PWMController.comp_basic_gen(vdd=1,vss=0,vthresh=0.5);
V_U2_V4 = ee.sources.voltage_source(dc_voltage={(30*0.001),'V'});
X_U2_U4 = UC1843_PWMController.comp_basic_gen(vdd=1,vss=0,vthresh=0.5);
X_U3_U1 = UC1843_PWMController.comphys_basic_gen(vdd=1,vss=0,vthresh=0.5);
V_U3_V2 = ee.sources.voltage_source(dc_voltage={8.5,'V'});
V_U3_V3 = ee.sources.voltage_source(dc_voltage={0.6,'V'});
D_U4_D64 = ee.additional.spice_semiconductors.spice_diode(AREA={1,'m^2'},SCALE={1,'1'},IS={1e-15,'A/m^2'}, ...
RS={0.005,'Ohm*m^2'},N={0.001,'1'},C_param={2,'1'},CJO={0,'F/m^2'},VJ={1,'V'},M={0.5,'1'},FC={0.5,'1'}, ...
TT={1e-11,'s'},RevBrk={2,'1'},BV={Inf,'V'},IBV={1e-10,'A/m^2'},XTI={3,'1'},EG={1.11,'eV'});
X_U4_U4 = UC1843_PWMController.srlatchrhp_basic_gen(vdd=1,vss=0,vthresh=0.5);
X_U4_U3 = UC1843_PWMController.inv_basic_gen(vdd=1,vss=0,vthresh=0.5);
X_U4_S1 = UC1843_PWMController.pwm_u4_s1();
R_U4_R1 = ee.passive.instrumented_resistor(R={(23.6*1000),'Ohm'});
X_U4_S2 = UC1843_PWMController.pwm_u4_s2();
R_U4_R2 = ee.passive.instrumented_resistor(R={(11.8*1000),'Ohm'});
V_U4_V2 = ee.sources.voltage_source(dc_voltage={1,'V'});
V_U4_V3 = ee.sources.voltage_source(dc_voltage={1.11,'V'});
X_U4_U5 = UC1843_PWMController.comp_basic_gen(vdd=1,vss=0,vthresh=0.5);
end
connections
connect(D_U1_D64.p,comp);
connect(D_U1_D64.n,u1_n16714588);
connect(V_U1_V2.p,u1_n16714588);
connect(V_U1_V2.n,ground);
connect(R_U1_R1.p,u1_n00165);
connect(R_U1_R1.n,comp);
connect(C_U1_C1.p,comp);
connect(C_U1_C1.n,ground);
connect(D_U1_D65.p,ground);
connect(D_U1_D65.n,comp);
connect(R_U2_R3.p,u2_n16728372);
connect(R_U2_R3.n,u2_rc_chg);
connect(V_U2_V2.p,u2_n00256);
connect(V_U2_V2.n,*);
connect(D_U2_D64.p,u2_n16728372);
connect(D_U2_D64.n,u2_rc_chg);
connect(C_U2_C1.p,u2_rc_chg);
connect(C_U2_C1.n,ground);
connect(R_U2_R2.p,rt_ct);
connect(R_U2_R2.n,u2_n16715325);
connect(X_U2_S1.node_1,u2_clk_on_ltch);
connect(X_U2_S1.node_2,ground);
connect(X_U2_S1.node_3,u2_n16715325);
connect(X_U2_S1.node_4,ground);
connect(X_U2_U2.in_1,u2_n00308);
connect(X_U2_U2.out,clk);
connect(X_U2_U7.s,clk);
connect(X_U2_U7.r,u2_rc_chg);
connect(X_U2_U7.q,u2_clk_on_ltch);
connect(X_U2_U7.qb,n16716082);
connect(X_U2_U1.inp,rt_ct);
connect(X_U2_U1.inm,u2_n00256);
connect(X_U2_U1.y,u2_n00308);
connect(V_U2_V4.p,u2_n16727532);
connect(V_U2_V4.n,*);
connect(X_U2_U4.inp,u2_n16727532);
connect(X_U2_U4.inm,rt_ct);
connect(X_U2_U4.y,u2_n16728372);
connect(X_U3_U1.inp,vcc);
connect(X_U3_U1.inm,u3_n00322);
connect(X_U3_U1.hys,u3_n00432);
connect(X_U3_U1.out,vcc_ok);
connect(V_U3_V2.p,u3_n00322);
connect(V_U3_V2.n,ground);
connect(V_U3_V3.p,u3_n00432);
connect(V_U3_V3.n,ground);
connect(D_U4_D64.p,u4_n00048);
connect(D_U4_D64.n,u4_n16712666);
connect(X_U4_U4.s,u4_n16713373);
connect(X_U4_U4.r,u4_n00188);
connect(X_U4_U4.q,u4_pwm);
connect(X_U4_U4.qb,n16714102);
connect(X_U4_U3.a,u4_pwm);
connect(X_U4_U3.y,u4_n16723990);
connect(X_U4_S1.node_1,u4_pwm);
connect(X_U4_S1.node_2,ground);
connect(X_U4_S1.node_3,vc);
connect(X_U4_S1.node_4,output_1);
connect(R_U4_R1.p,u4_n00052);
connect(R_U4_R1.n,u4_n00048);
connect(X_U4_S2.node_1,u4_n16723990);
connect(X_U4_S2.node_2,ground);
connect(X_U4_S2.node_3,output_1);
connect(X_U4_S2.node_4,pwr_gnd);
connect(R_U4_R2.p,u4_n00048);
connect(R_U4_R2.n,ground);
connect(V_U4_V2.p,u4_n16712666);
connect(V_U4_V2.n,ground);
connect(V_U4_V3.p,comp);
connect(V_U4_V3.n,u4_n00052);
connect(X_U4_U5.inp,isense);
connect(X_U4_U5.inm,u4_n00048);
connect(X_U4_U5.y,u4_n00188);
end
branches
E_U1_E1: u1_n00165.i -> ground.i;
E_U3_ABM1: vref.i -> *;
E_U3_E1: ref_ea.i -> ground.i;
E_U4_ABM3: u4_n16713373.i -> *;
end
equations
value(u1_n00165.v-ground.v,'V') == (31622.77)*value(ref_ea.v-vfb.v,'V');
value(vref.v,'V') == (if value(vcc_ok.v,'V')>0.5, 5 else 0 end) ;
value(ref_ea.v-ground.v,'V') == (0.5)*value(vref.v-ground.v,'V');
value(u4_n16713373.v,'V') == (if value(vcc_ok.v,'V')>0.5, value(clk.v,'V') else 0 end) ;
end
end
component srlatchrhp_basic_gen
% srlatchrhp_basic_gen
% Component automatically generated from a SPICE netlist for subcircuit SRLATCHRHP_BASIC_GEN.
% MATLAB version: 9.6.
% Simscape Electrical version: 7.1.
% Simscape code generated on: 10-Feb-2021 17:02:24
%
% Users should manually implement the following SPICE commands in order to
% achieve a complete implementation:
% srlatchrhp_basic_gen: .ic value(qint.v,'V') {vss}
nodes
s = foundation.electrical.electrical; % s
r = foundation.electrical.electrical; % r
q = foundation.electrical.electrical; % q
qb = foundation.electrical.electrical; % qb
end
nodes(Access=protected, ExternalAccess=none)
qint = foundation.electrical.electrical;
my5 = foundation.electrical.electrical;
myvss = foundation.electrical.electrical;
qqq = foundation.electrical.electrical;
qqqd1 = foundation.electrical.electrical;
qbr = foundation.electrical.electrical;
end
parameters
vdd = {1, '1'};
vss = {0, '1'};
vthresh = {0.5, '1'};
end
variables
GQ = {value={0,'A'},priority=priority.none};
EQ = {value={0,'A'},priority=priority.none};
EQB = {value={0,'A'},priority=priority.none};
end
components(ExternalAccess=observe)
CQINT = foundation.electrical.elements.capacitor(c={(1*1e-09),'F'},r={0,'Ohm'},g={0,'1/Ohm'},vc.priority=priority.none);
RQINT = ee.passive.instrumented_resistor(R={(5000*1000000),'Ohm'});
D_D10 = ee.additional.spice_semiconductors.spice_diode(AREA={1,'m^2'},SCALE={1,'1'},IS={1e-15,'A/m^2'}, ...
RS={0.05,'Ohm*m^2'},N={0.01,'1'},C_param={2,'1'},CJO={0,'F/m^2'},VJ={1,'V'},M={0.5,'1'},FC={0.5,'1'}, ...
TT={1e-11,'s'},RevBrk={2,'1'},BV={Inf,'V'},IBV={1e-10,'A/m^2'},XTI={3,'1'},EG={1.11,'eV'});
V1 = ee.sources.voltage_source(dc_voltage={vdd,'V'});
D_D11 = ee.additional.spice_semiconductors.spice_diode(AREA={1,'m^2'},SCALE={1,'1'},IS={1e-15,'A/m^2'}, ...
RS={0.05,'Ohm*m^2'},N={0.01,'1'},C_param={2,'1'},CJO={0,'F/m^2'},VJ={1,'V'},M={0.5,'1'},FC={0.5,'1'}, ...
TT={1e-11,'s'},RevBrk={2,'1'},BV={Inf,'V'},IBV={1e-10,'A/m^2'},XTI={3,'1'},EG={1.11,'eV'});
V2 = ee.sources.voltage_source(dc_voltage={vss,'V'});
X3 = UC1843_PWMController.buf_basic_gen(vdd=vdd,vss=vss,vthresh=vthresh);
RQQ = ee.passive.instrumented_resistor(R={1,'Ohm'});
RQB = ee.passive.instrumented_resistor(R={1,'Ohm'});
CDUMMY1 = foundation.electrical.elements.capacitor(c={(1*1e-09),'F'},r={0,'Ohm'},g={0,'1/Ohm'},vc.priority=priority.none);
CDUMMY2 = foundation.electrical.elements.capacitor(c={(1*1e-09),'F'},r={0,'Ohm'},g={0,'1/Ohm'},vc.priority=priority.none);
end
connections
connect(CQINT.p,qint);
connect(CQINT.n,*);
connect(RQINT.p,qint);
connect(RQINT.n,*);
connect(D_D10.p,qint);
connect(D_D10.n,my5);
connect(V1.p,my5);
connect(V1.n,*);
connect(D_D11.p,myvss);
connect(D_D11.n,qint);
connect(V2.p,myvss);
connect(V2.n,*);
connect(X3.a,qqq);
connect(X3.y,qqqd1);
connect(RQQ.p,qqqd1);
connect(RQQ.n,q);
connect(RQB.p,qbr);
connect(RQB.n,qb);
connect(CDUMMY1.p,q);
connect(CDUMMY1.n,*);
connect(CDUMMY2.p,qb);
connect(CDUMMY2.n,*);
end
branches
GQ: * -> qint.i;
EQ: qqq.i -> *;
EQB: qbr.i -> *;
end
equations
value(GQ,'A') == (if value(r.v,'V') > (vthresh), -5 else (if value(s.v,'V')>(vthresh), 5 else 0 end) ...
end);
value(qqq.v,'V') == (1)*value(qint.v,'V');
value(qbr.v,'V') == (if value(q.v,'V') > (vthresh), (vss) else (vdd) end);
end
end

Answers (2)

Sarvani Panguluri
Sarvani Panguluri on 26 Feb 2021
Hi,
This part of documentation - Make Manual Changes to a Converted Simscape Component File explains where the intial conditions have to be placed. Hope this helps!
  1 Comment
Andrea Gonzalez
Andrea Gonzalez on 26 Feb 2021
Hi! Thank you for your reply.
I read that document, but the example it shows is specifically for a parameter included in the SPICE resistor model (temperature parameters). I tried something similar for the capacitor model trying to add the initial conditions as:
CQINT = foundation.electrical.elements.capacitor(IC = 0,c={(1*1e-09),'F'},r={0,'Ohm'},g={0,'1/Ohm'},vc.priority=priority.none);
However, adding the "IC=0" trows an error "Invalid IC command". This is what I would like to know. How to add that specific command for capacitors or nodes.
Thank you,

Sign in to comment.


David John
David John on 3 Aug 2021
The ".ic" statement in SPICE is not really part of the subcircuit model; rather it is part of the transient simulation.
In any case, in order to specify an initial condition, you need to define a variable that is equal to the thing you want to set a condition for, and then define that variable as having priority.high.
For example, in your case, you have a node called qint, and you want to set qint.v to vss in srlatchrhp_basic_gen, where vss is a parameter.
I would try something like the following:
1) Create a private variables section with a variable called something like qintv:
variables(Access=private)
qintv = {value=vss, priority=priority.high};
end
2) Add an equation to the equations section that sets that variable to the voltage on the node that you're trying to set:
equations
qintv == qint.v;
end
The other way to do it would be to expose the variable on the Variables tab, but this is a bit more complicated since you're trying to set a variable on a subcomponent rather than on the top-level component.

Community Treasure Hunt

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

Start Hunting!