kicad/pcb_calculator/tracks_width_versus_current...

208 lines
8.7 KiB
C++
Raw Normal View History

2011-08-07 16:02:58 +00:00
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2011 jean-pierre.charras
* Copyright (C) 1992-2011 Kicad Developers, see change_log.txt for contributors.
*
* 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 program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* see
* http://www.desmith.net/NMdS/Electronics/TraceWidth.html
* http://www.ultracad.com/articles/pcbtemp.pdf
* for more info
*/
2014-02-07 16:09:15 +00:00
#include <cmath>
#include <wx/wx.h>
#include <wx/config.h>
2011-08-07 16:02:58 +00:00
#include <pcb_calculator_frame_base.h>
2011-08-07 16:02:58 +00:00
#include <pcb_calculator.h>
#include <UnitSelector.h>
#include <units_scales.h>
2011-08-07 16:02:58 +00:00
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
extern double DoubleFromString( const wxString& TextValue );
2011-08-07 16:02:58 +00:00
// Key words to read/write some parameters in config:
#define KEYWORD_TW_CURRENT wxT( "TW_Track_Current" )
#define KEYWORD_TW_DELTA_TC wxT( "TW_Delta_TC" )
#define KEYWORD_TW_TRACK_COPPER_THICKNESS wxT( "TW_Track_CopperThickness" )
#define KEYWORD_TW_TRACK_LEN wxT( "TW_Track_Len" )
#define KEYWORD_TW_TRACK_COPPER_THICKNESS_UNIT wxT( "TW_Track_CopperThickness_Unit" )
#define KEYWORD_TW_TRACK_LEN_UNIT wxT( "TW_Track_Len_Unit" )
#define KEYWORD_TW_EXTTRACK_WIDTH_UNIT wxT( "TW_ExtTrack_Width_Unit" )
#define KEYWORD_TW_INTTRACK_WIDTH_UNIT wxT( "TW_IntTrack_Width_Unit" )
void PCB_CALCULATOR_FRAME::TW_WriteConfig()
{
// Save current parameters values in config:
m_Config->Write( KEYWORD_TW_EXTTRACK_WIDTH_UNIT, m_TW_ExtTrackWidth_choiceUnit->GetSelection() );
m_Config->Write( KEYWORD_TW_INTTRACK_WIDTH_UNIT, m_TW_IntTrackWidth_choiceUnit->GetSelection() );
m_Config->Write( KEYWORD_TW_TRACK_COPPER_THICKNESS_UNIT,
m_TW_CuThickness_choiceUnit->GetSelection() );
m_Config->Write( KEYWORD_TW_TRACK_LEN_UNIT, m_TW_CuLength_choiceUnit->GetSelection() );
m_Config->Write( KEYWORD_TW_CURRENT, m_TrackCurrentValue->GetValue() );
m_Config->Write( KEYWORD_TW_DELTA_TC, m_TrackDeltaTValue->GetValue() );
m_Config->Write( KEYWORD_TW_TRACK_COPPER_THICKNESS, m_TrackThicknessValue->GetValue() );
m_Config->Write( KEYWORD_TW_TRACK_LEN, m_TrackLengthValue->GetValue() );
}
void PCB_CALCULATOR_FRAME::OnTWCalculateButt( wxCommandEvent& event )
{
// Prepare parameters:
2014-03-20 06:24:33 +00:00
double current = std::abs( DoubleFromString( m_TrackCurrentValue->GetValue() ) );
double thickness = std::abs( DoubleFromString( m_TrackThicknessValue->GetValue() ) );
double deltaT_C = std::abs( DoubleFromString( m_TrackDeltaTValue->GetValue() ) );
double track_len = std::abs( DoubleFromString( m_TrackLengthValue->GetValue() ) );
2011-08-07 16:02:58 +00:00
double extTrackWidth;
double intTrackWidth;
// Normalize units:
thickness *= m_TW_CuThickness_choiceUnit->GetUnitScale();
track_len *= m_TW_CuLength_choiceUnit->GetUnitScale();
extTrackWidth = TWCalculate( current, thickness, deltaT_C, false );
intTrackWidth = TWCalculate( current, thickness, deltaT_C, true );
// Display values:
wxString msg;
msg.Printf( wxT( "%g" ), extTrackWidth / m_TW_ExtTrackWidth_choiceUnit->GetUnitScale() );
m_ExtTrackWidthValue->SetValue( msg );
msg.Printf( wxT( "%g" ), intTrackWidth / m_TW_IntTrackWidth_choiceUnit->GetUnitScale() );
m_IntTrackWidthValue->SetValue( msg );
// Display areas:
double scale = m_TW_ExtTrackWidth_choiceUnit->GetUnitScale();
double ext_area = thickness * extTrackWidth;
msg.Printf( wxT( "%g" ), ext_area / (scale * scale) );
2014-02-07 16:09:15 +00:00
2011-08-07 16:02:58 +00:00
m_ExtTrackAreaValue->SetValue( msg );
wxString strunit = m_TW_ExtTrackWidth_choiceUnit->GetUnitName();
msg = strunit + wxT( " x " ) + strunit;
m_ExtTrackAreaUnitLabel->SetLabel( msg );
2014-02-07 16:09:15 +00:00
2011-08-07 16:02:58 +00:00
scale = m_TW_IntTrackWidth_choiceUnit->GetUnitScale();
double int_area = thickness * intTrackWidth;
msg.Printf( wxT( "%g" ), int_area / (scale * scale) );
2014-02-07 16:09:15 +00:00
2011-08-07 16:02:58 +00:00
m_IntTrackAreaValue->SetValue( msg );
strunit = m_TW_IntTrackWidth_choiceUnit->GetUnitName();
msg = strunit + wxT( " x " ) + strunit;
m_IntTrackAreaUnitLabel->SetLabel( msg );
// Display resistance (assuming using copper ):
double rho = 1.72e-008; // In Ohms*meter
double ext_res = rho / ext_area * track_len;
msg.Printf( wxT( "%g" ), ext_res );
m_ExtTrackResistValue->SetValue( msg );
2014-02-07 16:09:15 +00:00
2011-08-07 16:02:58 +00:00
double int_res = rho / int_area * track_len;
msg.Printf( wxT( "%g" ), int_res );
m_IntTrackResistValue->SetValue( msg );
// Display drop voltage
double ext_drop_volt = ext_res * current;
msg.Printf( wxT( "%g" ), ext_drop_volt );
m_ExtTrackVDropValue->SetValue( msg );
2014-02-07 16:09:15 +00:00
2011-08-07 16:02:58 +00:00
double int_drop_volt = int_res * current;
msg.Printf( wxT( "%g" ), int_drop_volt );
m_IntTrackVDropValue->SetValue( msg );
// Display power loss
double loss = ext_drop_volt * current;
msg.Printf( wxT( "%g" ), loss );
m_ExtTrackLossValue->SetValue( msg );
2014-02-07 16:09:15 +00:00
2011-08-07 16:02:58 +00:00
loss = int_drop_volt * current;
msg.Printf( wxT( "%g" ), loss );
m_IntTrackLossValue->SetValue( msg );
}
/* calculate track width for external or internal layers
*
* Imax = 0.048 * dT^0.44 * A^0.725 for external layer
* Imax = 0.024 * dT^0.44 * A^0.725 for internal layer
* with A = area = aThickness * trackWidth ( in mils )
* and dT = temperature rise in degree C
* Of course we want to know trackWidth
*/
double PCB_CALCULATOR_FRAME::TWCalculate( double aCurrent, double aThickness, double aDeltaT_C,
bool aUseInternalLayer )
{
double scale = 0.048; // We are using normalize units (sizes in meters)
if( aUseInternalLayer )
scale *= 0.024 / 0.048;
// aThickness is given in normalize units (in meters) and we need mil
aThickness /= UNIT_MIL;
/* formula is Imax = scale * dT^0.44 * A^0.725
* or
* log(Imax) = log(scale) + 0.44*log(dT)
* +(0.725*(log(aThickness) + log(trackWidth))
* log(trackWidth) * 0.725 = ln(Imax) - ln(scale) - 0.44*log(dT) - 0.725*log(aThickness)
*/
double dtmp = log( aCurrent ) - log( scale ) - 0.44 * log( aDeltaT_C ) - 0.725 * log( aThickness );
dtmp /= 0.725;
double trackWidth = exp( dtmp );
trackWidth *= UNIT_MIL; // We are using normalize units (sizes in meters) and we have mil
return trackWidth; // in meters
}
void PCB_CALCULATOR_FRAME::TW_Init()
{
int tmp;
wxString msg;
// Read parameters values:
m_Config->Read( KEYWORD_TW_EXTTRACK_WIDTH_UNIT, &tmp, 0 );
m_TW_ExtTrackWidth_choiceUnit->SetSelection( tmp );
m_Config->Read( KEYWORD_TW_INTTRACK_WIDTH_UNIT, &tmp, 0 );
m_TW_IntTrackWidth_choiceUnit->SetSelection( tmp );
m_Config->Read( KEYWORD_TW_TRACK_COPPER_THICKNESS_UNIT, &tmp, 0 );
m_TW_CuThickness_choiceUnit->SetSelection( tmp );
m_Config->Read( KEYWORD_TW_TRACK_LEN_UNIT, &tmp, 0 );
m_TW_CuLength_choiceUnit->SetSelection( tmp );
m_Config->Read( KEYWORD_TW_CURRENT, &msg, wxT( "1.0" ) );
m_TrackCurrentValue->SetValue( msg );
m_Config->Read( KEYWORD_TW_DELTA_TC, &msg, wxT( "10.0" ) );
m_TrackDeltaTValue->SetValue( msg );
m_Config->Read( KEYWORD_TW_TRACK_COPPER_THICKNESS, &msg, wxT( "0.035" ) );
m_TrackThicknessValue->SetValue( msg );
m_Config->Read( KEYWORD_TW_TRACK_LEN, &msg, wxT( "20" ) );
m_TrackLengthValue->SetValue( msg );
// Init formulas text
2011-08-07 19:03:32 +00:00
m_htmlWinFormulas->AppendToPage( _( "<br><em>The formula (from IPC 2221) is:</em></br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br><b>I = K * dT<sup>0.44</sup> * (W*H)<sup>0.725</sup></b></br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br>Internal traces : <b>K = 0.024</b></br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br>External traces: <b>K = 0.048</b></br>" ) );
2011-08-07 16:02:58 +00:00
m_htmlWinFormulas->AppendToPage( _( "<br>where:</br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br><b>I</b> = maximum current in Amps</br>" ) );
2011-08-07 19:03:32 +00:00
m_htmlWinFormulas->AppendToPage( _( "<br><b>dT</b> = temperature rise above ambient in deg C</br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br><b>W,H</b> = Width and Thickness in mils</br>" ) );
2011-08-07 16:02:58 +00:00
}