📄 rsistor.cpp
字号:
// Rsistor.cpp : implementation file
//
#include "stdafx.h"
#include "Resistor_2.h"
#include "Rsistor.h"
#include "stdlib.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
double R_table_5_per[R_table_5_m][R_table_5_n] ={
{1.0, 5.6, 33, 160, 820, 3.9*K, 20*K, 100*K, 510*K, 2.7*M},
{1.1, 6.2, 36, 180, 910, 4.3*K, 22*K, 110*K, 560*K, 3.0*M},
{1.2, 6.8, 39, 200, 1*K, 4.7*K, 24*K, 120*K, 620*K, 3.3*M},
{1.3, 7.5, 43, 220, 1.1*K, 5.1*K, 27*K, 130*K, 680*K, 3.6*M},
{1.5, 8.2, 47, 240, 1.2*K, 5.6*K, 30*K, 150*K, 750*K, 3.9*M},
{1.6, 9.1, 51, 270, 1.3*K, 6.2*K, 33*K, 160*K, 820*K, 4.3*M},
{1.8, 10, 56, 300, 1.5*K, 6.6*K, 36*K, 180*K, 910*K, 4.7*M},
{2.0, 11, 62, 330, 1.6*K, 7.5*K, 39*K, 200*K, 1*M, 5.1*M},
{2.2, 12, 68, 360, 1.8*K, 8.2*K, 43*K, 220*K, 1.1*M, 5.6*M},
{2.4, 13, 75, 390, 2*K, 9.1*K, 47*K, 240*K, 1.2*M, 6.2*M},
{2.7, 15, 82, 430, 2.2*K, 10*K, 51*K, 270*K, 1.3*M, 6.8*M},
{3.0, 16, 91, 470, 2.4*K, 11*K, 56*K, 300*K, 1.5*M, 7.5*M},
{3.3, 18, 100, 510, 2.7*K, 12*K, 62*K, 330*K, 1.6*M, 8.2*M},
{3.6, 20, 110, 560, 3*K, 13*K, 68*K, 360*K, 1.8*M, 9.1*M},
{3.9, 22, 120, 620, 3.2*K, 15*K, 75*K, 390*K, 2*M, 10*M},
{4.3, 24, 130, 680, 3.3*K, 16*K, 82*K, 430*K, 2.2*M, 15*M},
{4.7, 27, 150, 750, 3.6*K, 18*K, 91*K, 470*K, 2.4*M, 22*M},
{5.1, 30, 0, 0, 0, 0, 0, 0, 0, 0}};
double R_table_1_per[R_table_1_m][R_table_1_n] = {
{10, 33, 100, 332, 1*K, 3.32*K, 10.5*K, 34*K, 107*K, 357*K},
{10.2, 33.2, 102, 340, 1.02*K, 3.4*K, 10.7*K, 34.8*K, 110*K, 360*K},
{10.5, 34, 105, 348, 1.05*K, 3.48*K, 11*K, 35.7*K, 113*K, 365*K},
{10.7, 34.8, 107, 350, 1.07*K, 3.57*K, 11.3*K, 36*K, 115*K, 374*K},
{11, 35.7, 110, 357, 1.1*K, 3.6*K, 11.5*K, 36.5*K, 118*K, 383*K},
{11.3, 36, 113, 360, 1.13*K, 3.65*K, 11.8*K, 37.4*K, 120*K, 390*K},
{11.5, 36.5, 115, 365, 1.15*K, 3.74*K, 12*K, 38.3*K, 121*K, 392*K},
{11.8, 37.4, 118, 374, 1.18*K, 3.83*K, 12.1*K, 39*K, 124*K, 402*K},
{12, 38.3, 120, 383, 1.2*K, 3.9*K, 12.4*K, 39.2*K, 127*K, 412*K},
{12.1, 39, 121, 390, 1.21*K, 3.92*K, 12.7*K, 40.2*K, 130*K, 422*K},
{12.4, 39.2, 124, 392, 1.24*K, 4.02*K, 13*K, 41.2*K, 133*K, 430*K},
{12.7, 40.2, 127, 402, 1.27*K, 4.12*K, 13.3*K, 42.2*K, 137*K, 432*K},
{13, 41.2, 130, 412, 1.3*K, 4.22*K, 13.7*K, 43*K, 140*K, 442*K},
{13.3, 42.2, 133, 422, 1.33*K, 4.32*K, 14*K, 43.2*K, 143*K, 453*K},
{13.7, 43, 137, 430, 1.37*K, 4.42*K, 14.3*K, 44.2*K, 147*K, 464*K},
{14, 43.2, 140, 432, 1.4*K, 4.53*K, 14.7*K, 45.3*K, 150*K, 470*K},
{14.3, 44.2, 143, 442, 1.43*K, 4.64*K, 15*K, 46.4*K, 154*K, 475*K},
{14.7, 45.3, 147, 453, 1.47*K, 4.7*K, 15.4*K, 47*K, 158*K, 487*K},
{15, 46.4, 150, 464, 1.5*K, 4.75*K, 15.8*K, 47.5*K, 160*K, 499*K},
{15.4, 47, 154, 470, 1.54*K, 4.87*K, 16*K, 48.7*K, 162*K, 511*K},
{15.8, 47.5, 158, 475, 1.58*K, 4.99*K, 16.2*K, 49.9*K, 165*K, 523*K},
{16, 48.7, 160, 487, 1.6*K, 5.1*K, 16.5*K, 51*K, 169*K, 536*K},
{16.2, 49.9, 162, 499, 1.62*K, 5.11*K, 16.9*K, 51.1*K, 174*K, 549*K},
{16.5, 51, 165, 510, 1.65*K, 5.23*K, 17.4*K, 52.3*K, 178*K, 560*K},
{16.9, 51.1, 169, 511, 1.69*K, 5.36*K, 17.8*K, 53.6*K, 180*K, 562*K},
{17.4, 52.3, 174, 523, 1.74*K, 5.49*K, 18*K, 54.9*K, 182*K, 576*K},
{17.8, 53.6, 178, 536, 1.78*K, 5.6*K, 18.2*K, 56*K, 187*K, 590*K},
{18, 54.9, 180, 549, 1.8*K, 5.62*K, 18.7*K, 56.2*K, 191*K, 604*K},
{18.2, 56, 182, 560, 1.82*K, 5.76*K, 19.1*K, 57.6*K, 196*K, 619*K},
{18.7, 56.2, 187, 562, 1.87*K, 5.9*K, 19.6*K, 59*K, 200*K, 620*K},
{19.1, 57.6, 191, 565, 1.91*K, 6.04*K, 20*K, 60.4*K, 205*K, 634*K},
{19.6, 59, 196, 578, 1.96*K, 6.19*K, 20.5*K, 61.9*K, 210*K, 649*K},
{20, 60.4, 200, 590, 2*K, 6.2*K, 21*K, 62*K, 215*K, 665*K},
{20.5, 61.9, 205, 604, 2.05*K, 6.34*K, 21.5*K, 63.4*K, 220*K, 680*K},
{21, 62, 210, 619, 2.1*K, 6.49*K, 22*K, 64.9*K, 221*K, 681*K},
{21.5, 63.4, 215, 620, 2.15*K, 6.65*K, 22.1*K, 66.5*K, 226*K, 698*K},
{22, 64.9, 220, 634, 2.2*K, 6.8*K, 22.6*K, 68*K, 232*K, 715*K},
{22.1, 66.5, 221, 649, 2.21*K, 6.81*K, 23.2*K, 68.1*K, 237*K, 732*K},
{22.6, 68, 226, 665, 2.26*K, 6.98*K, 23.7*K, 69.8*K, 240*K, 750*K},
{23.2, 68.1, 232, 680, 2.32*K, 7.15*K, 24*K, 71.5*K, 243*K, 768*K},
{23.7, 69.8, 237, 681, 2.37, 7.32*K, 24.3*K, 73.2*K, 249*K, 787*K},
{24, 71.5, 240, 698, 2.4*K, 7.5*K, 24.9*K, 75*K, 255*K, 806*K},
{24.3, 73.2, 243, 715, 2.43*K, 7.68*K, 25.5*K, 76.8*K, 261*K, 820*K},
{24.7, 75, 249, 732, 2.49*K, 7.87*K, 26.1*K, 78.7*K, 267*K, 825*K},
{24.9, 75.5, 255, 750, 2.55*K, 8.06*K, 26.7*K, 80.6*K, 270*K, 845*K},
{25.5, 76.8, 261, 768, 2.61*K, 8.2*K, 27*K, 82*K, 274*K, 866*K},
{26.1, 78.7, 267, 787, 2.67*K, 8.25*K, 27.4*K, 82.5*K, 280*K, 887*K},
{26.7, 80.6, 270, 806, 2.7*K, 8.45*K, 28*K, 84.5*K, 287*K, 909*K},
{27, 82, 274, 820, 2.74*K, 8.66*K, 28.7*K, 86.6*K, 294*K, 910*K},
{27.4, 82.5, 280, 825, 2.8*K, 8.8*K, 29.4*K, 88.7*K, 300*K, 931*K},
{28, 84.5, 287, 845, 2.87*K, 8.87*K, 30*K, 90.9*K, 301*K, 953*K},
{28.7, 86.6, 294, 866, 2.94*K, 9.09*K, 30.1*K, 91*K, 309*K, 976*K},
{29.4, 88.7, 300, 887, 3.0*K, 9.1*K, 30.9*K, 93.1*K, 316*K, 1.0*M},
{30, 90.9, 301, 909, 3.01*K, 9.31*K, 31.6*K, 95.3*K, 324*K, 1.5*M},
{30.1, 91, 309, 910, 3.09*K, 9.53*K, 32.4*K, 97.6*K, 330*K, 2.2*M},
{30.9, 93.1, 316, 931, 3.16*K, 9.76*K, 33*K, 100*K, 332*K, 0},
{31.6, 95.3, 324, 953, 3.24*K, 10*K, 33.2*K, 102*K, 340*K, 0},
{32.4, 97.6, 330, 976, 3.3*K, 10.2*K, 33.6*K, 105*K, 348*K, 0}};
// CRsistor dialog
CRsistor::CRsistor(CWnd* pParent /*=NULL*/)
: CDialog(CRsistor::IDD, pParent)
{
//{{AFX_DATA_INIT(CRsistor)
m_SR1_Value = _T("");
m_SR2_Value = _T("");
m_SR1_Min = _T("0");
m_SR1_Max = _T("22M");
m_SR2_Max = _T("22M");
m_SR2_Min = _T("0");
m_SDispersion_Range = _T("100");
m_SBenchmark = _T("");
//}}AFX_DATA_INIT
}
void CRsistor::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRsistor)
DDX_Control(pDX, IDC_COMBO_R_Percision, m_CR_Percision);
DDX_Control(pDX, IDC_Display, m_CDisplay);
DDX_Text(pDX, IDC_R1_Value, m_SR1_Value);
DDX_Text(pDX, IDC_R2_Value, m_SR2_Value);
DDX_Text(pDX, IDC_R1_MIN, m_SR1_Min);
DDX_Text(pDX, IDC_R1_MAX, m_SR1_Max);
DDX_Text(pDX, IDC_R2_MAX, m_SR2_Max);
DDX_Text(pDX, IDC_R2_MIN, m_SR2_Min);
DDX_Text(pDX, IDC_R1_Dispersion_Range, m_SDispersion_Range);
DDX_Text(pDX, IDC_Benchmark, m_SBenchmark);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRsistor, CDialog)
//{{AFX_MSG_MAP(CRsistor)
ON_BN_CLICKED(IDC_BUTTON_Calculate, OnBUTTONCalculate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRsistor message handlers
struct R_search
{
double r1;
double r2;
double ratio;
double dispersion;
};
void CRsistor::OnBUTTONCalculate()
{
// TODO: Add your control notification handler code here
CRsistor resistor;
double r1,r2;
double ratio;
char ch_temp[18];
CString dis_tmp;
CString c_tmp;
double dispersion_range;
double benchmark;
UpdateData(TRUE);
//***** get r1 and r2 , calculate the ratio *****************
stoa(ch_temp, m_SR1_Value);
r1 = atof(ch_temp);
stoa(ch_temp, m_SR2_Value);
r2 = atof(ch_temp);
ratio = r1 / r2;
dis_tmp += "Ratio is : ";
c_tmp.Format("%.10f", ratio);
dis_tmp += c_tmp;
dis_tmp += "\r\n";
if(!m_SBenchmark.IsEmpty())
{
stoa(ch_temp, m_SBenchmark);
benchmark = atof(ch_temp);
benchmark = benchmark * ratio;
dis_tmp += "Ideal Value : ";
c_tmp.Format("%.10f", benchmark);
dis_tmp += c_tmp;
dis_tmp += "\r\n";
}
//****************************************************************
//*******阻值遍历*************************************************
struct R_search r_search[GOOD_NUM];
int i;
for(i=0; i<GOOD_NUM; i++)
{
r_search[i].dispersion = 100;
}
ransack(r_search, ratio);
if(m_SDispersion_Range.IsEmpty())
{
dispersion_range = 100.0;
}
else
{
stoa(ch_temp, m_SDispersion_Range);
dispersion_range = atof(ch_temp);
}
for(i=GOOD_NUM-1; i>=0; i--)
{
if(fabs(r_search[i].dispersion) < fabs(dispersion_range) )
{
dis_tmp += "R1 = ";
dis_tmp += ConvertToR(c_tmp, r_search[i].r1);
dis_tmp += " ";
dis_tmp += "R2 = ";
dis_tmp += ConvertToR(c_tmp, r_search[i].r2);
dis_tmp += " ";
dis_tmp += "DPN = ";
c_tmp.Format("%.3f", r_search[i].dispersion);
dis_tmp += c_tmp;
dis_tmp += "%";
if(!m_SBenchmark.IsEmpty())
{
stoa(ch_temp, m_SBenchmark);
benchmark = atof(ch_temp);
benchmark = benchmark * r_search[i].ratio;
dis_tmp += " Actual Value : ";
c_tmp.Format("%.6f", benchmark);
dis_tmp += c_tmp;
}
dis_tmp += " Ratio = ";
c_tmp.Format("%.6f", r_search[i].ratio);
dis_tmp += c_tmp;
dis_tmp += "\r\n";
}
}
//****************************************************************
SetDlgItemText(IDC_Display, dis_tmp);
}
float CRsistor::stof(CString str)
{
int dot_position;
int i;
int str_length;
char ch_temp_integer[18];
char ch_temp_decimal[18];
float result;
//float divisor;
str_length = str.GetLength();
dot_position = str.Find('.');
if(dot_position == -1)
{
for(i=0; i<str_length; i++)
{
ch_temp_integer[i] = str.GetAt(i);
}
ch_temp_integer[i] = '\0';
result = (float)atoi(ch_temp_integer);
}
else
{
for(i=0; i<dot_position; i++)
{
ch_temp_integer[i] = str.GetAt(i);
}
ch_temp_integer[i] = '\0';
for(i=dot_position+1; i<str_length; i++)
{
ch_temp_decimal[i] = str.GetAt(i);
}
ch_temp_decimal[i] = '\0';
result = (float)atoi(ch_temp_integer) + (float)atoi(ch_temp_decimal);
}
return result;
}
void CRsistor::stoa(char *target, CString str)
{
int str_length;
int i;
str_length = str.GetLength();
for(i=0; i<str_length; i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -