#include "stdafx.h" #include ".\dppshaping.h" //@doc CDppShaping CDppShaping::CDppShaping(void) { dblPeakingMult = 1.0; b80MHzMode = false; } CDppShaping::~CDppShaping(void) { } void CDppShaping::Set80MHzMode(BOOL is80Mhz) { if (is80Mhz) { dblPeakingMult = 0.25; b80MHzMode = true; } else { dblPeakingMult = 1.0; b80MHzMode = false; } } //@mfunc Pulse Shaping Control Setup and Initialization. //@parm Rise Option Control //@parm FlatTop Option Control void CDppShaping::Shaping_Setup(CComboBox *cboRiseObj, CComboBox *cboTopObj) { int i; int intAvg; cboRise = cboRiseObj; //set pointers to ctrl objects cboTop = cboTopObj; cboRise->ResetContent(); mAvg = 1; //default avg val // Changed peaking time/decimation combinations 5/6/02 //For i = 1 To 15 CString strTemp; if (b80MHzMode) { // 50/100 shaping update strTemp.Format("%.3f",(1.0 * 0.2) * dblPeakingMult); cboRise->AddString(strTemp); strTemp.Format("%.3f",(2.0 * 0.2) * dblPeakingMult); cboRise->AddString(strTemp); } // 50/100 shaping update for (i=1; i<=8; i++) { strTemp.Format("%.3f",(i * 0.8) * dblPeakingMult); cboRise->AddString(strTemp); //MessageBox(NULL,strTemp," ",MB_OK); } for (intAvg=1; intAvg<=4; intAvg++) { for (i=5; i<=8; i++) { strTemp.Format("%.3f",(i * 0.8 * pow(2.0,intAvg)) * dblPeakingMult); cboRise->AddString(strTemp); } } //clsConfig.Avg cboRise->SetCurSel(0); cboTop->SetCurSel(0); mFlatTop = 0; SetRiseCombo(); } //@mfunc Calculate Rise display text from a Rise combobox control index. //@parm Rise combobox control index //@rdesc Rise display text value string CString CDppShaping::GetRiseValueFromIndex(int RiseIndex, BOOL isRiseAveCalc = FALSE) { long idxRiseText; long idxAve; long idxX; CString RiseTextArray[MAXPEAKINGTIMES]; CString strMsg; double dblPeakingMult; if (isRiseAveCalc) { dblPeakingMult = 1.0; //always use 20mhz values for riseave calcs } else if (b80MHzMode) { dblPeakingMult = 0.25; } else { dblPeakingMult = 1.0; } strMsg = ""; if ((RiseIndex < 0) || (RiseIndex >= MAXPEAKINGTIMES)) { return strMsg; } idxRiseText = -1; if (b80MHzMode) { for(idxX=1;idxX<=2;idxX++) { idxRiseText++; if (isRiseAveCalc) { //create valid 20mhz values for 80mhz rise ave' RiseTextArray[idxRiseText].Format("%.3f",(1.0 * 0.8 * dblPeakingMult)); } else { //create real 80mhz values RiseTextArray[idxRiseText].Format("%.3f",((double)(idxX) * 0.2 * dblPeakingMult)); } strMsg += RiseTextArray[idxRiseText] + "\r\n"; } } for(idxX=1;idxX<=8;idxX++) { idxRiseText++; RiseTextArray[idxRiseText].Format("%.3f",((double)(idxX) * 0.8 * dblPeakingMult)); strMsg += RiseTextArray[idxRiseText] + "\r\n"; } for(idxAve=1;idxAve<=4;idxAve++) { for(idxX=5;idxX<=8;idxX++) { idxRiseText++; RiseTextArray[idxRiseText].Format("%.3f",((double)(idxX) * 0.8 * pow(2.0,idxAve)) * dblPeakingMult); strMsg += RiseTextArray[idxRiseText] + "\r\n"; } } if (! b80MHzMode) { //fill rest of array with valid (largest) value for(idxX=1;idxX<=2;idxX++) { idxRiseText++; RiseTextArray[idxRiseText].Format("%.3f",((double)(8) * 0.8 * pow(2.0,4)) * dblPeakingMult); strMsg += RiseTextArray[idxRiseText] + "\r\n"; } } if (RiseIndex > idxRiseText) { return RiseTextArray[idxRiseText]; } return RiseTextArray[RiseIndex]; } // get the closest value less than or equal to the selected flattop CString CDppShaping::GetDefaultFlatTopFromRiseIndex(int RiseIndex, double dblFlatTop) { int i; CString strTop(""); CString strTemp(""); // local copies used in calculating flattops for resolution tests int mRise; //risetime register setting int mAvg; //holds decimation setting for pulse shaping bool bDone=false; CString strLowest(""); double dblRiseVal; dblRiseVal = atof(GetRiseValueFromIndex(RiseIndex, TRUE)); if ((dblRiseVal >= 0) && (dblRiseVal <= 6.4001)) { // Case 0 To 6.4 mRise = (int)((dblRiseVal+0.0001) / 0.8); mAvg = 1; } else if ((dblRiseVal >= 8) && (dblRiseVal <= 12.8001)) { // Case 8 To 12.8 mRise = (int)((dblRiseVal+0.0001) / 1.6); mAvg = 2; } else if ((dblRiseVal >= 16) && (dblRiseVal <= 25.6001)) { // Case 16 To 25.6; mRise = (int)((dblRiseVal+0.0001) / 3.2); mAvg = 3; } else if ((dblRiseVal >= 32) && (dblRiseVal <= 51.2001)) { // Case 32 To 51.2 mRise = (int)((dblRiseVal+0.0001) / 6.4); mAvg = 4; } else if ((dblRiseVal >= 64) && (dblRiseVal <= 102.4001)) { // Case 64 To 102.4 mRise = (int)((dblRiseVal+0.0001) / 12.8); mAvg = 5; } strLowest = dbl_to_uS(((0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); if (atof(strLowest) >= dblFlatTop) { strTop = strLowest; bDone = true; } if (!bDone) { // skip any more calcs if have results for(i=1;i<=8;i++) { // create new list if (bDone) { break; }; strTemp = dbl_to_uS((((double)i * 0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); if (atof(strTemp) <= dblFlatTop) { strTop = strTemp; } else { bDone = true; } } } if (!bDone) { // skip any more calcs if have results for(i=9;i<=62;i++) { // create new list if (bDone) { break; }; if ((i % 4) == 0) { strTemp = dbl_to_uS((((double)i * 0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); if (atof(strTemp) <= dblFlatTop) { strTop = strTemp; } else { bDone = true; } } } } if (!bDone) { // skip any more calcs if have results strTop = dbl_to_uS(((63.0 * 0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); if (atof(strTemp) <= dblFlatTop) { strTop = strTemp; } else { bDone = true; } } if (strTop.GetLength() == 0) { // value wasn't found, assign lowest value available strTop = strLowest; // this should never happen } return strTop; } double CDppShaping::GetDblValFromComboText(CComboBox *m_ComboBoxCtrl) { int int_strlen; double dblVal; CString strText(""); m_ComboBoxCtrl->GetLBText(m_ComboBoxCtrl->GetCurSel(),strText); // get cbo text at the current position strText.TrimLeft(); strText.TrimRight(); strText = strText; // remove whitespace bebore checking size int_strlen = strText.GetLength(); // get the len to determine substring char *stopch; dblVal = strtod(strText.Mid(0,int_strlen-2),&stopch); return dblVal; } void CDppShaping::SetRiseCombo() { int i; float dblRiseVal; CString strTop(""); int RiseIdx; CString strTopFMT; CString temp; CString strFtAll; strFtAll = ""; RiseIdx = cboRise->GetCurSel(); dblRiseVal = (float)atof(GetRiseValueFromIndex(RiseIdx,TRUE)); if ((dblRiseVal >= 0) && (dblRiseVal <= 6.4001)) { // Case 0 To 6.4 mRise = (int)((dblRiseVal+0.0001) / 0.8); mAvg = 1; } else if ((dblRiseVal >= 8) && (dblRiseVal <= 12.8001)) { // Case 8 To 12.8 mRise = (int)((dblRiseVal+0.0001) / 1.6); mAvg = 2; } else if ((dblRiseVal >= 16) && (dblRiseVal <= 25.6001)) { // Case 16 To 25.6; mRise = (int)((dblRiseVal+0.0001) / 3.2); mAvg = 3; } else if ((dblRiseVal >= 32) && (dblRiseVal <= 51.2001)) { // Case 32 To 51.2 mRise = (int)((dblRiseVal+0.0001) / 6.4); mAvg = 4; } else if ((dblRiseVal >= 64) && (dblRiseVal <= 102.4001)) { // Case 64 To 102.4 mRise = (int)((dblRiseVal+0.0001) / 12.8); mAvg = 5; } cboTop->ResetContent(); cboTop->ResetContent(); for(i=1;i<=8;i++) { // create new list strTop = dbl_to_uS((((double)i * 0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); cboTop->AddString(strTop); } for(i=9;i<=62;i++) { // create new list if ((i % 4) == 0) { strTop = dbl_to_uS((((double)i * 0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); cboTop->AddString(strTop); } } strTop = dbl_to_uS(((63.0 * 0.05 * pow(2.0,(mAvg-1))) * dblPeakingMult)); cboTop->AddString(strTop); cboTop->SetCurSel(0); mFlatTop = 0; } CString CDppShaping::dbl_to_uS(double dblVal) { //unsigned char t; unsigned long l; unsigned long ul; CString strInt; CString strDec; CString strVal; ul = (unsigned long)(dblVal * 1000.0); l = ul / 1000; // convert to integer uS strInt.Format("%lu", l); // output integer portion in uS strDec.Format(".%03lu", ul - (l * 1000)); // output 3 chars right of decimal point strVal = strInt + strDec; return strVal; } //clsDialogs.DPPTop calls SetTopCombo (the ctrl calls DPPTop) //if top selection is made assign value to top var //@mfunc Sets FlatTop value from the FlatTop combobox selection. // //@comm This sub is used with the cboTop control click event. // //@ex Calling SetTopCombo from a control | // //Private Sub cboTop_click() // clsRise.SetTopCombo // dlgDPPCONFIG.FlatTop = clsRise.FlatTop //} void CDppShaping::SetTopCombo() { CString strTop(""); double dblTopVal; dblTopVal = GetDblValFromComboText(cboTop); mFlatTop = cboTop->GetCurSel(); if (mFlatTop < 0) { mFlatTop = 0; } }