KiCad PCB EDA Suite
Loading...
Searching...
No Matches
common/transline_calculations/twistedpair.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Michael Margraf <[email protected]>
3 * Modifications 2011 for Kicad: Jean-Pierre Charras
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this package. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
23
24namespace TC = TRANSLINE_CALCULATIONS;
26
27
58{
60
61 const double twist = GetParameter( TCP::TWISTEDPAIR_TWIST );
62 const double epsrEnv = GetParameter( TCP::TWISTEDPAIR_EPSILONR_ENV );
63 const double Din = GetParameter( TCP::PHYS_DIAM_IN );
64 const double Dout = GetParameter( TCP::PHYS_DIAM_OUT );
65 const double freq = GetParameter( TCP::FREQUENCY );
66 const double len = GetParameter( TCP::PHYS_LEN );
67 const double epsr = GetDispersedEpsilonR( freq );
68 const double tand = GetDispersedTanDelta( freq );
69
71
72 // Lefferson defines theta in degrees for the 0.0007 * theta^2 term. The KiCad
73 // legacy implementation used radians, which made the twist contribution about
74 // 3300x too small. Convert to degrees before squaring.
75 const double theta_rad = std::atan( twist * M_PI * Dout );
76 const double theta_deg = theta_rad * ( 180.0 / M_PI );
77
78 const double epsEff = epsrEnv + ( 0.25 + 0.0007 * theta_deg * theta_deg ) * ( epsr - epsrEnv );
80
81 const double z0 = ( TC::ZF0 / M_PI / std::sqrt( epsEff ) ) * std::acosh( Dout / Din );
82 SetParameter( TCP::Z0, z0 );
83
84 const double skinDepth = GetParameter( TCP::SKIN_DEPTH );
85 const double sigma = GetParameter( TCP::SIGMA );
86
87 // Thin-wire conductor and dielectric attenuation. Lefferson 1971 does not cover loss;
88 // these are the standard parallel-wire forms summarised in Wadell, "Transmission Line
89 // Design Handbook", Artech House 1991, §3.2.3 (Twisted Pair).
90 SetParameter( TCP::LOSS_CONDUCTOR, ( TC::LOG2DB / 2.0 ) * len / skinDepth / sigma / M_PI / z0
91 / ( Din - skinDepth ) );
92
94 TC::LOG2DB * len * M_PI / TC::C0 * freq * std::sqrt( epsEff ) * tand );
95
96 SetParameter( TCP::ANG_L, 2.0 * M_PI * len * std::sqrt( epsEff ) * freq / TC::C0 );
97
99}
100
101
103{
104 // 1-D Newton on whichever diameter the UI flagged as the unknown. MinimiseZ0Error1D
105 // runs Analyse repeatedly until |Z0 - Z0_target| is below the base-class tolerance or
106 // the iteration cap is reached, then recomputes PHYS_LEN from ANG_L to keep the
107 // UI round-trip consistent with the legacy TRANSLINE::minimizeZ0Error1D contract.
108 const TCP target =
110
111 return MinimiseZ0Error1D( target, TCP::Z0, true );
112}
113
114
116{
121
122 const double Z0 = GetParameter( TCP::Z0 );
123 const double angL = GetParameter( TCP::ANG_L );
124 const double len = GetParameter( TCP::PHYS_LEN );
125 const double Din = GetParameter( TCP::PHYS_DIAM_IN );
126 const double Dout = GetParameter( TCP::PHYS_DIAM_OUT );
127
128 const bool Z0_invalid = !std::isfinite( Z0 ) || Z0 < 0;
129 const bool angL_invalid = !std::isfinite( angL ) || angL < 0;
130 const bool len_invalid = !std::isfinite( len ) || len < 0;
131 const bool Din_invalid = !std::isfinite( Din ) || Din <= 0.0;
132 const bool Dout_invalid = !std::isfinite( Dout ) || Dout <= 0.0;
133 const bool geometry_invalid = Din > Dout;
134
139 ( Din_invalid || geometry_invalid ) ? TRANSLINE_STATUS::WARNING : TRANSLINE_STATUS::OK );
141 ( Dout_invalid || geometry_invalid ) ? TRANSLINE_STATUS::WARNING : TRANSLINE_STATUS::OK );
142}
143
144
146{
151
152 const double Z0 = GetParameter( TCP::Z0 );
153 const double angL = GetParameter( TCP::ANG_L );
154 const double len = GetParameter( TCP::PHYS_LEN );
155 const double Din = GetParameter( TCP::PHYS_DIAM_IN );
156 const double Dout = GetParameter( TCP::PHYS_DIAM_OUT );
157
158 const bool Z0_invalid = !std::isfinite( Z0 ) || Z0 < 0;
159 const bool angL_invalid = !std::isfinite( angL ) || angL < 0;
160 const bool len_invalid = !std::isfinite( len ) || len < 0;
161 const bool Din_invalid = !std::isfinite( Din ) || Din <= 0.0;
162 const bool Dout_invalid = !std::isfinite( Dout ) || Dout <= 0.0;
163 const bool geometry_invalid = Din > Dout;
164
170 : ( Dout_invalid ? TRANSLINE_STATUS::WARNING : TRANSLINE_STATUS::OK );
171
178 : Din_status );
182 : Dout_status );
183}
double GetDispersedEpsilonR(double aF) const
Dispersed permittivity at aF. Returns raw EPSILONR when the model is inactive.
TRANSLINE_PARAMETERS m_synthesizeTarget
Which geometry parameter is the unknown during synthesis (set by the UI)
double GetDispersedTanDelta(double aF) const
Dispersed loss tangent at aF. Returns raw TAND when the model is inactive.
double GetParameter(const TRANSLINE_PARAMETERS aParam) const
Gets the given calculation property.
void SetParameter(const TRANSLINE_PARAMETERS aParam, const double aValue)
Sets the given calculation property.
void SetSynthesisResult(TRANSLINE_PARAMETERS aParam, const double aValue, const TRANSLINE_STATUS aStatus=TRANSLINE_STATUS::OK)
Sets a synthesis result.
void UpdateDielectricModel()
Refit the Djordjevic-Sarkar model from the current parameter map.
double SkinDepth() const
Calculate skin depth.
bool MinimiseZ0Error1D(TRANSLINE_PARAMETERS aOptimise, TRANSLINE_PARAMETERS aMeasure, bool aRecalculateLength=false)
minimizeZ0Error1D
void SetAnalysisResult(TRANSLINE_PARAMETERS aParam, const double aValue, const TRANSLINE_STATUS aStatus=TRANSLINE_STATUS::OK)
Sets an analysis result.
static double UnitPropagationDelay(double aEpsilonEff)
Calculates the unit propagation delay (ps/cm) for the given effective permittivity.
bool Synthesize(SYNTHESIZE_OPTS aOpts) override
Synthesize Din or Dout to hit the target Z0. Length is recomputed from ANG_L.
void Analyse() override
Analyse pair geometry to output Z0, electrical length, losses, skin depth, εeff.
void SetSynthesisResults() override
Sets the output values and status following synthesis.
void SetAnalysisResults() override
Sets the output values and status following analysis.
TRANSLINE_PARAMETERS TCP
#define M_PI
SYNTHESIZE_OPTS
Options for specifying synthesis inputs, targets, or strategies.
TRANSLINE_STATUS
Parameter status values.
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.