File: twistedpair.cpp

package info (click to toggle)
kicad 9.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 770,320 kB
  • sloc: cpp: 961,692; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 227; javascript: 167; perl: 10
file content (196 lines) | stat: -rw-r--r-- 7,319 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * twistedpair.h - twisted pair class definition
 *
 * Copyright (C) 2011 Michael Margraf <michael.margraf@alumni.tu-berlin.de>
 * Modifications 2011 for Kicad: Jean-Pierre Charras
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this package; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include "twistedpair.h"
#include "units.h"

TWISTEDPAIR::TWISTEDPAIR() : TRANSLINE()
{
    m_Name = "TwistedPair";
    Init();
}


/**
 *  \f$ \theta = \arctan\left( T \cdot \pi \cdot D_{out} \right) \f$
 *
 * Where :
 * - \f$ \theta \f$ : pitch angle
 * - \f$ T \f$ : Number of twists per unit length
 * - \f$ D_{out} \f$ : Wire diameter with insulation
 *
 *  \f$ e_{eff} = e_{env} \cdot \left( 0.25 + 0.0007 \cdot \theta^2 \right)\cdot\left(e_r-e_{env}\right) \f$
 *
 * Where :
 * - \f$ e_{env} \f$ : relative dielectric constant of air ( or some other surronding material ),
 * - \f$ e_r \f$ : relative dielectric constant of the film insulation,
 * - \f$ e_{eff} \f$ : effective relative dielectric constant
 *
 * \f$ Z_0 = \frac{Z_\mathrm{VACUUM}}{\pi \cdot \sqrt{e_{eff}}}\cosh^{-1}\left(\frac{D_{out}}{D_{in}}\right) \f$
 *
 * - \f$ Z_0 \f$ : line impedance
 * - \f$ Z_\mathrm{VACUUM} \f$ : vacuum impedance
 * - \f$ D_{in} \f$ : Wire diameter without insulation
 *
 * Reference for above equations :
 *
 * [1] : P. Lefferson, ``Twisted Magnet Wire Transmission Line,''
 * IEEE Transactions on Parts, Hybrids, and Packaging, vol. PHP-7, no. 4, pp. 148-154, Dec. 1971.
 *
 * The following URL can be used as reference : http://qucs.sourceforge.net/tech/node93.html
 **/
void TWISTEDPAIR::calcAnalyze()
{

    double tw = atan( m_parameters[TWISTEDPAIR_TWIST_PRM] * M_PI
                      * m_parameters[PHYS_DIAM_OUT_PRM] ); // pitch angle

    m_parameters[EPSILON_EFF_PRM] =
            m_parameters[TWISTEDPAIR_EPSILONR_ENV_PRM]
            + ( 0.25 + 0.0007 * tw * tw )
                      * ( m_parameters[EPSILONR_PRM] - m_parameters[TWISTEDPAIR_EPSILONR_ENV_PRM] );

    m_parameters[Z0_PRM] =
            ZF0 / M_PI / sqrt( m_parameters[EPSILON_EFF_PRM] )
            * acosh( m_parameters[PHYS_DIAM_OUT_PRM] / m_parameters[PHYS_DIAM_IN_PRM] );

    m_parameters[LOSS_CONDUCTOR_PRM] =
            10.0 / log( 10.0 ) * m_parameters[PHYS_LEN_PRM] / m_parameters[SKIN_DEPTH_PRM]
            / m_parameters[SIGMA_PRM] / M_PI / m_parameters[Z0_PRM]
            / ( m_parameters[PHYS_DIAM_IN_PRM] - m_parameters[SKIN_DEPTH_PRM] );

    m_parameters[LOSS_DIELECTRIC_PRM] = 20.0 / log( 10.0 ) * m_parameters[PHYS_LEN_PRM] * M_PI / C0
                                        * m_parameters[FREQUENCY_PRM]
                                        * sqrt( m_parameters[EPSILON_EFF_PRM] )
                                        * m_parameters[TAND_PRM];

    m_parameters[ANG_L_PRM] = 2.0 * M_PI * m_parameters[PHYS_LEN_PRM]
                              * sqrt( m_parameters[EPSILON_EFF_PRM] ) * m_parameters[FREQUENCY_PRM]
                              / C0; // in radians
}


// -------------------------------------------------------------------
void TWISTEDPAIR::show_results()
{
    setResult( 0, m_parameters[EPSILON_EFF_PRM], "" );
    setResult( 1, m_parameters[LOSS_CONDUCTOR_PRM], "dB" );
    setResult( 2, m_parameters[LOSS_DIELECTRIC_PRM], "dB" );
    setResult( 3, m_parameters[SKIN_DEPTH_PRM] / UNIT_MICRON, "µm" );
}

void TWISTEDPAIR::showAnalyze()
{
    setProperty( Z0_PRM, m_parameters[Z0_PRM] );
    setProperty( ANG_L_PRM, m_parameters[ANG_L_PRM] );

    // Check for errors
    if( !std::isfinite( m_parameters[Z0_PRM] ) || m_parameters[Z0_PRM] < 0 )
        setErrorLevel( Z0_PRM, TRANSLINE_ERROR );

    if( !std::isfinite( m_parameters[ANG_L_PRM] ) || m_parameters[ANG_L_PRM] < 0 )
        setErrorLevel( ANG_L_PRM, TRANSLINE_ERROR );

    // Find warnings to display - physical parameters
    if( !std::isfinite( m_parameters[PHYS_DIAM_IN_PRM] ) || m_parameters[PHYS_DIAM_IN_PRM] <= 0.0 )
        setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_WARNING );

    if( !std::isfinite( m_parameters[PHYS_DIAM_OUT_PRM] )
            || m_parameters[PHYS_DIAM_OUT_PRM] <= 0.0 )
    {
        setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_WARNING );
    }

    if( m_parameters[PHYS_DIAM_IN_PRM] > m_parameters[PHYS_DIAM_OUT_PRM] )
    {
        setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_WARNING );
        setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_WARNING );
    }

    if( !std::isfinite( m_parameters[PHYS_LEN_PRM] ) || m_parameters[PHYS_LEN_PRM] < 0.0 )
        setErrorLevel( PHYS_LEN_PRM, TRANSLINE_WARNING );
}

void TWISTEDPAIR::showSynthesize()
{
    if( isSelected( PHYS_DIAM_IN_PRM ) )
        setProperty( PHYS_DIAM_IN_PRM, m_parameters[PHYS_DIAM_IN_PRM] );
    else if( isSelected( PHYS_DIAM_OUT_PRM ) )
        setProperty( PHYS_DIAM_OUT_PRM, m_parameters[PHYS_DIAM_OUT_PRM] );

    setProperty( PHYS_LEN_PRM, m_parameters[PHYS_LEN_PRM] );

    // Check for errors
    if( !std::isfinite( m_parameters[PHYS_DIAM_IN_PRM] ) || m_parameters[PHYS_DIAM_IN_PRM] <= 0.0 )
    {
        if( isSelected( PHYS_DIAM_IN_PRM ) )
            setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_ERROR );
        else
            setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_WARNING );
    }

    if( !std::isfinite( m_parameters[PHYS_DIAM_OUT_PRM] )
            || m_parameters[PHYS_DIAM_OUT_PRM] <= 0.0 )
    {
        if( isSelected( PHYS_DIAM_OUT_PRM ) )
            setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_ERROR );
        else
            setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_WARNING );
    }

    if( m_parameters[PHYS_DIAM_IN_PRM] > m_parameters[PHYS_DIAM_OUT_PRM] )
    {
        if( isSelected( PHYS_DIAM_IN_PRM ) )
            setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_ERROR );
        else if( isSelected( PHYS_DIAM_OUT_PRM ) )
            setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_ERROR );
    }

    if( !std::isfinite( m_parameters[PHYS_LEN_PRM] ) || m_parameters[PHYS_LEN_PRM] < 0.0 )
        setErrorLevel( PHYS_LEN_PRM, TRANSLINE_ERROR );

    // Check for warnings
    if( !std::isfinite( m_parameters[Z0_PRM] ) || m_parameters[Z0_PRM] < 0 )
        setErrorLevel( Z0_PRM, TRANSLINE_WARNING );

    if( !std::isfinite( m_parameters[ANG_L_PRM] ) || m_parameters[ANG_L_PRM] < 0 )
        setErrorLevel( ANG_L_PRM, TRANSLINE_WARNING );
}


#define MAX_ERROR 0.000001

// -------------------------------------------------------------------
void TWISTEDPAIR::calcSynthesize()
{
    if( isSelected( PHYS_DIAM_IN_PRM ) )
        minimizeZ0Error1D( &( m_parameters[PHYS_DIAM_IN_PRM] ) );
    else
        minimizeZ0Error1D( &( m_parameters[PHYS_DIAM_OUT_PRM] ) );
}