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

📄 cls9858evbd1.cls

📁 AD9954源码
💻 CLS
📖 第 1 页 / 共 3 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cls9858EVBD"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Description = "AD9858 Evaluation Board Class - Models the AD9858 Evaluation board."
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'*******************************************************
'* Enums                                               *
'*******************************************************
Public Enum adiBinValues
    abvLow = 0
    abvHigh = 1
End Enum
 
Public Enum evbdComMode
    Parallel = 0
    Serial = 1
End Enum

Public Enum evbdSerMode
    TwoWire = 0
    ThreeWire = 1
End Enum

Public Enum evbBuffs
    evbDataBuffer = 0    'U5
    evbAddressBuffer = 1 'U7
    evbControlBuffer = 2 'U8
End Enum

Public Enum evbBits
    evbBit0 = 0
    evbBit1 = 1
    evbBit2 = 2
    evbBit3 = 3
    evbBit4 = 4
    evbBit5 = 5
    evbBit6 = 6
    evbBit7 = 7
End Enum

'*******************************************************
'* Constants                                           *
'*******************************************************
'Bit Number Constants for the signals on the
'parallel port's data port
Const bnD0 = 0
Const bnD1 = 1
Const bnD2 = 2
Const bnD3 = 3
Const bnD4 = 4
Const bnD5 = 5
Const bnD6 = 6
Const bnD7 = 7

Const bnA0_SDIO = 0
Const bnA1 = 1
Const bnA2_IOReset = 2
Const bnA3 = 3
Const bnA4 = 4
Const bnA5 = 5

Const bnPS0 = 0
Const bnPS1 = 1
Const bnSPMode = 2
Const bnReset = 3
Const bnFUD = 4
Const bnWRB_SCLK = 5
Const bnRDB_CSB = 6

'Bit Number Constants for the signals on the
'parallel port's status port
Const bnSDO = 3

'Bit Number Constants for the signals on the
'parallel port's Control port
Const bnClockD = 0
Const bnClockA = 1
Const bnRB_Enable = 2
Const bnClockF = 3

'Define the serial mode register names which index the
'lookup table above
Const smCFR = &H0
Const smDFTW = &H1
Const smDFRRW = &H2
Const smFTW0 = &H3
Const smPOW0 = &H4
Const smFTW1 = &H5
Const smPOW1 = &H6
Const smFTW2 = &H7
Const smPOW2 = &H8
Const smFTW3 = &H9
Const smPOW3 = &HA
Const smDAC_CTRL = &HB
Const smTR0 = &HC
Const smTR1 = &HD
Const smTR2 = &HE

'*******************************************************
'local variable(s) to hold property value(s)           *
'*******************************************************
Private mvarD0 As adiBinValues 'local copy
Private mvarD1 As adiBinValues 'local copy
Private mvarD2 As adiBinValues 'local copy
Private mvarD3 As adiBinValues 'local copy
Private mvarD4 As adiBinValues 'local copy
Private mvarD5 As adiBinValues 'local copy
Private mvarD7 As adiBinValues 'local copy
Private mvarA0_SDIO As adiBinValues 'local copy
Private mvarA1 As adiBinValues 'local copy
Private mvarA2_IOReset As adiBinValues 'local copy
Private mvarA3 As adiBinValues 'local copy
Private mvarA4 As adiBinValues 'local copy
Private mvarA5 As adiBinValues 'local copy
Private mvarSDI As adiBinValues 'local copy
Private mvarPS0 As adiBinValues 'local copy
Private mvarPS1 As adiBinValues 'local copy
Private mvarSPMode As adiBinValues 'local copy
Private mvarReset As adiBinValues 'local copy
Private mvarFUD As adiBinValues 'local copy
Private mvarWRB_SCLK As adiBinValues 'local copy
Private mvarRDB_CSB As adiBinValues 'local copy
Private mvarSDO As adiBinValues 'local copy
Private mvarClock_D As adiBinValues 'local copy
Private mvarClock_A As adiBinValues 'local copy
Private mvarRB_Enable As adiBinValues 'local copy
Private mvarClock_F As adiBinValues 'local copy
Private mvarD6 As adiBinValues 'local copy
Private mvarEnabled As Boolean 'local copy
Private mvarLSBFirst As Boolean 'local copy

'Delcare the LPTIO class
Private PPIO As clsLPTIO

'These variables store the values last latched into the latches
'U5,U7,U8 on the Evaluation Board
Private evbBuffers(0 To 2) As Integer
Private evbBitVals(0 To 7) As Integer

'Allocate memory for a lookup table for the serial mode
'register sizes
Private sRegSize(0 To 14) As Integer
Private sPRegAddr(0 To 14, 0 To 3) As Integer
'local variable(s) to hold property value(s)
Private mvarSerialIOMode As evbdSerMode 'local copy
'To fire this event, use RaiseEvent with the following syntax:
'RaiseEvent ResetOccured[(arg1, arg2, ... , argn)]
Public Event ResetOccured()
Attribute ResetOccured.VB_Description = "Is triggered after a reset has occured."
'local variable(s) to hold property value(s)
Private mvarAutoFUD As Boolean 'local copy
Public Property Let AutoFUD(ByVal vData As Boolean)
Attribute AutoFUD.VB_Description = "When set to true after a load the software will automatically strobe the FUD pin on the AD9858, loading the data sent and making it active.  When set to false the user must manually strobe the FUD pin, to make the data sent active."
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.AutoFUD = 5
    mvarAutoFUD = vData
End Property


Public Property Get AutoFUD() As Boolean
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.AutoFUD
    AutoFUD = mvarAutoFUD
End Property

'Gets the active profile
'Returns 1 to 4
Public Function GetActiveProfile() As Integer
Attribute GetActiveProfile.VB_Description = "Gets the currently active profile."
    Dim sProfileNum As String
    'Set the profile number
    sProfileNum = CStr(PS1) & CStr(PS0)
    GetActiveProfile = CInt(cbaseBinS2Dec(sProfileNum)) + 1
End Function

'Sets the active profile
'Inputs: Profile = A value from 0 to 3
Public Sub SetActiveProfile(ByVal Profile As Integer)
Attribute SetActiveProfile.VB_Description = "Sets the currently active profile."
    Dim sProfileNum As String
    'Use the profile selection bits to select the profile
    Select Case Profile
        Case 0:
            PS0 = abvLow
            PS1 = abvLow
        Case 1:
            PS0 = abvHigh
            PS1 = abvLow
        Case 2:
            PS0 = abvLow
            PS1 = abvHigh
        Case 3:
            PS0 = abvHigh
            PS1 = abvHigh
    End Select
End Sub


Public Property Let SerialIOMode(ByVal vData As evbdSerMode)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.SerialIOMode = 5
    'mvarSerialIOMode = vData
    MsgBox "SerialIOMode is currently a read only property." & vbCrLf & "SerialIOMOde can only be set by setting Bit 1 in the Control Register.", vbCritical, "Funciton: Not Yet Supported!!"
End Property


Public Property Get SerialIOMode() As evbdSerMode
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.SerialIOMode
    SerialIOMode = mvarSerialIOMode
End Property






Public Property Let LSBFirst(ByVal vData As Boolean)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.LSBFirst = 5
    'mvarLSBFirst = vData
End Property


Public Property Get LSBFirst() As Boolean
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.LSBFirst
    LSBFirst = mvarLSBFirst
End Property
'Loads the data speicified by data into the AD9858 at the register address
'specified by Address
Public Sub LoadData(ByVal Address As Integer, ByVal Data As String)
    If mvarEnabled Then
        If SPMode = abvHigh Then
            ParallelLoad Address, Data
        Else
            SerialLoad Address, Data
        End If
    End If
    
    If mvarAutoFUD = True Then
        'Strobe the FUD line
        FUD = abvLow
        FUD = abvHigh
        FUD = abvLow
    End If
End Sub


'This Sub is designed to work just like SerialLoad data and address
'values are identical in format.
'Address is the serial address of the register to be modified
'Data Format - MSB 10101010 10101010 LSB
'                 LBO             FBO
Public Sub ParallelLoad(ByVal Address As Integer, ByVal Data As String)
    Dim sByte As String
    Dim sData As String
    Dim cntr As Integer
    Dim iData As Integer
    Dim NumBytes As Integer
    
    'Only work if the object is enabled
    If mvarEnabled = True Then
    
        'Get the number of bytes sent
        NumBytes = sRegSize(Address)
        
        'If the number of bytes to send is different than the number of bytes
        'present in the data passed then exit the sub
        If (NumBytes = (Len(Data) / 8)) And (Address >= 0 And Address <= &HD) Then
            'Get a copy of the data, this data should contain the right amount for
            'the register
            sData = Data
            
            'Loop through the data and send each byte
            For cntr = 0 To NumBytes - 1
                'Get the byte to send
                sByte = Right(sData, 8)
                
                'Trim off that byte
                If Len(sData) > 8 Then
                    sData = Left(sData, Len(sData) - 8)
                End If
                
                'Convert the data to an integer form
                iData = CInt(cbaseBinS2Dec(sByte))
                
                'Load the data into the AD9858
                ParallelLoadByte sPRegAddr(Address, cntr), iData
            Next cntr
        Else
            'The data isn't valid or the address isn't valid
            If Address < 0 Or Address > &HD Then
                MsgBox "Error: Invalid address = " & Address & ".", vbApplicationModal, "Error: Sub ParallelLoad"
            End If
            
            If NumBytes = (Len(Data) / 8) Then
                MsgBox "Error: Invalid data = " & Data & ".", vbApplicationModal, "Error: Sub ParallelLoad"
            End If
        End If
    End If
End Sub

Public Sub SerialLoad(ByVal Address As Integer, ByVal Data As String)
    Dim sInstructByte As String
    Dim sData As String
    Dim cntr As Integer
    Dim NumBytes As Integer
    
    'Only work if the object is enabled
    If mvarEnabled = True Then
        'Get the number of bytes sent
        NumBytes = sRegSize(Address)
        
        'If the number of bytes to send is different than the number of bytes
        'present in the data passed then exit the sub
        If (NumBytes = (Len(Data) / 8)) And (Address >= 0 And Address <= &HD) Then
            'Build the instruction byte
            sInstructByte = "0000" & cbaseDec2Bin(Address, 4)
            sData = Data
            
            'Check to see if the part is currently in LSB First Mode
            If LSBFirst Then
                'Rearrange the instruction byte into LSB First format
                sInstructByte = FlipString(sInstructByte)
                'Rearrange the data into LSB First format
                sData = FlipString(sData)
            End If
            
            'Build the final data string to be sent to the AD9858
            sData = sInstructByte & sData
            
            'Set SCLK Low before csb goes low so that we will know its
            'state
            WRB_SCLK = abvLow
            
            'First take the CSB line low
            RDB_CSB = abvLow
            
            'Send the Instruction Byte first
'            For cntr = 1 To Len(sInstructByte)
'                'Set SDI to the proper value
'                A0_SDIO = CInt(Mid(sInstructByte, cntr, 1))
'                'Latch the data into the AD9858
'                WRB_SCLK = abvHigh
'                WRB_SCLK = abvLow
'            Next cntr
            
            'Loop through the data
            For cntr = 1 To Len(sData)
                'Set SDI to the proper value
                A0_SDIO = CInt(Mid(sData, cntr, 1))
                'Latch the data into the AD9858
                WRB_SCLK = abvHigh
                WRB_SCLK = abvLow
            Next cntr
                    
            'Now return the CSB line high
            RDB_CSB = abvHigh
            'Always return SCLK to a High when done just incase the user
            'switches to Parallel Mode
            WRB_SCLK = abvHigh
            
            'Now Check to see if they put the part into LSB First or 2 or 3 Wire Mode
            If Address = 0 Then
                If Right(Data, 1) = "1" Then
                    'They sent the LSBFirst Bit
                    mvarLSBFirst = True
                Else
                    'They Sent MSB First Mode
                    mvarLSBFirst = False
                End If
                If Left(Right(Data, 2), 1) = "1" Then
                    'They sent the SDIO Input Only Bit so they want 3 Wire Mode
                    mvarSerialIOMode = ThreeWire
                    'Make sure RB_Enable is a low
                    RB_Enable = abvLow
                Else
                    'They want 2 wire mode
                    mvarSerialIOMode = TwoWire
                End If
            End If
        Else
            'The data isn't valid or the address isn't valid
            If Address < 0 Or Address > &HD Then
                MsgBox "Error: Invalid address = " & Address & ".", vbApplicationModal, "Error: Sub SerialLoad"
            End If
            
            If NumBytes = (Len(Data) / 8) Then
                MsgBox "Error: Invalid data = " & Data & ".", vbApplicationModal, "Error: Sub SerialLoad"
            End If
        End If
    End If
End Sub
'Reads back a string serialy
Public Function SerialRead(ByVal Address As Integer) As String
    Dim sInstructByte As String
    Dim cntr As Integer
    Dim NumBytes As Integer
    Dim sRetStr As String
    
    'Only work if the object is enabled
    If mvarEnabled = True Then
        'Get the number of bytes sent
        NumBytes = sRegSize(Address)
        
        'If the number of bytes to send is different than the number of bytes
        'present in the data passed then exit the sub
        If Address >= 0 And Address <= &HE Then
            'Build the instruction byte
            sInstructByte = "1000" & cbaseDec2Bin(Address, 4)
            
            'Check to see if the part is currently in LSB First Mode
            If LSBFirst Then
                'Rearrange the instruction byte into LSB First format
                sInstructByte = FlipString(sInstructByte)
            End If
            
            'Set SCLK Low before csb goes low so that we will know its
            'state
            WRB_SCLK = abvLow
            
            'First take the CSB line low
            RDB_CSB = abvLow
            
            'Take readback enable low
            RDB_CSB = abvLow
            
            'Send the Instruction Byte first
            For cntr = 1 To Len(sInstructByte)
                'Set SDI to the proper value
                A0_SDIO = CInt(Mid(sInstructByte, cntr, 1))
                'Latch the data into the AD9858
                WRB_SCLK = abvHigh
                If cntr <> Len(sInstructByte) Then
                    WRB_SCLK = abvLow
                End If
                
            Next cntr
            
            If SerialIOMode = TwoWire Then
                'Set read back enable high
                RB_Enable = abvHigh
            Else
                'Make sure its low or
                RB_Enable = abvLow
            End If
                        
            'Loop through, reading the data back
            For cntr = 0 To ((NumBytes * 8) - 1)
                'Latch the data into the AD9858
                WRB_SCLK = abvLow
                'Get a bit from the eval board
                sRetStr = sRetStr & CStr(SDO)
                'Set sclk high only if it isn't the last bit shifted in
                WRB_SCLK = abvHigh
            Next cntr
            
            'Take the sclk line low again
            WRB_SCLK = abvLow
                                
            'If in 2 Wire mode set RB_Enable Low again
            If SerialIOMode = TwoWire Then
                'Set read back enable low
                RB_Enable = abvLow
            End If

⌨️ 快捷键说明

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