VERSION 5.00 Object = "{FE0065C0-1B7B-11CF-9D53-00AA003C9CB6}#1.1#0"; "COMCT232.OCX" Begin VB.Form Form1 Caption = "Form1" ClientHeight = 7140 ClientLeft = 60 ClientTop = 450 ClientWidth = 7305 LinkTopic = "Form1" ScaleHeight = 7140 ScaleWidth = 7305 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Stop Caption = "&Stop" Height = 375 Left = 5280 TabIndex = 44 Top = 840 Width = 1215 End Begin ComCtl2.UpDown DAC1spin Height = 255 Left = 2520 TabIndex = 43 Top = 6240 Width = 255 _ExtentX = 450 _ExtentY = 450 _Version = 327681 Enabled = -1 'True End Begin ComCtl2.UpDown DAC0spin Height = 255 Left = 2520 TabIndex = 42 Top = 5880 Width = 255 _ExtentX = 450 _ExtentY = 450 _Version = 327681 Enabled = -1 'True End Begin VB.Timer Timer1 Enabled = 0 'False Interval = 500 Left = 6720 Top = 6600 End Begin VB.CommandButton Begin Caption = "&Begin" Height = 375 Left = 5280 TabIndex = 39 Top = 360 Width = 1215 End Begin VB.Frame Frame1 Caption = "Single Ended Mode Only" Height = 3615 Left = 3240 TabIndex = 22 Top = 1800 Width = 3255 Begin VB.TextBox ChannelEdit Height = 285 Index = 8 Left = 1440 TabIndex = 30 Top = 360 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 9 Left = 1440 TabIndex = 29 Top = 720 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 10 Left = 1440 TabIndex = 28 Top = 1080 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 11 Left = 1440 TabIndex = 27 Top = 1440 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 12 Left = 1440 TabIndex = 26 Top = 1800 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 13 Left = 1440 TabIndex = 25 Top = 2160 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 14 Left = 1440 TabIndex = 24 Top = 2520 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 15 Left = 1440 TabIndex = 23 Top = 2880 Width = 855 End Begin VB.Label Label10 Caption = "Channel 8:" Height = 255 Left = 480 TabIndex = 38 Top = 360 Width = 855 End Begin VB.Label Label11 Caption = "Channel 9:" Height = 255 Left = 480 TabIndex = 37 Top = 720 Width = 855 End Begin VB.Label Label12 Caption = "Channel 10:" Height = 255 Left = 480 TabIndex = 36 Top = 1080 Width = 855 End Begin VB.Label Label13 Caption = "Channel 11:" Height = 255 Left = 480 TabIndex = 35 Top = 1440 Width = 855 End Begin VB.Label Label14 Caption = "Channel 12:" Height = 255 Left = 480 TabIndex = 34 Top = 1800 Width = 855 End Begin VB.Label Label15 Caption = "Channel 13:" Height = 255 Left = 480 TabIndex = 33 Top = 2160 Width = 855 End Begin VB.Label Label16 Caption = "Channel 14:" Height = 255 Left = 480 TabIndex = 32 Top = 2520 Width = 855 End Begin VB.Label Label17 Caption = "Channel 15:" Height = 255 Left = 480 TabIndex = 31 Top = 2880 Width = 855 End End Begin VB.TextBox DACout Height = 285 Index = 1 Left = 1560 TabIndex = 21 Top = 6240 Width = 975 End Begin VB.TextBox DACout Height = 285 Index = 0 Left = 1560 TabIndex = 20 Top = 5880 Width = 975 End Begin VB.TextBox ChannelEdit Height = 285 Index = 7 Left = 1200 TabIndex = 17 Top = 4680 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 6 Left = 1200 TabIndex = 16 Top = 4320 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 5 Left = 1200 TabIndex = 15 Top = 3960 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 4 Left = 1200 TabIndex = 14 Top = 3600 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 3 Left = 1200 TabIndex = 13 Top = 3240 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 2 Left = 1200 TabIndex = 12 Top = 2880 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 1 Left = 1200 TabIndex = 11 Top = 2520 Width = 855 End Begin VB.TextBox ChannelEdit Height = 285 Index = 0 Left = 1200 TabIndex = 10 Top = 2160 Width = 855 End Begin VB.TextBox Addr Height = 375 Left = 4080 TabIndex = 0 Text = "Text1" Top = 360 Width = 855 End Begin VB.Label DAC1Label Caption = "DAC 1 output range is x to x volts" Height = 255 Left = 3000 TabIndex = 41 Top = 6240 Width = 3375 End Begin VB.Label DAC0Label Caption = "DAC 0 output range is x to x volts" Height = 255 Left = 3000 TabIndex = 40 Top = 5880 Width = 3255 End Begin VB.Label Label19 Caption = "DAC 1 Output:" Height = 255 Left = 360 TabIndex = 19 Top = 6240 Width = 1095 End Begin VB.Label Label18 Caption = "DAC 0 Output:" Height = 255 Left = 360 TabIndex = 18 Top = 5880 Width = 1095 End Begin VB.Label Label9 Caption = "Channel 7:" Height = 255 Left = 240 TabIndex = 9 Top = 4680 Width = 855 End Begin VB.Label Label8 Caption = "Channel 6:" Height = 255 Left = 240 TabIndex = 8 Top = 4320 Width = 855 End Begin VB.Label Label7 Caption = "Channel 5:" Height = 255 Left = 240 TabIndex = 7 Top = 3960 Width = 855 End Begin VB.Label Label6 Caption = "Channel 4:" Height = 255 Left = 240 TabIndex = 6 Top = 3600 Width = 855 End Begin VB.Label Label5 Caption = "Channel 3:" Height = 255 Left = 240 TabIndex = 5 Top = 3240 Width = 855 End Begin VB.Label Label4 Caption = "Channel 2:" Height = 255 Left = 240 TabIndex = 4 Top = 2880 Width = 855 End Begin VB.Label Label3 Caption = "Channel 1:" Height = 255 Left = 240 TabIndex = 3 Top = 2520 Width = 855 End Begin VB.Label Label2 Caption = "Channel 0:" Height = 255 Left = 240 TabIndex = 2 Top = 2160 Width = 855 End Begin VB.Label Label1 Caption = "Enter the Base Address in HEX and click BEGIN" Height = 255 Left = 480 TabIndex = 1 Top = 480 Width = 3495 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim BASE As Integer Dim jumpers As Integer Dim adrange As Byte Dim dacBrange As Byte Dim dacArange As Byte Dim channels As Integer Private Sub Begin_Click() 'get the address and set up the global variables and calibrate the card BASE = "&H" + Addr.Text init doCAL 'determine the number of channels If (jumpers And 1) Then channels = 16 Else channels = 8 End If 'tell the card which channels will be scanned 'bits 0-3 are the start channel and bits 4-7 are the end channel OutPortB BASE + &H2, (channels - 1) * &H10 'determine the dac ranges and let the user know what they are If dacArange Then DAC0Label.Caption = "DAC 0 output range is 0 to 5 volts" Else DAC0Label.Caption = "DAC 0 output range is 0 to 10 volts" End If If dacBrange Then DAC1Label.Caption = "DAC 1 output range is 0 to 5 volts" Else DAC1Label.Caption = "DAC 1 output range is 0 to 10 volts" End If 'start the timer Timer1.Enabled = True End Sub 'set the default address to 300 (HEX) Private Sub Form_Load() Addr.Text = "300" End Sub 'stop the timer Private Sub Stop_Click() Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Dim count As Integer Dim reading As Long Dim dacoutput As Double Dim temp As Double Dim bpAdjust As Double Dim gainAdjust As Double 'Determine the gain and if the card is in bipolar mode 'then set the variables to be used later If adrange And &H2 Then bpAdjust = 0.5 Else bpAdjust = 0# End If If adrange And &H4 Then gainAdjust = 10# Else gainAdjust = 20# End If 'pause the timer Timer1.Enabled = False 'have the board take one reading per channel For count = 1 To channels OutPortB BASE, 0 Next count 'read each of the values from the board. Convert them to volts 'and display them For count = 0 To channels - 1 'the reading is two bytes long and we read from the board one 'byte at a time. We need to do two reads. The first byte is the 'most significant reading = InPortB(BASE) reading = ShiftLeft(InPortB(BASE), 8) Or reading temp = ((reading / 65536#) - bpAdjust) * gainAdjust ChannelEdit(count).Text = temp Next count 'send out the dac values and put the actual output on screen If dacArange Then dacoutput = DAC(0, 0.49 * DAC0spin.Value) Else dacoutput = DAC(0, 0.99 * DAC0spin.Value) End If DACout(0).Text = dacoutput If dacBrange Then dacoutput = DAC(1, 0.49 * DAC1spin.Value) Else dacoutput = DAC(1, 0.99 * DAC1spin.Value) End If DACout(1).Text = dacoutput 'restart the timer Timer1.Enabled = True End Sub 'sbitd takes data and bit, then returns 0x81 or 0x01 based on data[bit] Public Function sbitd(ByVal data As Integer, ByVal bit As Byte) As Integer If (ShiftRight(data, bit) And &H1) Then sbitd = &H81 Else sbitd = &H1 End If End Function 'DAC will write to the selected DAC and returns the actual volts '(as modified for 12-bit D/A) 'DACnum is 0 or 1 'DACV is volts Public Function DAC(ByVal DACnum As Byte, ByVal DACV As Double) As Double Dim count As Long Dim range As Byte If DACnum Then range = dacBrange Else range = dacArange End If If range Then count = DACV / 5 * 4096 Else count = DACV / 10 * 4096 End If count = count And &HFFF '12-bit DAC DACnum = DACnum + 1 'To the hardware, the DACs are 1-based OutPortB BASE + 9, &H81 'DAC load mode = software OutPortB BASE + 9, sbitd(DACnum, 1) + 2 'DACnum bit 1 OutPortB BASE + 9, sbitd(DACnum, 0) + 2 'DACnum bit 0 OutPortB BASE + 9, &H1 'unused bit OutPortB BASE + 9, sbitd(count, 11) 'data bit 11 OutPortB BASE + 9, sbitd(count, 10) 'data bit 10 OutPortB BASE + 9, sbitd(count, 9) 'data bit 9 OutPortB BASE + 9, sbitd(count, 8) 'data bit 8 OutPortB BASE + 9, sbitd(count, 7) 'data bit 7 OutPortB BASE + 9, sbitd(count, 6) 'data bit 6 OutPortB BASE + 9, sbitd(count, 5) 'data bit 5 OutPortB BASE + 9, sbitd(count, 4) 'data bit 4 OutPortB BASE + 9, sbitd(count, 3) 'data bit 3 OutPortB BASE + 9, sbitd(count, 2) 'data bit 2 OutPortB BASE + 9, sbitd(count, 1) 'data bit 1 OutPortB BASE + 9, sbitd(count, 0) 'data bit 0 OutPortB BASE + 9, &H0 'end trans OutPortB BASE + 9, &H2 'Load DACs If range Then DAC = count / 4096# * 5# 'actual V Else DAC = count / 4096# * 10# 'actual V End If End Function ' Enable the EEEPROM for writing Public Sub EEPROM_Enable() OutPortB BASE + &HA, &H81 'start bit OutPortB BASE + &HA, &H1 'Opcode bit 0 (00 = enable/disable) OutPortB BASE + &HA, &H1 'Opcode bit 1 "" OutPortB BASE + &HA, &H81 'a5 (must be 1 to enable) OutPortB BASE + &HA, &H81 'a4 (must be 1 to enable) OutPortB BASE + &HA, &H1 'a3 (don't care because enable/disable) OutPortB BASE + &HA, &H1 'a2 (don't care because enable/disable) OutPortB BASE + &HA, &H1 'a1 (don't care because enable/disable) OutPortB BASE + &HA, &H1 'a0 (don't care because enable/disable) OutPortB BASE + &HA, &H0 'end trans End Sub ' Disable the EEPROM write Public Sub EEPROM_Disable() OutPortB BASE + &HA, &H81 'start bit OutPortB BASE + &HA, &H1 'Opcode bit 0 (00 = enable/disable) OutPortB BASE + &HA, &H1 'Opcode bit 1 "" OutPortB BASE + &HA, &H1 'a5 (must be 0 to disable) OutPortB BASE + &HA, &H1 'a4 (must be 0 to disable) OutPortB BASE + &HA, &H1 'a3 (don't care because enable/disable) OutPortB BASE + &HA, &H1 'a2 (don't care because enable/disable) OutPortB BASE + &HA, &H1 'a1 (don't care because enable/disable) OutPortB BASE + &HA, &H1 'a0 (don't care because enable/disable) OutPortB BASE + &HA, &H0 'end trans End Sub ' write the value in data to the EEPROM to the location specified by addr Public Sub EEPROM_Write(ByVal Addr As Integer, ByVal data As Integer) OutPortB BASE + &HA, &H81 'Start Bit OutPortB BASE + &HA, &H1 'Opcode Bit 0 (01=write) OutPortB BASE + &HA, &H81 'Opcode Bit 1 "" OutPortB BASE + &HA, sbitd(Addr, 5) 'a5 (address to write to) OutPortB BASE + &HA, sbitd(Addr, 4) 'a4 OutPortB BASE + &HA, sbitd(Addr, 3) 'a3 OutPortB BASE + &HA, sbitd(Addr, 2) 'a2 OutPortB BASE + &HA, sbitd(Addr, 1) 'a1 OutPortB BASE + &HA, sbitd(Addr, 0) 'a0 OutPortB BASE + &HA, sbitd(data, 15) 'd15 OutPortB BASE + &HA, sbitd(data, 14) 'd14 OutPortB BASE + &HA, sbitd(data, 13) 'd13 OutPortB BASE + &HA, sbitd(data, 12) 'd12 OutPortB BASE + &HA, sbitd(data, 11) 'd11 OutPortB BASE + &HA, sbitd(data, 10) 'd10 OutPortB BASE + &HA, sbitd(data, 9) 'd9 OutPortB BASE + &HA, sbitd(data, 8) 'd8 OutPortB BASE + &HA, sbitd(data, 7) 'd7 OutPortB BASE + &HA, sbitd(data, 6) 'd6 OutPortB BASE + &HA, sbitd(data, 5) 'd5 OutPortB BASE + &HA, sbitd(data, 4) 'd4 OutPortB BASE + &HA, sbitd(data, 3) 'd3 OutPortB BASE + &HA, sbitd(data, 2) 'd2 OutPortB BASE + &HA, sbitd(data, 1) 'd1 OutPortB BASE + &HA, sbitd(data, 0) 'd0 OutPortB BASE + &HA, &H0 'end trans 'Sleep (20) End Sub ' read the value from the EEPROM at the location specified by addr and return it Public Function EEPROM_Read(ByVal Addr As Integer) As Long Dim data As Long data = 0 OutPortB BASE + &HA, &H81 'Start Bit OutPortB BASE + &HA, &H81 'Opcode Bit 0 (10=Read) OutPortB BASE + &HA, &H1 'Opcode Bit 1 "" OutPortB BASE + &HA, sbitd(Addr, 5) 'a5 (address to write to) OutPortB BASE + &HA, sbitd(Addr, 4) 'a4 OutPortB BASE + &HA, sbitd(Addr, 3) 'a3 OutPortB BASE + &HA, sbitd(Addr, 2) 'a2 OutPortB BASE + &HA, sbitd(Addr, 1) 'a1 OutPortB BASE + &HA, sbitd(Addr, 0) 'a0 ' delay(10) ' InPortB(BASE+&h0a)'dummy bit data = ShiftRight(InPortB(BASE + &HA), 7) 'd15 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd14 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd13 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd12 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd11 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd10 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd9 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd8 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd7 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd6 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd5 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd4 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd3 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd2 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd1 data = ShiftLeft(data, 1) + ShiftRight(InPortB(BASE + &HA), 7) 'd0 OutPortB BASE + &HA, &H0 'end com EEPROM_Read = data End Function ' write the gain (M) and the offset (B) to the pots. y=Mx + B Public Sub CAL_ADC(ByVal M As Byte, ByVal B As Byte) 'write cal to A/D, offset first, then slope OutPortB BASE + &HB, &H1 'a1 pot 00 is offset OutPortB BASE + &HB, &H1 'a0 "" OutPortB BASE + &HB, sbitd(B, 7) 'data bit 7 of offset OutPortB BASE + &HB, sbitd(B, 6) 'data bit 6 of offset OutPortB BASE + &HB, sbitd(B, 5) 'data bit 5 of offset OutPortB BASE + &HB, sbitd(B, 4) 'data bit 4 of offset OutPortB BASE + &HB, sbitd(B, 3) 'data bit 3 of offset OutPortB BASE + &HB, sbitd(B, 2) 'data bit 2 of offset OutPortB BASE + &HB, sbitd(B, 1) 'data bit 1 of offset OutPortB BASE + &HB, sbitd(B, 0) 'data bit 0 of offset OutPortB BASE + &HB, &H0 'end trans 'write slope now OutPortB BASE + &HB, &H1 'a1 pot 01 is slope of A/D OutPortB BASE + &HB, &H81 'a0 pot 01 is slope of A/D OutPortB BASE + &HB, sbitd(M, 7) 'data bit 7 of slope OutPortB BASE + &HB, sbitd(M, 6) 'data bit 6 of slope OutPortB BASE + &HB, sbitd(M, 5) 'data bit 5 of slope OutPortB BASE + &HB, sbitd(M, 4) 'data bit 4 of slope OutPortB BASE + &HB, sbitd(M, 3) 'data bit 3 of slope OutPortB BASE + &HB, sbitd(M, 2) 'data bit 2 of slope OutPortB BASE + &HB, sbitd(M, 1) 'data bit 1 of slope OutPortB BASE + &HB, sbitd(M, 0) 'data bit 0 of slope OutPortB BASE + &HB, &H0 'end trans End Sub ' write the gain(M) for the specified DAC to the pots Public Sub CAL_DAC(ByVal DACnum As Byte, ByVal M As Byte) OutPortB BASE + &HB, &H81 'a1 pot 10 is slope of DAC0 OutPortB BASE + &HB, sbitd(DACnum, 0) 'a0 pot 11 is slope of DAC1 OutPortB BASE + &HB, sbitd(M, 7) 'data bit 7 of slope OutPortB BASE + &HB, sbitd(M, 6) 'data bit 6 of slope OutPortB BASE + &HB, sbitd(M, 5) 'data bit 5 of slope OutPortB BASE + &HB, sbitd(M, 4) 'data bit 4 of slope OutPortB BASE + &HB, sbitd(M, 3) 'data bit 3 of slope OutPortB BASE + &HB, sbitd(M, 2) 'data bit 2 of slope OutPortB BASE + &HB, sbitd(M, 1) 'data bit 1 of slope OutPortB BASE + &HB, sbitd(M, 0) 'data bit 0 of slope OutPortB BASE + &HB, &H0 'end trans End Sub ' writes the current calibration values to the EEPROM. Public Sub CALWrite(ByVal zAM As Byte, ByVal zAB As Byte, ByVal zDAM As Byte, ByVal zDBM As Byte) EEPROM_Enable EEPROM_Write (adrange + 0), zAB EEPROM_Write (adrange + 8), zAM EEPROM_Write (dacArange + &H10), zDAM EEPROM_Write (dacBrange + &H12), zDBM EEPROM_Disable End Sub ' reads the calibration values from the EEPROM and write them to the pots ' this should be done before taking any readings from the board. Public Sub doCAL() Dim zDAM As Byte Dim zDBM As Byte Dim zAM As Byte Dim zAB As Byte zAB = EEPROM_Read((adrange + 0)) And &HFF 'byte 0-7 in EEPROM holds "B" for ADC zAM = EEPROM_Read((adrange + 8)) And &HFF 'byte 8-f in EEPROM holds "M" for ADC zDAM = EEPROM_Read((dacArange + &H10)) And &HFF 'byte x10,x11 in EEPROM holds "M" for DAC0 zDBM = EEPROM_Read((dacBrange + &H12)) And &HFF 'byte x12,x13 in EEPROM holds "M" for DAC1 CAL_DAC 0, zDAM 'write the calibration value from EEPROM to CAL Pots CAL_DAC 1, zDBM ' "" CAL_ADC zAM, zAB ' "" End Sub 'reads the jumper config from the board and initializes the global variables Public Sub init() jumpers = InPortB(BASE + &H8) 'jumper configuration readback adrange = jumpers And &H7 'd2,d1,d0 are 5/10, uni/bip, 16/8 dacBrange = ShiftRight(jumpers, 3) And &H1 'd4,d3 are 5/10 for daca,b dacArange = ShiftRight(jumpers, 4) And &H1 End Sub