KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_track_width_calculations.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <cmath>
21
22#include <boost/test/unit_test.hpp>
23
25
33BOOST_AUTO_TEST_SUITE( TrackWidthCalculations )
34
35
36// External coefficients: K = 215.3, a = 2, b = -1.15, c = -1.0
37BOOST_AUTO_TEST_CASE( ExternalCurrentFromWidth )
38{
39 // 20 mil wide, 1 oz (1.378 mil) thick, 10 C rise.
40 double current = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 1.378, 10.0, false );
41
42 BOOST_CHECK_CLOSE( current, 1.4164291025677085, 1e-6 );
43}
44
45
46// Internal 1 oz coefficients (default UI thickness): K = 200, a = 1.9, b = -1.10, c = -1.52
47BOOST_AUTO_TEST_CASE( InternalCurrentFromWidth )
48{
49 double current = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 1.378, 10.0, true );
50
51 BOOST_CHECK_CLOSE( current, 1.513124408404138, 1e-6 );
52}
53
54
55// IPC-2152 reverses the IPC-2221 assumption that internal traces run much hotter; the data showed
56// internal traces cool about as well as (or better than) external ones, so an internal trace is
57// not derated by the historical factor of two.
58BOOST_AUTO_TEST_CASE( InternalNotHalvedRelativeToExternal )
59{
60 double external = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 1.378, 10.0, false );
61 double internal = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 1.378, 10.0, true );
62
63 BOOST_CHECK_GT( internal, 0.5 * external );
64}
65
66
67// Coefficient selection should bucket by nominal copper weight; a 2 oz internal trace uses the
68// 2 oz fit (K = 300, a = 2), distinct from the 1 oz fit.
69BOOST_AUTO_TEST_CASE( InternalCopperWeightSelection )
70{
71 double current = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 2.756, 10.0, true );
72
73 // K=300, a=2, b=-1.15, c=-1.52 at W=20, Th=2.756, dT=10
74 BOOST_CHECK_CLOSE( current, 2.208736063285966, 1e-6 );
75}
76
77
78// CurrentFromWidth and WidthFromCurrent must be exact inverses.
79BOOST_AUTO_TEST_CASE( RoundTripExternal )
80{
81 const double width = 25.0;
82 const double thickness = 1.378;
83 const double deltaT = 30.0;
84
85 double current = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( width, thickness, deltaT, false );
86 double recovered = TRACK_WIDTH_CALCULATIONS::WidthFromCurrent( current, thickness, deltaT, false );
87
88 BOOST_CHECK_CLOSE( recovered, width, 1e-6 );
89}
90
91
92BOOST_AUTO_TEST_CASE( RoundTripInternal )
93{
94 const double width = 25.0;
95 const double thickness = 1.378;
96 const double deltaT = 30.0;
97
98 double current = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( width, thickness, deltaT, true );
99 double recovered = TRACK_WIDTH_CALCULATIONS::WidthFromCurrent( current, thickness, deltaT, true );
100
101 BOOST_CHECK_CLOSE( recovered, width, 1e-6 );
102}
103
104
105// A wider, thicker trace and a larger allowed temperature rise must each increase current capacity.
106BOOST_AUTO_TEST_CASE( Monotonicity )
107{
108 double base = TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 1.378, 10.0, false );
109
110 BOOST_CHECK_GT( TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 40.0, 1.378, 10.0, false ), base );
111 BOOST_CHECK_GT( TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 2.756, 10.0, false ), base );
112 BOOST_CHECK_GT( TRACK_WIDTH_CALCULATIONS::CurrentFromWidth( 20.0, 1.378, 40.0, false ), base );
113}
114
115
double CurrentFromWidth(double aWidthMils, double aThicknessMils, double aDeltaT_C, bool aUseInternalLayer)
Compute the maximum current a track can carry for a given temperature rise.
double WidthFromCurrent(double aCurrentA, double aThicknessMils, double aDeltaT_C, bool aUseInternalLayer)
Compute the track width required to carry a given current for a given temperature rise.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ExternalCurrentFromWidth)
Tests for the IPC-2152 (Brooks & Adam) track width / current calculations.