2011-08-05 19:53:42 +00:00
|
|
|
/****************************************************************************
|
|
|
|
** From Qucs Attenuator Synthesis
|
|
|
|
** attenuator_classes.cpp
|
|
|
|
**
|
|
|
|
** since 2006/6/14
|
|
|
|
**
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <wx/bitmap.h>
|
|
|
|
|
2019-09-29 15:25:56 +00:00
|
|
|
#include <i18n_utility.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <kiface_i.h>
|
2021-05-04 02:27:54 +00:00
|
|
|
#include <bitmaps.h>
|
2020-10-13 01:01:25 +00:00
|
|
|
|
|
|
|
#include "attenuator_classes.h"
|
|
|
|
#include "pcb_calculator_settings.h"
|
2011-08-05 19:53:42 +00:00
|
|
|
|
2016-01-16 14:27:42 +00:00
|
|
|
// Html texts showing the formulas
|
2019-10-01 15:03:00 +00:00
|
|
|
wxString pi_formula =
|
2020-10-13 01:55:32 +00:00
|
|
|
#include "attenuators/pi_formula.h"
|
2016-01-16 14:27:42 +00:00
|
|
|
|
2019-10-01 15:03:00 +00:00
|
|
|
|
|
|
|
wxString tee_formula =
|
2020-10-13 01:55:32 +00:00
|
|
|
#include "attenuators/tee_formula.h"
|
2019-10-01 15:03:00 +00:00
|
|
|
|
2016-01-16 14:27:42 +00:00
|
|
|
|
2019-09-29 15:25:56 +00:00
|
|
|
wxString bridget_tee_formula =
|
2020-10-13 01:55:32 +00:00
|
|
|
#include "attenuators/bridget_tee_formula.h"
|
2016-01-16 14:27:42 +00:00
|
|
|
|
2019-10-01 15:03:00 +00:00
|
|
|
|
|
|
|
wxString splitter_formula =
|
2020-10-13 01:55:32 +00:00
|
|
|
#include "attenuators/splitter_formula.h"
|
2019-10-01 15:03:00 +00:00
|
|
|
|
2016-01-16 14:27:42 +00:00
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ATTENUATOR::ATTENUATOR( ATTENUATORS_TYPE aTopology )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_base");
|
|
|
|
m_Error = false;
|
|
|
|
m_Topology = aTopology;
|
|
|
|
m_ResultCount = 3; // If 3 values must be calculated
|
|
|
|
m_Zin = 50; // Ohms
|
|
|
|
m_Zin_Enable = true;
|
|
|
|
m_Zout = 50; // Ohms
|
|
|
|
m_Attenuation = 6.0; // dB
|
|
|
|
m_Attenuation_Enable = true;
|
|
|
|
m_MinimumATT = 0.0; // dB
|
|
|
|
m_SchBitMap = NULL;
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = NULL;
|
2015-03-04 09:26:00 +00:00
|
|
|
|
|
|
|
// Initialize these variables mainly to avoid warnings from a static analyzer
|
|
|
|
m_R1 = 0.0;
|
|
|
|
m_R2 = 0.0;
|
|
|
|
m_R3 = 0.0;
|
|
|
|
Lmin = L = A = 0.0; // internal variable for temporary use
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR::~ATTENUATOR()
|
|
|
|
{
|
|
|
|
delete m_SchBitMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void ATTENUATOR::ReadConfig()
|
2011-08-05 19:53:42 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
std::string name = m_Name.ToStdString();
|
|
|
|
|
|
|
|
wxASSERT( cfg->m_Attenuators.attenuators.count( name ) );
|
|
|
|
|
|
|
|
m_Attenuation = cfg->m_Attenuators.attenuators.at( name ).attenuation;
|
|
|
|
m_Zin = cfg->m_Attenuators.attenuators.at( name ).zin;
|
|
|
|
m_Zout = cfg->m_Attenuators.attenuators.at( name ).zout;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void ATTENUATOR::WriteConfig()
|
2011-08-05 19:53:42 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
std::string name = m_Name.ToStdString();
|
|
|
|
|
|
|
|
cfg->m_Attenuators.attenuators[ name ].attenuation = m_Attenuation;
|
|
|
|
cfg->m_Attenuators.attenuators[ name ].zin = m_Zin;
|
|
|
|
cfg->m_Attenuators.attenuators[ name ].zout = m_Zout;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_PI::ATTENUATOR_PI() : ATTENUATOR( PI_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_pi");
|
2021-05-04 02:27:54 +00:00
|
|
|
m_SchBitMap = KiBitmapNew( BITMAPS::att_pi );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &pi_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_PI::Calculate()
|
|
|
|
{
|
|
|
|
if( !ATTENUATOR::Calculate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_R2 = ( (L - 1) / 2 ) * sqrt( m_Zin * m_Zout / L );
|
|
|
|
m_R1 = 1 / ( ( (A / m_Zin) ) - (1 / m_R2) );
|
|
|
|
m_R3 = 1 / ( ( (A / m_Zout) ) - (1 / m_R2) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_TEE::ATTENUATOR_TEE() : ATTENUATOR( TEE_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_tee");
|
2021-05-04 02:27:54 +00:00
|
|
|
m_SchBitMap = KiBitmapNew( BITMAPS::att_tee );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &tee_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_TEE::Calculate()
|
|
|
|
{
|
|
|
|
if( !ATTENUATOR::Calculate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_R2 = ( 2 * sqrt( L * m_Zin * m_Zout ) ) / (L - 1);
|
|
|
|
m_R1 = m_Zin * A - m_R2;
|
|
|
|
m_R3 = m_Zout * A - m_R2;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_BRIDGE::ATTENUATOR_BRIDGE() : ATTENUATOR( BRIDGE_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_bridge");
|
|
|
|
m_Zin_Enable = false;
|
|
|
|
m_ResultCount = 2;
|
2021-05-04 02:27:54 +00:00
|
|
|
m_SchBitMap = KiBitmapNew( BITMAPS::att_bridge );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &bridget_tee_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_BRIDGE::Calculate()
|
|
|
|
{
|
|
|
|
m_Zin = m_Zout;
|
|
|
|
if( !ATTENUATOR::Calculate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
L = pow( 10, m_Attenuation / 20 );
|
|
|
|
m_R1 = m_Zin * (L - 1);
|
|
|
|
m_R2 = m_Zin / (L - 1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_SPLITTER::ATTENUATOR_SPLITTER() : ATTENUATOR( SPLITTER_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_splitter");
|
|
|
|
m_Attenuation_Enable = false;
|
|
|
|
m_Attenuation = 6.0;
|
|
|
|
m_MinimumATT = 6.0;
|
|
|
|
m_Zin_Enable = false;
|
2021-05-04 02:27:54 +00:00
|
|
|
m_SchBitMap = KiBitmapNew( BITMAPS::att_splitter );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &splitter_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_SPLITTER::Calculate()
|
|
|
|
{
|
|
|
|
m_Attenuation = 6.0;
|
|
|
|
m_Zin = m_Zout;
|
|
|
|
m_R1 = m_R2 = m_R3 = m_Zout / 3.0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR::Calculate()
|
|
|
|
{
|
|
|
|
L = pow( 10, m_Attenuation / 10 );
|
|
|
|
|
|
|
|
A = (L + 1) / (L - 1);
|
|
|
|
|
|
|
|
if( m_Zin > m_Zout )
|
|
|
|
{
|
|
|
|
Lmin = (2 * m_Zin / m_Zout) - 1 + 2 *
|
|
|
|
sqrt( m_Zin / m_Zout * (m_Zin / m_Zout - 1) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Lmin = (2 * m_Zout / m_Zin) - 1 + 2 *
|
|
|
|
sqrt( m_Zout / m_Zin * (m_Zout / m_Zin - 1) );
|
|
|
|
}
|
|
|
|
m_MinimumATT = 10 * log10( Lmin );
|
|
|
|
|
|
|
|
if( m_MinimumATT > m_Attenuation )
|
|
|
|
{
|
|
|
|
m_Error = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Error = false;
|
|
|
|
return true;
|
|
|
|
}
|