⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modmain.bas

📁 AD9954源码
💻 BAS
📖 第 1 页 / 共 5 页
字号:
    Dim CntrStart As Integer
    Dim CntrStop As Integer
    Dim CntrStep As Integer

    Dim FileType As String
    Dim FileRevNum As Double
    Dim TempDataStr As String
    Dim RSCW0Str As String
    Dim RSCW1Str As String
    Dim RSCW2Str As String
    Dim RSCW3Str As String
    Dim TmpProfile_DUT1 As Integer
    Dim TmpProfile_DUT2 As Integer

    Dim ModeCntrlRS0 As Integer
    Dim NoDwellRS0 As Integer
    Dim StartAddressRS0 As Integer
    Dim FinalAddressRS0 As Integer
    Dim AddressRampRateRS0 As Long

    Dim ModeCntrlRS1 As Integer
    Dim NoDwellRS1 As Integer
    Dim StartAddressRS1 As Integer
    Dim FinalAddressRS1 As Integer
    Dim AddressRampRateRS1 As Long

    Dim ModeCntrlRS2 As Integer
    Dim NoDwellRS2 As Integer
    Dim StartAddressRS2 As Integer
    Dim FinalAddressRS2 As Integer
    Dim AddressRampRateRS2 As Long

    Dim ModeCntrlRS3 As Integer
    Dim NoDwellRS3 As Integer
    Dim StartAddressRS3 As Integer
    Dim FinalAddressRS3 As Integer
    Dim AddressRampRateRS3 As Long

    Dim RamSegment0Data() As String
    Dim RamSegment1Data() As String
    Dim RamSegment2Data() As String
    Dim RamSegment3Data() As String

    Dim UseRS0 As Boolean
    Dim UseRS1 As Boolean
    Dim UseRS2 As Boolean
    Dim UseRS3 As Boolean
    Dim sRAMAddr As String

    Dim PrgCntr As String 'Progress cntr
    Dim UpdatePrgBar As Boolean

    'Setup an error handler
    On Error GoTo ErrorHandler:

    'Set the screen cursor to hourglass
    Screen.MousePointer = 11

    If EvalBd.Enabled = True Then
        'If writing to both DUTs make sure that both are in the same IOMode
        If (DUTNum <> 1 And DUTNum <> 2) And (EvalBd.LSBFirstDUT1 <> EvalBd.LSBFirstDUT2) Then
            'LSBFirst mode must be the same on both DUTs
            MsgBox "Error: To write to both DUT's simultaniously the LSB First bit must be the same for both DUTs.", vbApplicationModal, "Error: SUB RAMLoadFile()"
        Else
            'If the number of bytes to send is different than the number of bytes
            'present in the data passed then exit the sub
            If (FileExists(RamFile)) Then
                'Get a sharable file handle
                FileHandle = FreeFile(1)

                'Open the file
                Open RamFile For Input As #FileHandle

                'Read the file header back
                Input #FileHandle, FileType, FileRevNum
                'Make sure its a valid file
                If FileType = "AD9859 RAM Configuration File" And FileRevNum = 1 Then
                    'Trash the next 4 lines
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr

                    'Read the RSCW0 Info
                    Input #FileHandle, dummystr, ModeCntrlRS0
                    Input #FileHandle, dummystr, NoDwellRS0
                    Input #FileHandle, dummystr, StartAddressRS0
                    Input #FileHandle, dummystr, FinalAddressRS0
                    Input #FileHandle, dummystr, AddressRampRateRS0

                    'Trash 4 More Lines
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr

                    'Resize the array
                    ReDim RamSegment0Data((FinalAddressRS0 - StartAddressRS0) + 1)

                    'Read in the data from the file
                    For cntr = 1 To ((FinalAddressRS0 - StartAddressRS0) + 1)
                        'Read the binary data in
                        Input #FileHandle, sRAMAddr, DummyDbl, dummystr, TempDataStr
                        'If the first address is numeric then set the UseRS Variable
                        If cntr = 1 And IsNumeric(sRAMAddr) Then
                            UseRS0 = True
                        End If
                        If UseRS0 = False Then
                            'Don't bother loading the ram data from the file because
                            'it isn't used anyway
                            Exit For
                        End If
                        'Remove the spaces
                        RamSegment0Data(cntr - 1) = cbaseDec2Bin(DummyDbl, 32)
                    Next cntr

                    'Trash all data until the next RSC Section
                    Do
                        Input #FileHandle, dummystr
                    Loop Until dummystr = "BEGIN - RAM Segment 1"

                    'Read the RSCW1 Info
                    Input #FileHandle, dummystr, ModeCntrlRS1
                    Input #FileHandle, dummystr, NoDwellRS1
                    Input #FileHandle, dummystr, StartAddressRS1
                    Input #FileHandle, dummystr, FinalAddressRS1
                    Input #FileHandle, dummystr, AddressRampRateRS1

                    'Trash 4 More Lines
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr

                    'Resize the array
                    ReDim RamSegment1Data((FinalAddressRS1 - StartAddressRS1) + 1)

                    'Read in the data from the file
                    For cntr = 1 To ((FinalAddressRS1 - StartAddressRS1) + 1)
                        'Read the binary data in
                        Input #FileHandle, sRAMAddr, DummyDbl, dummystr, TempDataStr
                        'If the first address is numeric then set the UseRS Variable
                        If cntr = 1 And IsNumeric(sRAMAddr) Then
                            UseRS1 = True
                        End If
                        If UseRS1 = False Then
                            'Don't bother loading the ram data from the file because
                            'it isn't used anyway
                            Exit For
                        End If
                        'Remove the spaces
                        RamSegment1Data(cntr - 1) = cbaseDec2Bin(DummyDbl, 32)
                    Next cntr

                    'Trash all data until the next RSC Section
                    Do
                        Input #FileHandle, dummystr
                    Loop Until dummystr = "BEGIN - RAM Segment 2"

                    'Read the RSCW2 Info
                    Input #FileHandle, dummystr, ModeCntrlRS2
                    Input #FileHandle, dummystr, NoDwellRS2
                    Input #FileHandle, dummystr, StartAddressRS2
                    Input #FileHandle, dummystr, FinalAddressRS2
                    Input #FileHandle, dummystr, AddressRampRateRS2

                    'Trash 4 More Lines
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr

                    'Resize the array
                    ReDim RamSegment2Data((FinalAddressRS2 - StartAddressRS2) + 1)

                    'Read in the data from the file
                    For cntr = 1 To ((FinalAddressRS2 - StartAddressRS2) + 1)
                        'Read the binary data in
                        Input #FileHandle, sRAMAddr, DummyDbl, dummystr, TempDataStr
                        'If the first address is numeric then set the UseRS Variable
                        If cntr = 1 And IsNumeric(sRAMAddr) Then
                            UseRS2 = True
                        End If
                        If UseRS2 = False Then
                            'Don't bother loading the ram data from the file because
                            'it isn't used anyway
                            Exit For
                        End If
                        'Remove the spaces
                        RamSegment2Data(cntr - 1) = cbaseDec2Bin(DummyDbl, 32)
                    Next cntr

                    'Trash all data until the next RSC Section
                    Do
                        Input #FileHandle, dummystr
                    Loop Until dummystr = "BEGIN - RAM Segment 3"

                    'Read the RSCW3 Info
                    Input #FileHandle, dummystr, ModeCntrlRS3
                    Input #FileHandle, dummystr, NoDwellRS3
                    Input #FileHandle, dummystr, StartAddressRS3
                    Input #FileHandle, dummystr, FinalAddressRS3
                    Input #FileHandle, dummystr, AddressRampRateRS3

                    'Trash 4 More Lines
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr
                    Input #FileHandle, dummystr

                    'Resize the array
                    ReDim RamSegment3Data((FinalAddressRS3 - StartAddressRS3) + 1)

                    'Read in the data from the file
                    For cntr = 1 To ((FinalAddressRS3 - StartAddressRS3) + 1)
                        'Read the binary data in
                        Input #FileHandle, sRAMAddr, DummyDbl, dummystr, TempDataStr
                        'If the first address is numeric then set the UseRS Variable
                        If cntr = 1 And IsNumeric(sRAMAddr) Then
                            UseRS3 = True
                        End If
                        If UseRS3 = False Then
                            'Don't bother loading the ram data from the file because
                            'it isn't used anyway
                            Exit For
                        End If
                        'Remove the spaces
                        RamSegment3Data(cntr - 1) = cbaseDec2Bin(DummyDbl, 32)
                    Next cntr
                    ' Close before reopening in another mode.
                    Close #FileHandle

                    '*** All data was read correctly - Now Program The DUT(s) ****
                    'First program the RSCW Registers
                    'Build the binary string for the RSCW in MSB format
                    'RAMSegmentAddressRampRate<7:0> + RAMSegmentAddressRampRate<15:8> +
                    'RAMSegmentFinalAddress<7:0> +
                    'RAMSegmentBeginningAddress<5:0> + RAMSegmentFinalAddress<9:8>
                    'RAMSegmentModeControl + NoDwellActive + RAMSegmentBeginningAddress<9:6>
                    RSCW0Str = Right(cbaseDec2Bin(AddressRampRateRS0, 16), 8) & _
                                  Left(cbaseDec2Bin(AddressRampRateRS0, 16), 8) & _
                                  Right(cbaseDec2Bin(FinalAddressRS0, 10), 8) & _
                                  Right(cbaseDec2Bin(StartAddressRS0, 10), 6) & _
                                  Left(cbaseDec2Bin(FinalAddressRS0, 10), 2) & _
                                  cbaseDec2Bin(ModeCntrlRS0, 3) & cbaseDec2Bin(NoDwellRS0, 1) & _
                                  Left(cbaseDec2Bin(StartAddressRS0, 10), 4)

'                    Debug.Print "RSCW0"
'                    PrintDecodedRSCW RSCW0Str

                    'Calculate the RSCW1 Register
                    RSCW1Str = Right(cbaseDec2Bin(AddressRampRateRS1, 16), 8) & _
                                  Left(cbaseDec2Bin(AddressRampRateRS1, 16), 8) & _
                                  Right(cbaseDec2Bin(FinalAddressRS1, 10), 8) & _
                                  Right(cbaseDec2Bin(StartAddressRS1, 10), 6) & _
                                  Left(cbaseDec2Bin(FinalAddressRS1, 10), 2) & _
                                  cbaseDec2Bin(ModeCntrlRS1, 3) & cbaseDec2Bin(NoDwellRS1, 1) & _
                                  Left(cbaseDec2Bin(StartAddressRS1, 10), 4)

'                    Debug.Print "RSCW1"
'                    PrintDecodedRSCW RSCW1Str

                    'Calculate the RSCW2 Register
                    RSCW2Str = Right(cbaseDec2Bin(AddressRampRateRS2, 16), 8) & _
                                  Left(cbaseDec2Bin(AddressRampRateRS2, 16), 8) & _
                                  Right(cbaseDec2Bin(FinalAddressRS2, 10), 8) & _
                                  Right(cbaseDec2Bin(StartAddressRS2, 10), 6) & _
                                  Left(cbaseDec2Bin(FinalAddressRS2, 10), 2) & _
                                  cbaseDec2Bin(ModeCntrlRS2, 3) & cbaseDec2Bin(NoDwellRS2, 1) & _
                                  Left(cbaseDec2Bin(StartAddressRS2, 10), 4)

'                    Debug.Print "RSCW2"
'                    PrintDecodedRSCW RSCW2Str

                    'Calculate the RSCW2 Register
                    RSCW3Str = Right(cbaseDec2Bin(AddressRampRateRS3, 16), 8) & _
                                  Left(cbaseDec2Bin(AddressRampRateRS3, 16), 8) & _
                                  Right(cbaseDec2Bin(FinalAddressRS3, 10), 8) & _
                                  Right(cbaseDec2Bin(StartAddressRS3, 10), 6) & _
                                  Left(cbaseDec2Bin(FinalAddressRS3, 10), 2) & _
                                  cbaseDec2Bin(ModeCntrlRS3, 3) & cbaseDec2Bin(NoDwellRS3, 1) & _
                                  Left(cbaseDec2Bin(StartAddressRS3, 10), 4)

'                    Debug.Print "RSCW3"
'                    PrintDecodedRSCW RSCW3Str

                    '*** Now Load the RAM Data into the RAM for RSCW0 ***
                    'Store the old profile
                    TmpProfile_DUT1 = EvalBd.GetActiveProfile(1)
                    TmpProfile_DUT2 = EvalBd.GetActiveProfile(2)

                    'Write to the RSCW0 Register
                    EvalBd.SerialLoad DUTNum, &H7, RSCW0Str
                    'Set the profile to write to the correct RAM Segment

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -