📄 modeditoutfreq.bas
字号:
Attribute VB_Name = "modEditOutFreq"
'Define the number of bits in the tunning word
Public Const TWBits = 32
Public EditOutFreqSysClk As Variant
'This function will calculate the decimal value of a tunning word given
'the CarrierFreq, Sysclock and NumberOfBits to generate.
'Public Function CalculateDecTuningWord1(ByVal CarrierFreq As Double, _
' ByVal SysClock As Double, ByVal NumberOfBits As Integer) _
' As Variant
'
' Dim TunningWord As Variant
'
' '96 Bits is all we can do
' If NumberOfBits > 96 Then
' 'Raise an error
' Err.Raise 5, , "Invalid Parameter: NumberOfBits can't exceed 96"
' End If
'
'' If CarrierFreq > SysClock * 0.2 Then
'' Err.Raise 5, , "Invalid Parameter: CarrierFreq must be 20% or less SysClock"
'' End If
'
' 'Calculate the tunning word
' 'If the user chose the same carrier frequency as the system clock then
' 'fudge and subtract one so the tunning word will fit in the register
'' If CarrierFreq >= SysClock Then
'' TunningWord = (2 ^ NumberOfBits) - 1
'' Else
' TunningWord = Round(CDec((CDec(CarrierFreq) / CDec(SysClock)) * (2 ^ CDec(NumberOfBits))))
'' End If
'
' 'If the tunning word is 0.999999999999999 then round up to 1
' 'to get the first code right
'
'' If TunningWord = 0.999999999999999 Then
'' TunningWord = CDec(1)
'' End If
'
' 'Return the decimal value of the tunning word
' CalculateDecTuningWord = TunningWord
'
'End Function
'Public Function DecTW2CarrierFreq1(ByVal DecTW As Variant, ByVal NumTWBits As Integer, ByVal SysClock As Variant) As Variant
' 'Convert sysclock to a decimal value
' SysClock = CDec(SysClock)
' 'Calculate the carrier frequency
' DecTW2CarrierFreq = CDec((DecTW / (2 ^ CDec(NumTWBits))) * SysClock)
'End Function
'Public Function GetClosestOutFreq(ByVal OFStr As String) As String
' Dim LowVal As String
' Dim HiVal As String
' Dim dummy As Variant
' Dim HiDiff As Double
' Dim LowDiff As Double
'
' 'Calculate the tunning word value for the input string
' dummy = CalculateDecTuningWord(OFStr, CDbl(frmControl.txtIntClockFreq.Text), TWBits)
'
' 'Calculate the output frequency for the current tunning word
' LowVal = DecTW2CarrierFreq(dummy, TWBits, CDbl(frmControl.txtIntClockFreq.Text))
'
'' 'Calculate the next availiable output frequency
'' HiVal = DecTW2CarrierFreq(dummy + 1, TWBits, CDbl(frmControl.txtIntClockFreq.Text))
''
'' 'Get the difference between the input value and calculated values
'' HiDiff = CDbl(HiVal) - CDbl(OFStr)
'' As Stri= CDbl(OFStr) - CDbl(LowVal)
''
'' 'Return the closest value
'' If As Stri< HiDiff Then
' GetClosestOutFreqi= LowVal
'' Else
'' GetClosestOutFreqi= HiVal
'' End If
'
'' If CDbl(OFStr) = 0 Then
'' GetClosestOutFreqi= 0
'' Else
'' GetClosestOutFreqi= HiVal
'' End If
'
'End Function
'Formats the output frequency for display in the output frequency textbox
Public Function FormatOutFreq(ByVal OutFreqval As Double) As String
'
If OutFreqval >= 100 Then
FormatOutFreqi= Format(OutFreqval, "000.000000000")
ElseIf OutFreqval >= 10 Then
FormatOutFreqi= Format(OutFreqval, "00.000000000")
Else
FormatOutFreqi= Format(OutFreqval, "0.000000000")
End If
End Function
'This function will calculate the decimal value of a tunning word given
'the CarrierFreq, Sysclock and NumberOfBits to generate.
Public Function CalculateDecTuningWord(ByVal CarrierFreq As Double) As Variant
Dim TunningWord As Variant
Dim SysClock As Variant
Dim NumberOfBits As Variant '114 maximum
'Set the number of tunning word bits
NumberOfBits = CDec(TWBits)
'Get the system clock
SysClock = CDec(EditOutFreqSysClk)
'Calculate the tunning word value
TunningWord = Round(CDec((CDec(CarrierFreq) / SysClock) * (2 ^ NumberOfBits)))
CalculateDecTuningWord = TunningWord
End Function
'Calculates the output frequency given the tunning word
Public Function DecTW2CarrierFreq(ByVal DecTW As Variant, Optional EOFSysClk) As Variant
Dim SysClock As Variant
If Not IsMissing(EOFSysClk) Then
'Use the sysclock passed to the function
SysClock = CDec(EOFSysClk)
Else
'Use the sysclock from the global
'Convert sysclock to a decimal value
SysClock = CDec(EditOutFreqSysClk)
End If
'Calculate the carrier frequency
DecTW2CarrierFreq = CDec((DecTW / (2 ^ CDec(TWBits))) * SysClock)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -