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; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
24
25
26namespace TC = TRANSLINE_CALCULATIONS;
28
29
60{
62
63 const double twist = GetParameter( TCP::TWISTEDPAIR_TWIST );
64 const double epsrEnv = GetParameter( TCP::TWISTEDPAIR_EPSILONR_ENV );
65 const double Din = GetParameter( TCP::PHYS_DIAM_IN );
66 const double Dout = GetParameter( TCP::PHYS_DIAM_OUT );
67 const double freq = GetParameter( TCP::FREQUENCY );
68 const double len = GetParameter( TCP::PHYS_LEN );
69 const double epsr = GetDispersedEpsilonR( freq );
70 const double tand = GetDispersedTanDelta( freq );
71
73
74 // Lefferson defines theta in degrees for the 0.0007 * theta^2 term. The KiCad
75 // legacy implementation used radians, which made the twist contribution about
76 // 3300x too small. Convert to degrees before squaring.
77 const double theta_rad = std::atan( twist * M_PI * Dout );
78 const double theta_deg = theta_rad * ( 180.0 / M_PI );
79
80 const double epsEff = epsrEnv + ( 0.25 + 0.0007 * theta_deg * theta_deg ) * ( epsr - epsrEnv );
82
83 const double z0 = ( TC::ZF0 / M_PI / std::sqrt( epsEff ) ) * std::acosh( Dout / Din );
84 SetParameter( TCP::Z0, z0 );
85
86 const double skinDepth = GetParameter( TCP::SKIN_DEPTH );
87 const double sigma = GetParameter( TCP::SIGMA );
88
89 // Thin-wire conductor and dielectric attenuation. Lefferson 1971 does not cover loss;
90 // these are the standard parallel-wire forms summarised in Wadell, "Transmission Line
91 // Design Handbook", Artech House 1991, §3.2.3 (Twisted Pair).
92 SetParameter( TCP::LOSS_CONDUCTOR, ( TC::LOG2DB / 2.0 ) * len / skinDepth / sigma / M_PI / z0
93 / ( Din - skinDepth ) );
94
96 TC::LOG2DB * len * M_PI / TC::C0 * freq * std::sqrt( epsEff ) * tand );
97
98 SetParameter( TCP::ANG_L, 2.0 * M_PI * len * std::sqrt( epsEff ) * freq / TC::C0 );
99
101}
102
103
105{
106 // 1-D Newton on whichever diameter the UI flagged as the unknown. MinimiseZ0Error1D
107 // runs Analyse repeatedly until |Z0 - Z0_target| is below the base-class tolerance or
108 // the iteration cap is reached, then recomputes PHYS_LEN from ANG_L to keep the
109 // UI round-trip consistent with the legacy TRANSLINE::minimizeZ0Error1D contract.
110 const TCP target =
112
113 return MinimiseZ0Error1D( target, TCP::Z0, true );
114}
115
116
118{
123
124 const double Z0 = GetParameter( TCP::Z0 );
125 const double angL = GetParameter( TCP::ANG_L );
126 const double len = GetParameter( TCP::PHYS_LEN );
127 const double Din = GetParameter( TCP::PHYS_DIAM_IN );
128 const double Dout = GetParameter( TCP::PHYS_DIAM_OUT );
129
130 const bool Z0_invalid = !std::isfinite( Z0 ) || Z0 < 0;
131 const bool angL_invalid = !std::isfinite( angL ) || angL < 0;
132 const bool len_invalid = !std::isfinite( len ) || len < 0;
133 const bool Din_invalid = !std::isfinite( Din ) || Din <= 0.0;
134 const bool Dout_invalid = !std::isfinite( Dout ) || Dout <= 0.0;
135 const bool geometry_invalid = Din > Dout;
136
141 ( Din_invalid || geometry_invalid ) ? TRANSLINE_STATUS::WARNING : TRANSLINE_STATUS::OK );
143 ( Dout_invalid || geometry_invalid ) ? TRANSLINE_STATUS::WARNING : TRANSLINE_STATUS::OK );
144}
145
146
148{
153
154 const double Z0 = GetParameter( TCP::Z0 );
155 const double angL = GetParameter( TCP::ANG_L );
156 const double len = GetParameter( TCP::PHYS_LEN );
157 const double Din = GetParameter( TCP::PHYS_DIAM_IN );
158 const double Dout = GetParameter( TCP::PHYS_DIAM_OUT );
159
160 const bool Z0_invalid = !std::isfinite( Z0 ) || Z0 < 0;
161 const bool angL_invalid = !std::isfinite( angL ) || angL < 0;
162 const bool len_invalid = !std::isfinite( len ) || len < 0;
163 const bool Din_invalid = !std::isfinite( Din ) || Din <= 0.0;
164 const bool Dout_invalid = !std::isfinite( Dout ) || Dout <= 0.0;
165 const bool geometry_invalid = Din > Dout;
166
172 : ( Dout_invalid ? TRANSLINE_STATUS::WARNING : TRANSLINE_STATUS::OK );
173
180 : Din_status );
184 : Dout_status );
185}
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.