KiCad PCB EDA Suite
Loading...
Searching...
No Matches
attenuator_classes.cpp
Go to the documentation of this file.
1/****************************************************************************
2** From Qucs Attenuator Synthesis
3** attenuator_classes.cpp
4**
5** since 2006/6/14
6**
7*****************************************************************************/
8
9#include <wx/bitmap.h>
10
11#include <i18n_utility.h>
12#include <kiface_base.h>
13#include <bitmaps.h>
14
15#include "attenuator_classes.h"
17
18// Html texts showing the formulas
19wxString pi_formula =
21
22
23wxString tee_formula =
25
26
27wxString bridget_tee_formula =
29
30
31wxString splitter_formula =
33
34
36{
37 m_Name = wxT( "att_base" );
38 m_Error = false;
39 m_Topology = aTopology;
40 m_ResultCount = 3; // If 3 values must be calculated
41 m_Zin = 50; // Ohms
42 m_Zin_Enable = true;
43 m_Zout = 50; // Ohms
44 m_Attenuation = 6.0; // dB
46 m_MinimumATT = 0.0; // dB
47 m_SchBitmapName = BITMAPS::INVALID_BITMAP;
48 m_FormulaName = nullptr;
49
50 // Initialize these variables mainly to avoid warnings from a static analyzer
51 m_R1 = 0.0;
52 m_R2 = 0.0;
53 m_R3 = 0.0;
54 Lmin = L = A = 0.0; // internal variable for temporary use
55}
56
57
59{
60}
61
62
64{
65 auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
66 std::string name = m_Name.ToStdString();
67
68 wxASSERT( cfg->m_Attenuators.attenuators.count( name ) );
69
70 m_Attenuation = cfg->m_Attenuators.attenuators.at( name ).attenuation;
71 m_Zin = cfg->m_Attenuators.attenuators.at( name ).zin;
72 m_Zout = cfg->m_Attenuators.attenuators.at( name ).zout;
73}
74
75
77{
78 auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
79 std::string name = m_Name.ToStdString();
80
81 cfg->m_Attenuators.attenuators[ name ].attenuation = m_Attenuation;
82 cfg->m_Attenuators.attenuators[ name ].zin = m_Zin;
83 cfg->m_Attenuators.attenuators[ name ].zout = m_Zout;
84}
85
86
88{
89 m_Name = wxT( "att_pi" );
90 m_SchBitmapName = BITMAPS::att_pi;
91 m_FormulaName = &pi_formula;
92}
93
94
96{
98 return false;
99
100 m_R2 = ( (L - 1) / 2 ) * sqrt( m_Zin * m_Zout / L );
101 m_R1 = 1 / ( ( (A / m_Zin) ) - (1 / m_R2) );
102 m_R3 = 1 / ( ( (A / m_Zout) ) - (1 / m_R2) );
103
104 return true;
105}
106
107
109{
110 m_Name = wxT( "att_tee" );
111 m_SchBitmapName = BITMAPS::att_tee;
112 m_FormulaName = &tee_formula;
113}
114
115
117{
118 if( !ATTENUATOR::Calculate() )
119 return false;
120
121 m_R2 = ( 2 * sqrt( L * m_Zin * m_Zout ) ) / (L - 1);
122 m_R1 = m_Zin * A - m_R2;
123 m_R3 = m_Zout * A - m_R2;
124
125 return true;
126}
127
128
130{
131 m_Name = wxT( "att_bridge" );
132 m_Zin_Enable = false;
133 m_ResultCount = 2;
134 m_SchBitmapName = BITMAPS::att_bridge;
135 m_FormulaName = &bridget_tee_formula;
136}
137
138
140{
141 m_Zin = m_Zout;
142
143 if( !ATTENUATOR::Calculate() )
144 return false;
145
146 L = pow( 10, m_Attenuation / 20 );
147 m_R1 = m_Zin * (L - 1);
148 m_R2 = m_Zin / (L - 1);
149
150 return true;
151}
152
153
155{
156 m_Name = wxT( "att_splitter" );
157 m_Attenuation_Enable = false;
158 m_Attenuation = 6.0;
159 m_MinimumATT = 6.0;
160 m_Zin_Enable = false;
161 m_SchBitmapName = BITMAPS::att_splitter;
162 m_FormulaName = &splitter_formula;
163}
164
165
167{
168 m_Attenuation = 6.0;
169 m_Zin = m_Zout;
170 m_R1 = m_R2 = m_R3 = m_Zout / 3.0;
171 return true;
172}
173
174
176{
177 L = pow( 10, m_Attenuation / 10 );
178
179 A = (L + 1) / (L - 1);
180
181 if( m_Zin > m_Zout )
182 {
183 Lmin = (2 * m_Zin / m_Zout) - 1 + 2 *
184 sqrt( m_Zin / m_Zout * (m_Zin / m_Zout - 1) );
185 }
186 else
187 {
188 Lmin = (2 * m_Zout / m_Zin) - 1 + 2 *
189 sqrt( m_Zout / m_Zin * (m_Zout / m_Zin - 1) );
190 }
191 m_MinimumATT = 10 * log10( Lmin );
192
194 {
195 m_Error = true;
196 return false;
197 }
198
199 m_Error = false;
200 return true;
201}
const char * name
Definition: DXF_plotter.cpp:57
ATTENUATORS_TYPE
@ TEE_TYPE
@ SPLITTER_TYPE
@ BRIDGE_TYPE
@ PI_TYPE
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ att_splitter
virtual bool Calculate() override
Calculates the values of components in attenuator.
virtual bool Calculate() override
Calculates the values of components in attenuator.
virtual bool Calculate() override
Calculates the values of components in attenuator.
virtual bool Calculate() override
Calculates the values of components in attenuator.
ATTENUATORS_TYPE m_Topology
void ReadConfig()
Read values stored in config for this attenuator.
void WriteConfig()
Read values stored in config for this attenuator.
virtual bool Calculate()
Calculates the values of components in attenuator.
BITMAPS m_SchBitmapName
wxString * m_FormulaName
bool m_Attenuation_Enable
virtual ~ATTENUATOR()
ATTENUATOR(ATTENUATORS_TYPE Topology)
double m_Attenuation
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
Some functions to handle hotkeys in KiCad.