Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Flattening hierarchy within spice .subckt

Status
Not open for further replies.

JohnCorn

Newbie level 1
Joined
Feb 15, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
28
Hi everyone,

I'd like to find a command line tool to flatten the hierarchy within a given subckt in a spice netlist. As a toy example, I might start with

.subckt attenuator in out comm
r1 in int 16.67 rmod1
r2 int out 16.67 rmod1
r3 int comm 66.67 rmod1
.model rmod1 r tc1=0.001 tc2=0.0001
.ends
.subckt bigatten in out
xnested1 in int 0 attenuator
xnested2 int out 0 attenuator
.ends
.subckt myfoo int1 0 1 2 3 4 100
v1 int1 0 1
rin int1 1 50
xsub1 1 2 100 attenuator
xsub2 2 3 100 attenuator
xsub3 3 4 bigatten
rx1 100 0 1m
rout 4 0 50
.ends

and I say something like "flatten dut.spi myfoo" and it spits out (my own comments added for clarity)

.subckt attenuator in out comm
r1 in int 16.67 rmod1
r2 int out 16.67 rmod1
r3 int comm 66.67 rmod1
.model rmod1 r tc1=0.001 tc2=0.0001
.ends
.subckt bigatten in out
xnested1 in int 0 attenuator
xnested2 int out 0 attenuator
.ends
.subckt myfoo int1 0 1 2 3 4 100
v1 int1 0 1
rin int1 1 50
*This is the expansion of subcircuit instance xsub1 (attenuator):
r1:xsub1 1 int:xsub1 16.67 rmod1:xsub1
r2:xsub1 int:xsub1 2 16.67 rmod1:xsub1
r3:xsub1 int:xsub1 100 66.67 rmod1:xsub1
.model rmod1:xsub1 r tc1=0.001 tc2=0.0001
*This is the expansion of subcircuit instance xsub2 (attenuator):
r1:xsub2 2 int:xsub2 16.67 rmod1:xsub2
r2:xsub2 int:xsub2 3 16.67 rmod1:xsub2
r3:xsub2 int:xsub2 100 66.67 rmod1:xsub2
.model rmod1:xsub2 r tc1=0.001 tc2=0.0001
*And now the expansion of subcircuit instance xsub3 (bigatten). First the expansion of nested subcircuit xnested1 in xsub3 (attenuator):
r1:xnested1:xsub3 3 int:xnested1:xsub3 16.67 rmod1:xnested1:xsub3
r2:xnested1:xsub3 int:xnested1:xsub3 int:xsub3 16.67 rmod1:xnested1:xsub3
r3:xnested1:xsub3 int:xnested1:xsub3 0 66.67 rmod1:xnested1:xsub3
.model rmod1:xnested1:xsub3 r tc1=0.001 tc2=0.0001
*The expansion of nested subcircuit xnested2 in xsub3 (attenuator):
r1:xnested2:xsub3 int:xsub3 int:xnested2:xsub3 16.67 rmod1:xnested2:xsub3
r2:xnested2:xsub3 int:xnested2:xsub3 4 16.67 rmod1:xnested2:xsub3
r3:xnested2:xsub3 int:xnested2:xsub3 0 66.67 rmod1:xnested2:xsub3
.model rmod1:xnested2:xsub3 r tc1=0.001 tc2=0.0001
*And finally the last two resistances from the original netlist.
rx1 100 0 1m
rout 4 0 50
.ends

If it hurts your eyes to look at that, I've recursively replaced subckt instantiations (lines beginning with X) inside myfoo with the bodies of corresponding subckt declarations, but with the parameter pin names replaced and internals renamed hierarchically to avoid namespace collisions/shorts.

I've been trying to roll my own, but it's a thousand lines of regular expression gymnastics and I'm getting very hard-to-find bugs on production-sized netlists.

Thanks!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top