KiCad PCB EDA Suite
|
Performs calculations on E-series values primarily to find target values as combinations (serial, parallel) of them. More...
#include <resistor_substitution_utils.h>
Public Types | |
enum | { S2R , S3R , S4R , NUMBER_OF_LEVELS } |
Public Member Functions | |
RES_EQUIV_CALC () | |
void | SetSeries (uint32_t aSeries) |
Set E-series to be used in calculations. | |
void | NewCalc (double aTargetValue) |
Initialize next calculation, clear exclusion mask and erase results from previous calculation. | |
void | Exclude (double aValue) |
If any value of the selected E-series not available, it can be entered as an exclude value. | |
void | Calculate () |
Executes all the calculations. | |
const std::array< std::optional< RESISTANCE >, NUMBER_OF_LEVELS > & | GetResults () |
Accessor to calculation results. | |
Private Member Functions | |
std::vector< RESISTANCE > | buildSeriesData (const ESERIES::ESERIES_VALUES &aList) |
Add values from aList to m_e_series tables. | |
void | prepare1RBuffer () |
Build 1R buffer, which is selected E-series table with excluded values removed. | |
void | prepare2RBuffer () |
Build 2R buffer, which consists of all possible combinations of two resistors from 1R buffer (serial and parallel), sorted by value. | |
std::pair< RESISTANCE &, RESISTANCE & > | findIn2RBuffer (double aTargetValue) |
Find in 2R buffer two values nearest to the given value (one smaller and one larger). | |
RESISTANCE | calculate2RSolution () |
Calculate the best combination consisting of exactly 2, 3 or 4 resistors. | |
RESISTANCE | calculate3RSolution () |
RESISTANCE | calculate4RSolution () |
Private Attributes | |
std::vector< std::vector< RESISTANCE > > | m_e_series |
std::vector< bool > | m_exclude_mask |
std::vector< RESISTANCE > | m_buffer_1R |
std::vector< RESISTANCE > | m_buffer_2R |
uint32_t | m_series = ESERIES::E6 |
double | m_target = 0 |
std::array< std::optional< RESISTANCE >, NUMBER_OF_LEVELS > | m_results |
Performs calculations on E-series values primarily to find target values as combinations (serial, parallel) of them.
RES_EQUIV_CALC class stores and performs calcuations on E-series values. It currently is targeted toward the resistor calculator and hard codes some limitations to optimize its use in the resistor calculator.
At this time these limitations are that this class handles only E-series up to E24 and it does not consider resistor values below 10 Ohm or above 1M Ohm.
Definition at line 54 of file resistor_substitution_utils.h.
anonymous enum |
Enumerator | |
---|---|
S2R | |
S3R | |
S4R | |
NUMBER_OF_LEVELS |
Definition at line 69 of file resistor_substitution_utils.h.
RES_EQUIV_CALC::RES_EQUIV_CALC | ( | ) |
Definition at line 219 of file resistor_substitution_utils.cpp.
References buildSeriesData(), and m_e_series.
|
private |
Add values from aList to m_e_series tables.
Covers all decades between FIRST_VALUE and LAST_VALUE.
Definition at line 282 of file resistor_substitution_utils.cpp.
References RES_EQUIV_CALC_FIRST_VALUE, RES_EQUIV_CALC_LAST_VALUE, and strValue().
Referenced by RES_EQUIV_CALC().
void RES_EQUIV_CALC::Calculate | ( | ) |
Executes all the calculations.
Results are to be retrieved using GetResults (below).
Definition at line 256 of file resistor_substitution_utils.cpp.
References std::abs(), calculate2RSolution(), calculate3RSolution(), calculate4RSolution(), epsilon, m_results, m_target, prepare1RBuffer(), prepare2RBuffer(), S2R, S3R, S4R, PROF_TIMER::Show(), and RESISTANCE::value.
Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().
|
private |
Calculate the best combination consisting of exactly 2, 3 or 4 resistors.
Definition at line 350 of file resistor_substitution_utils.cpp.
References SolutionCollector::Add2RLookupResults(), findIn2RBuffer(), SolutionCollector::GetBest(), and m_target.
Referenced by Calculate().
|
private |
Definition at line 367 of file resistor_substitution_utils.cpp.
References SolutionCollector::Add2RLookupResults(), findIn2RBuffer(), SolutionCollector::GetBest(), m_buffer_1R, m_target, parallelResistance(), parallelValue(), serialResistance(), and serialValue().
Referenced by Calculate().
|
private |
Definition at line 406 of file resistor_substitution_utils.cpp.
References SolutionCollector::Add2RLookupResults(), findIn2RBuffer(), SolutionCollector::GetBest(), m_buffer_1R, m_buffer_2R, m_target, parallelResistance(), parallelValue(), serialResistance(), and serialValue().
Referenced by Calculate().
void RES_EQUIV_CALC::Exclude | ( | double | aValue | ) |
If any value of the selected E-series not available, it can be entered as an exclude value.
aValue | is the value (in Ohms) to exclude from calculation Values to exclude are set to true in the current exclusion mask and will not be considered during calculations. |
Definition at line 244 of file resistor_substitution_utils.cpp.
References std::abs(), epsilon, m_e_series, m_exclude_mask, and m_series.
Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().
|
private |
Find in 2R buffer two values nearest to the given value (one smaller and one larger).
It always returns two valid values, even for input out of range or Nan.
Definition at line 329 of file resistor_substitution_utils.cpp.
References m_buffer_2R.
Referenced by calculate2RSolution(), calculate3RSolution(), and calculate4RSolution().
|
inline |
Accessor to calculation results.
Empty std::optional means that the exact value can be achieved using fewer resistors.
Definition at line 112 of file resistor_substitution_utils.h.
References m_results.
Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().
void RES_EQUIV_CALC::NewCalc | ( | double | aTargetValue | ) |
Initialize next calculation, clear exclusion mask and erase results from previous calculation.
aTargetValue | is the value (in Ohms) to be looked for |
Definition at line 234 of file resistor_substitution_utils.cpp.
References m_e_series, m_exclude_mask, m_results, m_series, and m_target.
Referenced by PANEL_R_CALCULATOR::OnCalculateESeries().
|
private |
Build 1R buffer, which is selected E-series table with excluded values removed.
Definition at line 301 of file resistor_substitution_utils.cpp.
References m_buffer_1R, m_e_series, m_exclude_mask, and m_series.
Referenced by Calculate().
|
private |
Build 2R buffer, which consists of all possible combinations of two resistors from 1R buffer (serial and parallel), sorted by value.
Definition at line 313 of file resistor_substitution_utils.cpp.
References m_buffer_1R, m_buffer_2R, parallelResistanceSimple(), and serialResistanceSimple().
Referenced by Calculate().
void RES_EQUIV_CALC::SetSeries | ( | uint32_t | aSeries | ) |
Set E-series to be used in calculations.
Correct values are from 0 to 4 inclusive, representing series (consecutively) E1, E3, E6, E12, E24. After changing the series, NewCalc must be called before running calculations.
Definition at line 229 of file resistor_substitution_utils.cpp.
References m_series.
Referenced by PANEL_R_CALCULATOR::OnESeriesSelection().
|
private |
Definition at line 151 of file resistor_substitution_utils.h.
Referenced by calculate3RSolution(), calculate4RSolution(), prepare1RBuffer(), and prepare2RBuffer().
|
private |
Definition at line 152 of file resistor_substitution_utils.h.
Referenced by calculate4RSolution(), findIn2RBuffer(), and prepare2RBuffer().
|
private |
Definition at line 149 of file resistor_substitution_utils.h.
Referenced by Exclude(), NewCalc(), prepare1RBuffer(), and RES_EQUIV_CALC().
|
private |
Definition at line 150 of file resistor_substitution_utils.h.
Referenced by Exclude(), NewCalc(), and prepare1RBuffer().
|
private |
Definition at line 157 of file resistor_substitution_utils.h.
Referenced by Calculate(), GetResults(), and NewCalc().
|
private |
Definition at line 154 of file resistor_substitution_utils.h.
Referenced by Exclude(), NewCalc(), prepare1RBuffer(), and SetSeries().
|
private |
Definition at line 155 of file resistor_substitution_utils.h.
Referenced by Calculate(), calculate2RSolution(), calculate3RSolution(), calculate4RSolution(), and NewCalc().