So I am trying to create a PCB with 8 relays. Since all relays have the same driving circuit, instead of making 8 sets of symbols, I created a Hierarchical Sheet. I then thought I could simply duplicate the sheets like normal. But I also wanted unique names (Values) for the parts inside the sheets. I can go inside each of the duplicated sheets and manually change the values. But there are 8 of them and I wanted to automate that process.
So I used the variable field ${#} in the values of all fields I wanted unique names for, such as the following.
And it worked. Since it is a hierarchical sheet, I also wanted unique names for the sheet pins (hierarchical labels) also. So I did the same for the pin names.
And that also worked. Now, whenever I duplicate the sheet, a new name will be generated by KiCad automatically. But that’s when I also noticed the problem. Even though KiCad resolves the name/value fields with variable fields, it does not treat the resolved values as the names for the logical interconnections.
If I try to connect a hierarchical sheet pin to something on the Root sheet, KiCad simply fails to recognize the resolved names of the pins and fails to connect them together. You can see in below screenshot that I have highlighted the REL1_IN net. But if I go inside the sheet, I can see they are not connected.
Is this behavior the intended behavior? KiCad ignores all resolved names for any underlying logical operations but uses them only for the visual presentation on the screen? Is there a different way to achieve what I want?
PS: I also applied the variable field for sheet names, but KiCad threw me the “Duplicate Sheet Names” error and I had to manually rename all sheets
I just realized that I don’t need UNIQUE names for the hierarchical labels in order for them to work. The sheet is an abstraction itself and it maintains the behavior even if duplicated. So I removed the variable field from the hierarchical labels and the nets are now connected
But after importing the [now fixed] schematic to the PCB editor, the footprints have randomly picked values instead of their resolved values in the schematic
I’d personally call this a bug: if KiCad doesn’t support using page number references like ${#} across hierarchical sheets, it should fail in a more obvious way than this. Sometimes it seems to use the page number of the PCB, which correctly should be 1. Sometimes it seems to pick the most recent open subsheet’s value? Not sure. Regardless, please report this as a bug to Gitlab. The easiest way to do so is to open the About KiCad page and select “Report Bug”. If you can, uploading the entire project (or a subset that shows this behavior) is very useful.
That being said, I think I have a solution for you in this case. If you press E to edit the sheet properties, you can assign additional variables like “SheetVal” for instance
Inside the sub sheets (or “leaves”) you can then assign the component Value to “${SheetVal}”. The components should automatically pick up the variable and show each sheet instance’s unique variables.
Yeah, if this doesn’t work, please file a bug report. And attach an example schematic if you can. I fixed a couple of sheet variable resolution issues in 7.99, I’m not if any of these improvements will come to 7.0.x though.
@mikebwilliams I just fixed a couple more and pushed them (and some of your fixes) back to 7.0.3. (Don’t know if they included this case or not, though.)
On the above. I noticed that when using sheet variables to give specific values to components, the substitution works fine while opening sheets in eeschema, however, when using the bulkedit functionality or exporting the BOM, the fields are not substituted and just show the variable name. @mikebwilliams Has the above been fixed with the mentioned fixes? If not I will open a bug report on gitlab.
The bulk editing in the symbol fields table should show the variable, not the value. BOM exporting should export the resolved variable value, so if it’s not, please file a bug report.
Wow, this thread got some attention while I was away!
Yeah! Using sheet-specific variables from Sheet Properties is a nice trick. It did not occur to me at that time. But I was able to solve the problem with hierarchical labels. Though, the problem of KiCad failing to use resolved variables remains active.
I just created a new sample project to see if the sheet-specific variables as suggested by @scandey, get resolved properly when importing a schematic to PCB, and it worked. The KiCad version is 7.0.5.
The variable ID is used to provide a unique sequence number to each subsheet and I can use the variable inside the sheet to generate unique names for the nets and part names.