# String replacement math, PCB stack and design rules

Things I believe would make life as a KiCad layouter easier

The following is just a list of thoughts that I have been accumulating over the past time. I think it would be great to see this being implemented within the near future, but I am no developer (and frankly I believe the dev’s have more important stuff to do for the scope of v6).

…'nuf chatter, lets break the simple stuff first:
1
Add support for nested substitutions of string replacements. For example if one=`two` and two=`okay` then `\${\${one}}` should return `okay`.
Now why would I want this? Well, we’ll get to that later…

2
Add support for PCB Calculations within string replacements - maybe something like these pseudo code examples:

``````\${CALC_STRIPLINE_W(Layer=In1.Cu, Zd=50)} //return calculated track width for 50 Ohm on layer In1.Cu
\${CALC_COUPLEDMICROSTRIPLINE_W(Layer=F.Cu, Frequency=100, Zd=90)} //return differential pair track width for 90 Ohm at 100MHz
\${CALC_COUPLEDMICROSTRIPLINE_S(Layer=F.Cu, Frequency=100, Zd=90)} //return differential pair track spacing
``````

Most of the values needed for these calculations are already in the stack up, the remaining few could be estimated or declared another way.

3
Now, with the above two suggestions in mind please consider this design rule pseudo example:

``````(rule "single_ended_50_ohm"
(condition "A.NetClass == 'SINGLE_ENDED_50R'")
(constraint track_width (opt \${CALC_STRIPLINE_W(Layer=\${LAYER}, Zd=50)}))
)
``````

With this we can expand design rules to give us the correct impedance for single ended tracks, no matter the board stack up or which layer we route it on.

Of course this idea should then also be applied to differential pairs and other types of transmission lines.

4
Something that would also be nice:

• If from schematic/netlist we could assign per net current handling capability and/or max. resistance/voltage drop, then trace width could automatically be optimized depending on layer thickness and whether the trace is internal or external covered by solder mask.
• Furthermore if we can assign an expected voltage span per net then it opens up to some pretty sophisticated automatic clearance rules.

5
By the way, in my opinion the PCB Calculator also needs:

• to be expanded with a Coupled Stripline option
• and to support reverse calculation for differential pairs at least, eg. a text field to input Differential Impedance (Zd)

*) Some background info might be relevant:

.

What do you think?

2 Likes

Nice!
We are getting into higher level engineering assistance here, not just the mechanics of drawing a board layout.

1 Like

Thanks for your thoughts @hmk, this is exactly what I had in mind.

I just stumpled upon another use case for nested substitutions:
Consider the two resistors: R1 and R_{S}1 (subscript S)
This substitutes for the value: \${R1:VALUE}
But this doesn’t: \${R_{S}1:VALUE}

That one’s just a bug. (Fix on the way…)

2 Likes
1 Like