Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define netnames based on external variables? #138

Open
Arrondissement5etDemi opened this issue Feb 19, 2025 · 3 comments
Open

Define netnames based on external variables? #138

Arrondissement5etDemi opened this issue Feb 19, 2025 · 3 comments

Comments

@Arrondissement5etDemi
Copy link

Hi!

I would like to have netname for pins that is a function of external variables, such as

for i = 1:10, 
    :(v_$i) = voltagesource(10), [+] == "vsrc_$i", [-] == gnd
end

Currently the code will show that i is undefined due to the QuoteNode nature of the pins.

Thanks a lot!!

@martinholters
Copy link
Member

This lacks a bit of context. Is that supposed to work in @circuit macro? That doesn't support for loops in the first place. And it's not meant for such advanced uses. You achieve what (i think) you want like so:

circ = Circuit()
for i = 1:10
    add!(circ, Symbol("v_$i"), voltagesource())
    connect!(circ, (Symbol("v_$i"), +), Symbol("vsrc_$i"))
    connect!(circ, (Symbol("v_$i"), -), Symbol("gnd"))
end

Also see the example at the very end of the documentation section on circuit desciption and note that you can create circ with the @circuit macro to populate it with the basic components and then still add to it programmatically.

Does this answer your question/solve your problem, or did I isunderstand?

@Arrondissement5etDemi
Copy link
Author

Hi, yes I meant a bit of a pseudocode by writing a for loop. I see that it must be defined outside of the macro. I need the pins to have names that depend on function outputs, so I think your code here will work! Will try this out and let you know if it solves my problem. Thanks!!

@Arrondissement5etDemi
Copy link
Author

It works. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants