Attribute VB_Name = "modShaping" Option Explicit '========================================================= '==== Shaping ============================================ '========================================================= Public Const MAXPEAKINGTIMES = 26 Public Const MAXPEAKINGTIMES_20MHZ = MAXPEAKINGTIMES - 2 Public Const MAXPEAKINGTIMES_80MHZ = MAXPEAKINGTIMES Public b80MHzModeCfg As Boolean Public b80MHzModeCfg_old As Boolean ' 0. read config values (from file or hw) ' 1. default is 20MHz FPGA Clock (CLCK=fpga clock),(fpga clock MODE=b80MHzModeCfg) ' 2. FPGA Clock is read BEFORE peaking time is set (TPEA=peaking time) ' 3. if no CLCK found or is AUTO then default fpga clock MODE is 20MHz (b80MHzModeCfg=false) ' 4. if the CLCK is set to 80 then fpga clock MODE is 80MHz (b80MHzModeCfg=true) ' 5. b80MHzModeCfg MUST be determined BEFORE peaking/flattop combobox values are generated ' 6. for CLCK=AUTO and TPEA>=5Us then b80MHzModeCfg=false(20mhz) ' 7. for CLCK=AUTO and TPEA<5Us then b80MHzModeCfg=true(80mhz) ' 8. if CLCK=20 or CLCK=80 then b80MHzModeCfg=false(20mhz) or b80MHzModeCfg=true(80mhz) ' 9. set peaking time combo using b80MHzModeCfg '10. search for closest peaking value index, update (hidden text value) '11. calculate flattop combo values using '12. search for closet flattop, update (hidden text value) 'the fpga clock speed determines the multiplier for calulating the combobox peaking times 'the fpga clock speed can (and should) be read from the hardware if connected 'GetFPGAClockMode is needed when no dpp device is attached and a configuration is being generated Public Function GetFPGAClockMode(strCLCK As String, strTPEA As String) As Boolean Dim is80MHz As Boolean Dim dblPeaking As Double Dim dblCLCK As Double Dim isAuto As Boolean Dim inRange As Boolean isAuto = CBool("AUTO" = strCLCK) 'true=the clock is not known dblPeaking = CDbl(Val(strTPEA)) dblCLCK = CDbl(Val(strCLCK)) is80MHz = False 'default=20MHz FPGA Clock mode If (isAuto) Then 'use TPEA to determine fpga clock If (dblPeaking < 5#) Then 'dblPeaking is uS, TPEA<5Us=fpga 80MHz mode is80MHz = True 'fpga clock MODE=80MHz End If Else If (dblCLCK = 80) Then 'clock setting is80MHz = True 'fpga clock MODE= End If End If '''' 'the clock should be set, test the clock to verify it matches TPEA '''' inRange = False '''' If (isAuto) Then 'if auto, the clock was already set by TPEA '''' inRange = True '''' Else '''' If (is80MHz) Then 'TPEA 80MHz Range (0.050-25.600) '''' If (dblPeaking >= 0.05) And (dblPeaking <= 25.6) Then '''' inRange = True '''' End If '''' Else 'TPEA 20MHz Range (0.800-102.400) '''' If (dblPeaking >= 0.8) And (dblPeaking <= 102.4) Then '''' inRange = True '''' End If '''' End If '''' End If GetFPGAClockMode = is80MHz End Function ' 9. set peaking time combo using b80MHzModeCfg '10. search for closest peaking value index, update (hidden text value) '11. calculate flattop combo values using '12. search for closet flattop, update (hidden text value) 'Private Sub cmdFlattopSearch_Click() ' txtFlattopFound = "0.000" ' SetShapingIndex cboFlatTop, txtFlattopSearch ' If (cboFlatTop.ListIndex <> LB_ERR) Then ' txtFlattopFound = cboFlatTop.List(cboFlatTop.ListIndex) ' End If 'End Sub ' 'Private Sub cmdPeakingSearch_Click() ' txtPeakingFound = "0.000" ' SetShapingIndex cboRise, txtPeakingSearch ' If (cboRise.ListIndex <> LB_ERR) Then ' txtPeakingFound = cboRise.List(cboRise.ListIndex) ' End If 'End Sub Public Sub cboRiseUpdate(cboRise As ComboBox, cboFlatTop As ComboBox, is80MHz As Boolean) Dim Decimation As Integer Dim idxFlattop As Integer Dim idx As Integer Dim strVal As String If (cboRise.ListCount > 0) Then Decimation = SetRiseAndAvg(cboRise.ListIndex, is80MHz) End If 'idxFlattop = cboFlatTop.ListIndex If (idxFlattop < 0) Then idxFlattop = 0 GetFlattopValues cboFlatTop, Decimation, idxFlattop, is80MHz strVal = "" If (cboFlatTop.ListCount > 0) Then For idx = 0 To (cboFlatTop.ListCount - 1) strVal = strVal & cboFlatTop.List(idx) & vbNewLine Next 'txtFlattop = strVal End If End Sub Public Sub LoadPeakingValues(cboRise As ComboBox, cboFlatTop As ComboBox, is80MHz As Boolean) Dim Decimation As Integer Dim idx As Integer Dim strVal As String SetComboRiseValues cboRise, is80MHz strVal = "" If (cboRise.ListCount > 0) Then For idx = 0 To (cboRise.ListCount - 1) strVal = strVal & cboRise.List(idx) & vbNewLine Next 'txtRise = strVal cboRise.ListIndex = 0 End If Decimation = SetRiseAndAvg(cboRise.ListIndex, is80MHz) GetFlattopValues cboFlatTop, Decimation, 0, is80MHz strVal = "" If (cboFlatTop.ListCount > 0) Then For idx = 0 To (cboFlatTop.ListCount - 1) strVal = strVal & cboFlatTop.List(idx) & vbNewLine Next 'txtFlattop = strVal cboRise.ListIndex = 0 End If End Sub Public Sub SetShapingIndex(cboShaping As ComboBox, strShapingIn As String) Dim ListIndex As Long Dim strShaping As String Dim idxShaping As Long Dim dblShapingIn As Double Dim dblShapingMin As Double Dim dblShapingMax As Double If (cboShaping.ListCount < 2) Then Exit Sub 'Shaping value error ListIndex = LB_ERR dblShapingIn = CDbl(Val(strShapingIn)) 'test min strShaping = Format(dblShapingIn, "0.000") 'format like cbo values ListIndex = FindCboIdxExact(cboShaping, strShaping) 'search for exact value If (ListIndex = LB_ERR) Then ListIndex = FindCboIdx(cboShaping, strShaping) 'search for similar value End If If (ListIndex = LB_ERR) Then 'find closet value by comparison dblShapingMin = CDbl(Val(cboShaping.List(0))) 'Shaping min dblShapingMax = CDbl(Val(cboShaping.List(cboShaping.ListCount - 1))) 'Shaping max If (dblShapingIn <= dblShapingMin) Then 'test min ListIndex = 0 ElseIf (dblShapingIn >= dblShapingMax) Then 'test max ListIndex = cboShaping.ListCount - 1 Else 'test in range For idxShaping = 0 To cboShaping.ListCount - 2 dblShapingMin = CDbl(Val(cboShaping.List(idxShaping))) 'Shaping range min dblShapingMax = CDbl(Val(cboShaping.List(idxShaping + 1))) 'Shaping range max If ((dblShapingIn >= dblShapingMin) And (dblShapingIn <= dblShapingMax)) Then ListIndex = idxShaping Exit For End If Next End If End If If ((ListIndex > LB_ERR) And (ListIndex < cboShaping.ListCount)) Then cboShaping.ListIndex = ListIndex End If End Sub Public Sub GetFlattopValues(cboFlatTop As ComboBox, DecimationIn As Integer, FlatTop As Integer, is80MHz As Boolean) Dim idxFlattop As Integer Dim dblPeakingMult As Double Dim Decimation As Integer If (is80MHz) Then dblPeakingMult = 0.25 Else dblPeakingMult = 1# End If Decimation = DecimationIn - 1 ' adjust to use px4 algorithm cboFlatTop.Clear For idxFlattop = 1 To 8 cboFlatTop.AddItem Trim(Format(CDbl(idxFlattop) * 0.05 * (2# ^ Decimation) * dblPeakingMult, "0.000") + "uS") Next For idxFlattop = 9 To 62 If ((idxFlattop Mod 4) = 0) Then cboFlatTop.AddItem Trim(Format(CDbl(idxFlattop) * 0.05 * (2# ^ Decimation) * dblPeakingMult, "0.000") + "uS") End If Next cboFlatTop.AddItem Trim(Format(CDbl(63#) * 0.05 * (2# ^ Decimation) * dblPeakingMult, "0.000") + "uS") cboFlatTop.ListIndex = FlatTop End Sub Public Sub SetComboRiseValues(cboRise As ComboBox, is80MHz As Boolean) Dim idxRise As Integer Dim Decimation As Integer Dim dblPeakingMult As Double cboRise.Clear If (is80MHz) Then dblPeakingMult = 0.25 cboRise.AddItem Format((CDbl(1) * 0.2 * dblPeakingMult), "0.000") + "uS" cboRise.AddItem Format((CDbl(2) * 0.2 * dblPeakingMult), "0.000") + "uS" Else dblPeakingMult = 1# End If For idxRise = 1 To 8 cboRise.AddItem Format((CDbl(idxRise) * 0.8 * dblPeakingMult), "0.000") + "uS" Next For Decimation = 1 To 4 For idxRise = 5 To 8 cboRise.AddItem Format((CDbl(idxRise) * 0.8 * (2# ^ Decimation) * dblPeakingMult), "0.000") + "uS" Next Next End Sub Public Function CheckRangeCDbl(TestVal As Single, MinVal As Single, MaxVal As Single) CheckRangeCDbl = CBool((TestVal >= MinVal) And (TestVal <= MaxVal)) End Function Private Function GetRiseTextValue(RiseIndex As Long, is80MHz As Boolean, isRiseAveCalc As Boolean) As String Dim idxRiseText As Long Dim idxAve As Long Dim idxX As Long Dim RiseTextArray(MAXPEAKINGTIMES - 1) As String Dim strMsg As String Dim dblPeakingMult As Double If (isRiseAveCalc) Then dblPeakingMult = 1# 'always use 20mhz values for riseave calcs ElseIf (is80MHz) Then dblPeakingMult = 0.25 Else dblPeakingMult = 1# End If strMsg = "" If ((RiseIndex < 0) Or (RiseIndex >= MAXPEAKINGTIMES)) Then Exit Function idxRiseText = -1 If (is80MHz) Then For idxX = 1 To 2 idxRiseText = idxRiseText + 1 If (isRiseAveCalc) Then 'create valid 20mhz values for 80mhz rise ave RiseTextArray(idxRiseText) = CStr(CDbl(1) * 0.8 * dblPeakingMult) + "uS" Else 'create real 80mhz values RiseTextArray(idxRiseText) = CStr(CDbl(idxX) * 0.2 * dblPeakingMult) + "uS" End If strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine Next idxX End If For idxX = 1 To 8 idxRiseText = idxRiseText + 1 RiseTextArray(idxRiseText) = CStr(CDbl(idxX) * 0.8 * dblPeakingMult) + "uS" strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine Next idxX For idxAve = 1 To 4 strMsg = "" For idxX = 5 To 8 idxRiseText = idxRiseText + 1 RiseTextArray(idxRiseText) = CStr(CDbl(idxX) * 0.8 * (2# ^ idxAve) * dblPeakingMult) + "uS" strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine Next idxX Next idxAve If (Not is80MHz) Then 'fill array with valid values For idxX = 1 To 2 idxRiseText = idxRiseText + 1 RiseTextArray(idxRiseText) = CStr(CDbl(8) * 0.8 * (2# ^ 4) * dblPeakingMult) + "uS" strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine Next End If GetRiseTextValue = RiseTextArray(RiseIndex) End Function 'Sets Rise and Avg global values from stored combobox index 'FlatTop = FlatTop combobox control index value Public Function SetRiseAndAvg(RiseIndex As Long, is80MHz As Boolean) As Integer Dim strRiseText As String Dim SngRiseVal As Single Dim Rise As Integer Dim Avg As Integer If ((RiseIndex < 0) Or (RiseIndex >= MAXPEAKINGTIMES)) Then Exit Function strRiseText = GetRiseTextValue(RiseIndex, is80MHz, True) 'uses value 20mhz only SngRiseVal = CDbl(Val(strRiseText)) If CheckRangeCDbl(SngRiseVal, 0, 6.4) Then Rise = SngRiseVal / 0.8 Avg = 1 ElseIf CheckRangeCDbl(SngRiseVal, 8, 12.8) Then Rise = SngRiseVal / 1.6 Avg = 2 ElseIf CheckRangeCDbl(SngRiseVal, 16, 25.6) Then Rise = SngRiseVal / 3.2 Avg = 3 ElseIf CheckRangeCDbl(SngRiseVal, 32, 51.2) Then Rise = SngRiseVal / 6.4 Avg = 4 ElseIf CheckRangeCDbl(SngRiseVal, 64, 102.4) Then Rise = SngRiseVal / 12.8 Avg = 5 End If SetRiseAndAvg = Avg End Function '========================================================= '==== Shaping ============================================ '=========================================================