Composability of subcircuits
See original GitHub issueLet’s say that I have a subcircuit for the main part of a buck converter, and I’ve parameterized it to accept an arbitrary inductor, diode, etc:
def buck_converter(
nmos: Part,
diode: Part,
inductor: Part,
cap_input: Part,
cap_output: Part,
):
@subcircuit
def buck_impl(pwm: Net, v_in: Net, v_out: Net, gnd: Net):
buck_inner_net = Net('buck_inner')
nmos_inst = nmos.copy()
nmos_inst['gate'] = pwm
nmos_inst['drain'] = v_in
nmos_inst['source'] = buck_inner_net
inductor_inst = inductor.copy()
inductor_inst['+'] = buck_inner_net
inductor_inst['-'] = v_out
diode_inst = diode.copy()
diode_inst['-'] = buck_inner_net
diode_inst['+'] = gnd
cap_input_inst = cap_input.copy()
cap_input_inst['+'] = v_in
cap_input_inst['-'] = gnd
cap_output_inst = cap_output.copy()
cap_output_inst['+'] = v_in
cap_output_inst['-'] = gnd
return buck_impl
However, what if I want to replace the diode with synchronous rectification? What I’d like to be able to do is create another subcircuit that provides that functionality, and be able to pass it in as the diode
parameter. As long as it has the same pin names, that should work.
However, I can’t do that, as the Circuit interface is nothing like the Part interface, and I can’t create a part with multiple components.
It seems to me that idea of a Circuit isn’t a very nice abstraction. It serves as a bag of parts and nets, a duplicate of the data that is already stored in the part and net graph. Why can’t that bag of parts and nets be built up as it is needed?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top GitHub Comments
Hi @flaviut, I’m curious if you’ve made any progress with this, as I’m also very interested in this functionality/think it’s a great idea.
The Circuit object didn’t come along until the latter part of SKiDL development. It was kind of a grab-bag of pieces. Re-thinking it as a type of Part makes sense.
I’m concerned about your mention of “non-backwards compatible”. To me, that means there would be current features of SKiDL that would not be available in a future version that used your ideas. I can’t really see why that would be. Maybe you mean something else.
I think getting the composability feature you want can be done with some tweaking of the Circuit object in the current version of SKiDL. However, a refactoring may lead to simplification and clearing of some of SKiDL’s underbrush. To that end, maybe I could make a branch where you could flesh-out some of your ideas and see where it leads.