Commit c4428ae5 authored by jean-pierre charras's avatar jean-pierre charras

Pcb calculator: Add track width tool

parent 4de4a208
......@@ -14,6 +14,7 @@ set(PCB_CALCULATOR_SRCS
params_read_write.cpp
regulators_funct.cpp
transline_ident.cpp
tracks_width_versus_current.cpp
UnitSelector.cpp
transline/transline.cpp
transline/c_microstrip.cpp
......
......@@ -27,6 +27,11 @@ public:
* to normalized units (meter, herz, ohm, radian )
*/
virtual double GetUnitScale() = 0;
wxString GetUnitName()
{
return GetStringSelection();
}
};
class UNIT_SELECTOR_LEN: public UNIT_SELECTOR
......
......@@ -33,10 +33,11 @@ class UNIT_SELECTOR_RESISTOR;
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/panel.h>
#include <wx/radiobox.h>
#include <wx/statline.h>
#include <wx/choice.h>
#include <wx/html/htmlwin.h>
#include <wx/statbox.h>
#include <wx/radiobox.h>
#include <wx/statline.h>
#include <wx/grid.h>
#include <wx/notebook.h>
#include <wx/frame.h>
......@@ -75,6 +76,52 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
wxStaticText* m_unitsVout;
wxButton* m_buttonCalculate;
wxStaticText* m_RegulMessage;
wxPanel* m_panelTrackWidth;
wxStaticText* m_staticText89;
wxStaticText* m_staticTextCurrent;
wxTextCtrl* m_TrackCurrentValue;
wxStaticText* m_staticText62;
wxStaticText* m_staticText63;
wxTextCtrl* m_TrackDeltaTValue;
wxStaticText* m_staticText64;
wxStaticText* m_staticText65;
wxTextCtrl* m_TrackThicknessValue;
UNIT_SELECTOR_LEN* m_TW_CuThickness_choiceUnit;
wxStaticText* m_staticText66;
wxTextCtrl* m_TrackLengthValue;
UNIT_SELECTOR_LEN* m_TW_CuLength_choiceUnit;
wxHtmlWindow* m_htmlWinFormulas;
wxButton* m_buttonTW;
wxStaticText* m_staticTextWidth;
wxTextCtrl* m_ExtTrackWidthValue;
UNIT_SELECTOR_LEN* m_TW_ExtTrackWidth_choiceUnit;
wxStaticText* m_staticTextArea;
wxTextCtrl* m_ExtTrackAreaValue;
wxStaticText* m_ExtTrackAreaUnitLabel;
wxStaticText* m_staticText651;
wxTextCtrl* m_ExtTrackResistValue;
wxStaticText* m_staticText84;
wxStaticText* m_staticText661;
wxTextCtrl* m_ExtTrackVDropValue;
wxStaticText* m_staticText83;
wxStaticText* m_staticText79;
wxTextCtrl* m_ExtTrackLossValue;
wxStaticText* m_staticText791;
wxStaticText* m_staticTextWidth11;
wxTextCtrl* m_IntTrackWidthValue;
UNIT_SELECTOR_LEN* m_TW_IntTrackWidth_choiceUnit;
wxStaticText* m_staticTextArea1;
wxTextCtrl* m_IntTrackAreaValue;
wxStaticText* m_IntTrackAreaUnitLabel;
wxStaticText* m_staticText6511;
wxTextCtrl* m_IntTrackResistValue;
wxStaticText* m_staticText841;
wxStaticText* m_staticText6611;
wxTextCtrl* m_IntTrackVDropValue;
wxStaticText* m_staticText831;
wxStaticText* m_staticText792;
wxTextCtrl* m_IntTrackLossValue;
wxStaticText* m_staticText7911;
wxPanel* m_panelTransline;
wxRadioBox* m_TranslineSelection;
wxPanel* m_panelDisplayshape;
......@@ -195,6 +242,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
// Virtual event handlers, overide them in your derived class
virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTWCalculateButt( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTranslineSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnPaintTranslinePanel( wxPaintEvent& event ) { event.Skip(); }
virtual void OnTranslineEpsilonR_Button( wxCommandEvent& event ) { event.Skip(); }
......@@ -212,7 +260,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
public:
PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Pcb Calculator"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 752,465 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL );
PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Pcb Calculator"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 670,465 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL );
~PCB_CALCULATOR_FRAME_BASE();
......
......@@ -46,6 +46,32 @@ private:
void ReadConfig();
void WriteConfig();
// tracks width versus current functions:
/**
* Function OnTWCalculateButt
* Called by clicking on the calculate button
*/
void OnTWCalculateButt( wxCommandEvent& event );
/**
* Function TW_Init
* Read config and init dialog widgets values
*/
void TW_Init();
/**
* Function TW_WriteConfig
* Write Track width prameters in config
*/
void TW_WriteConfig();
/**
* Function TWCalculate
* Performs track caracteristics values calculations.
*/
double TWCalculate( double aCurrent, double aThickness, double aDeltaT_C,
bool aUseInternalLayer );
// Transline functions:
/**
* Function OnTranslineSelection
......
......@@ -73,6 +73,8 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) :
TranslineTypeSelection( m_currTransLineType );
m_TranslineSelection->SetSelection( m_currTransLineType );
TW_Init();
SetAttenuator( m_AttenuatorsSelection->GetSelection() );
ToleranceSelection( m_rbToleranceSelection->GetSelection() );
......@@ -175,6 +177,8 @@ void PCB_CALCULATOR_FRAME::WriteConfig()
m_Config->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() );
m_Config->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() );
TW_WriteConfig();
for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
m_transline_list[ii]->WriteConfig( m_Config );
for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
......
/*
* 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
*/
#include "wx/wx.h"
#include "wx/config.h"
#include "pcb_calculator_frame_base.h"
#include "pcb_calculator.h"
#include "UnitSelector.h"
#include "units_scales.h"
extern double ReturnDoubleFromString( const wxString& TextValue );
// 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:
double current = ReturnDoubleFromString( m_TrackCurrentValue->GetValue() );
double thickness = ReturnDoubleFromString( m_TrackThicknessValue->GetValue() );
double deltaT_C = ReturnDoubleFromString( m_TrackDeltaTValue->GetValue() );
double track_len = ReturnDoubleFromString( m_TrackLengthValue->GetValue() );
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) );
m_ExtTrackAreaValue->SetValue( msg );
wxString strunit = m_TW_ExtTrackWidth_choiceUnit->GetUnitName();
msg = strunit + wxT( " x " ) + strunit;
m_ExtTrackAreaUnitLabel->SetLabel( msg );
scale = m_TW_IntTrackWidth_choiceUnit->GetUnitScale();
double int_area = thickness * intTrackWidth;
msg.Printf( wxT( "%g" ), int_area / (scale * scale) );
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 );
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 );
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 );
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
m_htmlWinFormulas->AppendToPage( _( "<br>The formulas (from IPC 2221) are:</br>" ) );
m_htmlWinFormulas->AppendToPage( _(
"<br>Internal traces : <b>I = 0.024 * dT^0.44 * A^0.725</b></br>" ) );
m_htmlWinFormulas->AppendToPage( _(
"<br>External traces: <b>I = 0.048 * dT^0.44 * A^0.725</b></br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br>where:</br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br><b>I</b> = maximum current in Amps</br>" ) );
m_htmlWinFormulas->AppendToPage( _(
"<br><b>dT</b> = temperature rise above ambient in C</br>" ) );
m_htmlWinFormulas->AppendToPage( _( "<br><b>A</b> = cross-sectional area in mils</br>" ) );
}
......@@ -250,9 +250,9 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum transline_type_id aType )
_( "MurC" ), _( "Relative Permeability of Conductor" ), 1,
false ) );
AddPrm( new TRANSLINE_PRM( PRM_TYPE_PHYS, PHYS_S_PRM,
_( "a" ), _( "Width of Waveguide" ), 10.0, true ) );
AddPrm( new TRANSLINE_PRM( PRM_TYPE_PHYS, PHYS_WIDTH_PRM,
_( "a" ), _( "Width of Waveguide" ), 10.0, true ) );
AddPrm( new TRANSLINE_PRM( PRM_TYPE_PHYS, PHYS_S_PRM,
_( "b" ), _( "Height of Waveguide" ), 5.0, true ) );
AddPrm( new TRANSLINE_PRM( PRM_TYPE_PHYS, PHYS_LEN_PRM,
_( "L" ), _( "Waveguide Length" ), 50.0, true ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment