VERSION 5.00 Begin VB.Form DSWTUN03 Caption = "DSWTUN03 by n4qa" ClientHeight = 3180 ClientLeft = 60 ClientTop = 405 ClientWidth = 4200 LinkTopic = "Form1" ScaleHeight = 3180 ScaleWidth = 4200 StartUpPosition = 3 'Windows Default Begin VB.OptionButton band_160 Caption = "160" Height = 255 Left = 120 TabIndex = 42 Top = 120 Width = 615 End Begin VB.ListBox Calibrate Height = 255 ItemData = "dswtun03.frx":0000 Left = 120 List = "dswtun03.frx":0010 TabIndex = 41 Top = 2880 Width = 855 End Begin VB.CommandButton key_SWAP Caption = "" Height = 255 Left = 1560 TabIndex = 40 Top = 360 Width = 975 End Begin VB.CommandButton key_XandR Caption = "X,R" Height = 255 Left = 1800 TabIndex = 39 Top = 2880 Width = 495 End Begin VB.CommandButton key_RequX Caption = "R=X" Height = 255 Left = 3360 TabIndex = 38 Top = 2520 Width = 735 End Begin VB.CommandButton keyX_equR Caption = "X=R" Height = 255 Left = 120 TabIndex = 37 Top = 2520 Width = 615 End Begin VB.ListBox portaddr Height = 255 ItemData = "dswtun03.frx":0032 Left = 3240 List = "dswtun03.frx":003C TabIndex = 36 Top = 2880 Width = 975 End Begin VB.OptionButton band_20 Caption = "20" Height = 195 Left = 3600 TabIndex = 35 Top = 120 Width = 495 End Begin VB.OptionButton band_30 Caption = "30" Height = 195 Left = 2760 TabIndex = 34 Top = 120 Width = 495 End Begin VB.OptionButton band_40 Caption = "40" Height = 195 Left = 1920 TabIndex = 33 Top = 120 Width = 495 End Begin VB.OptionButton band_80 Caption = "80" Height = 195 Left = 1080 TabIndex = 32 Top = 120 Width = 495 End Begin VB.CommandButton key_RD Caption = "RD" Height = 495 Left = 2760 TabIndex = 31 Top = 2280 Width = 255 End Begin VB.CommandButton key_RU Caption = "RU" Height = 495 Left = 2760 TabIndex = 30 Top = 1440 Width = 255 End Begin VB.CommandButton key_XD Caption = "XD" Height = 495 Left = 1080 TabIndex = 29 Top = 2280 Width = 255 End Begin VB.CommandButton key_XU Caption = "XU" Height = 495 Left = 1080 TabIndex = 28 Top = 1440 Width = 255 End Begin VB.CommandButton key_CHU Caption = "CHU" Height = 255 Left = 3360 TabIndex = 27 Top = 1080 Width = 735 End Begin VB.CommandButton key_W1AW Caption = "W1AW" Height = 255 Left = 3360 TabIndex = 26 Top = 1440 Width = 735 End Begin VB.CommandButton key_C Caption = "C" Height = 255 Left = 2400 TabIndex = 24 Top = 2880 Width = 255 End Begin VB.CommandButton key_Lend Caption = "L.End" Height = 255 Left = 120 TabIndex = 23 Top = 2160 Width = 615 End Begin VB.CommandButton key_middle Caption = "MID" Height = 255 Left = 120 TabIndex = 22 Top = 1440 Width = 615 End Begin VB.CommandButton key_Uend Caption = "U.End" Height = 255 Left = 120 TabIndex = 21 Top = 1080 Width = 615 End Begin VB.CommandButton key_QRP_X Caption = "QRP" Height = 255 Left = 120 TabIndex = 20 Top = 1800 Width = 615 End Begin VB.CommandButton key_9 Caption = "9" Height = 255 Left = 2400 TabIndex = 19 Top = 1440 Width = 255 End Begin VB.CommandButton key_8 Caption = "8" Height = 255 Left = 1920 TabIndex = 18 Top = 1440 Width = 255 End Begin VB.CommandButton key_7 Caption = "7" Height = 255 Left = 1440 TabIndex = 17 Top = 1440 Width = 255 End Begin VB.CommandButton key_6 Caption = "6" Height = 255 Left = 2400 TabIndex = 16 Top = 1800 Width = 255 End Begin VB.CommandButton key_5 Caption = "5" Height = 255 Left = 1920 TabIndex = 15 Top = 1800 Width = 255 End Begin VB.CommandButton key_4 Caption = "4" Height = 255 Left = 1440 TabIndex = 14 Top = 1800 Width = 255 End Begin VB.CommandButton key_3 Caption = "3" Height = 255 Left = 2400 TabIndex = 13 Top = 2160 Width = 255 End Begin VB.CommandButton key_2 Caption = "2" Height = 255 Left = 1920 TabIndex = 12 Top = 2160 Width = 255 End Begin VB.CommandButton key_1 Caption = "1" Height = 255 Left = 1440 TabIndex = 11 Top = 2160 Width = 255 End Begin VB.CommandButton key_0 Caption = "0" Height = 255 Left = 1920 TabIndex = 10 Top = 2520 Width = 255 End Begin VB.CommandButton key_X Caption = "X" Height = 255 Left = 1440 TabIndex = 9 Top = 2520 Width = 255 End Begin VB.CommandButton key_R Caption = "R" Height = 255 Left = 2400 TabIndex = 8 Top = 2520 Width = 255 End Begin VB.CommandButton key_dot Caption = "." Height = 255 Left = 1440 TabIndex = 7 Top = 2880 Width = 255 End Begin VB.CommandButton key_QRP_R Caption = "QRP" Height = 255 Left = 3360 TabIndex = 6 Top = 1800 Width = 735 End Begin VB.CommandButton key_WWV Caption = "WWV" Height = 255 Left = 3360 TabIndex = 5 Top = 2160 Width = 735 End Begin VB.TextBox freqselectdisplay Height = 285 Left = 1560 TabIndex = 4 Top = 720 Width = 975 End Begin VB.TextBox rcvrfreqdisplay Height = 285 Left = 3120 TabIndex = 1 Top = 360 Width = 975 End Begin VB.TextBox xmtrfreqdisplay Height = 285 Left = 0 TabIndex = 0 Top = 360 Width = 975 End Begin VB.Label Label4 Caption = "Freq input" Height = 255 Left = 1680 TabIndex = 25 Top = 1080 Width = 735 End Begin VB.Label Label2 Caption = " Rcvr Freq" Height = 255 Left = 3240 TabIndex = 3 Top = 720 Width = 975 End Begin VB.Label Label1 Caption = " Xmtr Freq" Height = 375 Left = 0 TabIndex = 2 Top = 720 Width = 855 End End Attribute VB_Name = "DSWTUN03" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' DSWTUN03 rel 2.0 ' Written by William K. Mabry, N4QA ' 14 March 2003 ' Updated 30 January 2008 to correct the values of DSW-80 constants 'ifreq' and ratio. ' Updated 09 August 2009 to include the 160-meter band. Private Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer) Dim D(0 To 31) Dim band Dim ifreq Dim ratio Dim port Dim low Dim high Private Sub band_160_Click() band = 160 ifreq = 4000 ratio = 134.217728 initialize End Sub Private Sub band_20_Click() band = 20 ifreq = -5185 ratio = 85.89934592 initialize End Sub Private Sub band_30_Click() band = 30 ifreq = -4000 ratio = 134.217728 initialize End Sub Private Sub band_40_Click() band = 40 ifreq = 4000 ratio = 134.217728 initialize End Sub Private Sub band_80_Click() band = 80 ifreq = 5185 ratio = 171.79869184 initialize End Sub Private Sub Calibrate_Click() Select Case Calibrate Case Is = "CAL ++" ratio = ratio * 1.000001 Case Is = "CAL +" ratio = ratio * 1.0000001 Case Is = "CAL -" ratio = ratio * 0.9999999 Case Is = "CAL --" ratio = ratio * 0.999999 Case Else End Select rcvrword = rcvrfreqdisplay * 1000 + ifreq * 1000 word = rcvrword * ratio to_binary_rcvr (word) xmtrword = xmtrfreqdisplay * 1000 * ratio word = xmtrword to_binary_xmtr (word) End Sub Private Sub key_0_Click() freqselectdisplay = freqselectdisplay + "0" End Sub Private Sub key_1_Click() freqselectdisplay = freqselectdisplay + "1" End Sub Private Sub key_2_Click() freqselectdisplay = freqselectdisplay + "2" End Sub Private Sub key_3_Click() freqselectdisplay = freqselectdisplay + "3" End Sub Private Sub key_4_Click() freqselectdisplay = freqselectdisplay + "4" End Sub Private Sub key_5_Click() freqselectdisplay = freqselectdisplay + "5" End Sub Private Sub key_6_Click() freqselectdisplay = freqselectdisplay + "6" End Sub Private Sub key_7_Click() freqselectdisplay = freqselectdisplay + "7" End Sub Private Sub key_8_Click() freqselectdisplay = freqselectdisplay + "8" End Sub Private Sub key_9_Click() freqselectdisplay = freqselectdisplay + "9" End Sub Private Sub key_C_Click() freqselectdisplay = "" End Sub Private Sub key_CHU_Click() Select Case band Case Is = 20 freqselectdisplay = "14669.2" rcvrfreqdisplay = "14669.2" Case Is = 30 freqselectdisplay = "7849.2" rcvrfreqdisplay = "7849.2" Case Is = 40 freqselectdisplay = "7850.8" rcvrfreqdisplay = "7850.8" Case Is = 80 freqselectdisplay = "3330.8" rcvrfreqdisplay = "3330.8" Case Is = 160 freqselectdisplay = "3330.8" rcvrfreqdisplay = "3330.8" End Select freq_set End Sub Private Sub initialize() 'initialize AD9835 Out port + 2, low 'fsync=0 For i = 1 To 16 a1 Next i Out port + 2, high 'fsync=1 'QRP power-up RX Mixer injection freq. key_QRP_R = True 'QRP power-up TX freq. key_QRP_X = True Out port + 2, low 'fsync=0 a1 a1 For i = 1 To 14 a0 Next i Out port + 2, high 'fsync=1 End Sub Private Sub key_dot_Click() freqselectdisplay = freqselectdisplay + "." End Sub Private Sub key_Lend_Click() Select Case band Case Is = 20 freqselectdisplay = "14000" Case Is = 30 freqselectdisplay = "10100" Case Is = 40 freqselectdisplay = "7000" Case Is = 80 freqselectdisplay = "3500" Case Is = 160 freqselectdisplay = "1800" End Select key_X_Click End Sub Private Sub key_middle_Click() Select Case band Case Is = 20 freqselectdisplay = "14175" Case Is = 30 freqselectdisplay = "10125" Case Is = 40 freqselectdisplay = "7150" Case Is = 80 freqselectdisplay = "3750" Case Is = 160 freqselectdisplay = "1900" End Select key_X_Click End Sub Private Sub key_QRP_R_Click() Select Case band Case Is = 20 freqselectdisplay = "14060" Case Is = 30 freqselectdisplay = "10110" Case Is = 40 freqselectdisplay = "7040" Case Is = 80 freqselectdisplay = "3560" Case Is = 160 freqselectdisplay = "1810" End Select key_R_Click End Sub Private Sub key_QRP_X_Click() Select Case band Case Is = 20 freqselectdisplay = "14060" Case Is = 30 freqselectdisplay = "10110" Case Is = 40 freqselectdisplay = "7040" Case Is = 80 freqselectdisplay = "3560" Case Is = 160 freqselectdisplay = "1810" End Select key_X_Click End Sub Private Sub key_R_Click() If Val(freqselectdisplay) > 30000 Then freqselectdisplay = "" test = CLng(Val(freqselectdisplay) * 10000) Mod 10 Select Case Val(freqselectdisplay) Case Is < -2550, Is > 18170 freqselectdisplay = "" Case Else Select Case test Case Is = 0 rcvrfreqdisplay = freqselectdisplay freq_set Case Else freqselectdisplay = "" End Select End Select freqselectdisplay = "" End Sub Private Sub freq_set() word = Val(freqselectdisplay) Select Case key_R Or key_QRP_R Or key_WWV Or key_CHU Or key_W1AW Or key_RequX Case Is = True word = word + ifreq Case Else End Select word = word * 1000 word = word * ratio Select Case key_R Or key_QRP_R Or key_WWV Or key_CHU Or key_W1AW Or key_RequX Case Is = True to_binary_rcvr (word) Case Else to_binary_xmtr (word) End Select freqselectdisplay = "" End Sub Private Sub to_binary_rcvr(word) Out port + 2, low 'fsync=0 a0 a0 a1 a1 a0 a0 a1 a1 For D_ = 31 To 24 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 Out port + 2, low 'fsync=0 a0 a0 a1 a0 a0 a0 a1 a0 For D_ = 23 To 16 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 Out port + 2, low 'fsync=0 a0 a0 a1 a1 a0 a0 a0 a1 For D_ = 15 To 8 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 Out port + 2, low 'fsync=0 a0 a0 a1 a0 a0 a0 a0 a0 For D_ = 7 To 0 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 End Sub Private Sub key_RD_Click() If CLng(Val(freqselectdisplay) * 10000) Mod 10 <> 0 Then freqselectdisplay = "": GoTo here Select Case Val(freqselectdisplay) Case Is <= 0, Is > 100 freqselectdisplay = "" Case Else word = Val(rcvrfreqdisplay) * 1000 + ifreq * 1000 - Val(freqselectdisplay) * 1000 word = word * ratio to_binary_rcvr (word) rcvrfreqdisplay = Str(Val(rcvrfreqdisplay) - Val(freqselectdisplay)) End Select here: End Sub Private Sub key_RequX_Click() freqselectbuffer = freqselectdisplay rcvrfreqdisplay = xmtrfreqdisplay freqselectdisplay = xmtrfreqdisplay freq_set freqselectdisplay = freqselectbuffer End Sub Private Sub key_RU_Click() If CLng(Val(freqselectdisplay) * 10000) Mod 10 <> 0 Then freqselectdisplay = "": GoTo here Select Case Val(freqselectdisplay) Case Is <= 0, Is > 100 freqselectdisplay = "" Case Else word = Val(rcvrfreqdisplay) * 1000 + ifreq * 1000 + Val(freqselectdisplay) * 1000 word = word * ratio to_binary_rcvr (word) rcvrfreqdisplay = Str(Val(rcvrfreqdisplay) + Val(freqselectdisplay)) End Select here: End Sub Private Sub key_SWAP_Click() rcvrbuffer = rcvrfreqdisplay rcvrfreqdisplay = xmtrfreqdisplay xmtrfreqdisplay = rcvrbuffer rcvrword = rcvrfreqdisplay * 1000 + ifreq * 1000 word = rcvrword * ratio to_binary_rcvr (word) xmtrword = xmtrfreqdisplay * 1000 word = xmtrword * ratio to_binary_xmtr (word) End Sub Private Sub key_Uend_Click() Select Case band Case Is = 20 freqselectdisplay = "14350" Case Is = 30 freqselectdisplay = "10150" Case Is = 40 freqselectdisplay = "7300" Case Is = 80 freqselectdisplay = "4000" Case Is = 160 freqselectdisplay = "1997" End Select key_X_Click End Sub Private Sub key_W1AW_Click() Select Case band Case Is = 20 freqselectdisplay = "14047.5" rcvrfreqdisplay = "14047.5" Case Is = 30 freqselectdisplay = "7047.5" rcvrfreqdisplay = "7047.5" Case Is = 40 freqselectdisplay = "7047.5" rcvrfreqdisplay = "7047.5" Case Is = 80 freqselectdisplay = "3581.5" rcvrfreqdisplay = "3581.5" Case Is = 160 freqselectdisplay = "1802.5" rcvrfreqdisplay = "1802.5" End Select freq_set End Sub Private Sub key_WWV_click() Select Case band Case Is = 20 freqselectdisplay = "14999.2" rcvrfreqdisplay = "14999.2" Case Is = 30 freqselectdisplay = "9999.2" rcvrfreqdisplay = "9999.2" Case Is = 40 freqselectdisplay = "5000.8" rcvrfreqdisplay = "5000.8" Case Is = 80 freqselectdisplay = "5000.8" rcvrfreqdisplay = "5000.8" Case Is = 160 freqselectdisplay = "2500.8" rcvrfreqdisplay = "2500.8" End Select freq_set End Sub Private Sub a1() For t = 0 To 100 Next t Out port, 12 For t = 0 To 100 Next t Out port, 4 '1 clocked For t = 0 To 100 Next t Out port, 12 For t = 0 To 100 Next t End Sub Private Sub a0() For t = 0 To 100 Next t Out port, 8 For t = 0 To 100 Next t Out port, 0 '0 clocked For t = 0 To 100 Next t Out port, 8 For t = 0 To 100 Next t End Sub Private Sub key_X_Click() If Val(freqselectdisplay) > 30000 Then freqselectdisplay = "" test = CLng(Val(freqselectdisplay) * 10000) Mod 10 Select Case Val(freqselectdisplay) Case Is < 0, Is > 30000 freqselectdisplay = "" Case Else Select Case test Case Is = 0 xmtrfreqdisplay = freqselectdisplay freq_set Case Else freqselectdisplay = "" End Select End Select freqselectdisplay = "" End Sub Private Sub to_binary_xmtr(word) Out port + 2, low 'fsync=0 a0 a0 a1 a1 a0 a1 a1 a1 For D_ = 31 To 24 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 Out port + 2, low 'fsync=0 a0 a0 a1 a0 a0 a1 a1 a0 For D_ = 23 To 16 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 Out port + 2, low 'fsync=0 a0 a0 a1 a1 a0 a1 a0 a1 For D_ = 15 To 8 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 Out port + 2, low 'fsync=0 a0 a0 a1 a0 a0 a1 a0 a0 For D_ = 7 To 0 Step -1 Select Case word Case Is >= 2 ^ D_ 'D_D = 1 a1 word = word - 2 ^ D_ Case Else 'D_D = 0 a0 End Select Next D_ Out port + 2, high 'fsync=1 End Sub Private Sub key_XandR_Click() rcvrfreqdisplay = freqselectdisplay rcvrword = freqselectdisplay * 1000 + ifreq * 1000 word = rcvrword * ratio to_binary_rcvr (word) xmtrfreqdisplay = freqselectdisplay xmtrword = freqselectdisplay * 1000 * ratio word = xmtrword to_binary_xmtr (word) freqselectdisplay = "" End Sub Private Sub key_XD_Click() X_DN = Val(freqselectdisplay) Select Case X_DN Case Is < 0, Is > 100 freqselectdisplay = "" Case Else X_DN = X_DN * -1000 word = Val(xmtrfreqdisplay) * 1000 + X_DN word = word * ratio to_binary_xmtr (word) xmtrfreqdisplay = Str(Val(xmtrfreqdisplay - Val(freqselectdisplay))) End Select End Sub Private Sub key_XU_Click() X_UP = Val(freqselectdisplay) Select Case X_UP Case Is < 0, Is > 100 freqselectdisplay = "" Case Else X_UP = X_UP * 1000 word = Val(xmtrfreqdisplay) * 1000 + X_UP word = word * ratio to_binary_xmtr (word) xmtrfreqdisplay = Str(Val(xmtrfreqdisplay + Val(freqselectdisplay))) End Select End Sub Private Sub keyX_equR_Click() freqselectbuffer = freqselectdisplay xmtrfreqdisplay = rcvrfreqdisplay freqselectdisplay = rcvrfreqdisplay freq_set freqselectdisplay = freqselectbuffer End Sub Private Sub portaddr_Click() Select Case portaddr Case Is = "0x100" port = &H100 '256, base ten low = 0 high = 1 Case Is = "0x278" port = &H278 '632, base ten low = 1 high = 0 Case Is = "0x378" port = &H378 '888, base ten low = 1 high = 0 Case Is = "0x3BC" port = &H3BC '956, base ten low = 1 high = 0 Case Is = "0x10A8" port = &H10A8 '4168, base ten low = 0 high = 1 Case Else End Select End Sub 'Examples: ' ' '160 meters 'QRP '32-bit tuning word '32 MHz DDS MCLK '4 MHz rcvr i.f. ' 'Receiver local oscillator tuning words for 1810 KHz receive: ' '00101110 01111010 11100001 01000111 Bin = 2E7AE147 Hex = 779804999 Dec ''ratio' = 2^32/32e6 = 4294967296/32000000 = 134.217728 'receiver local oscillator freq = 779804999/134.217728 = 5809999.995 Hz 'Receive freq = 5809999.995 Hz - 4000000 Hz = 1809999.995 Hz (USB) ' ' '00010001 10000101 00011110 10111000 Bin = 11851EB8 Hex = 293936824 Dec ''ratio' = 134.217728 'receiver local oscillator freq = 293936824/134.217728 = 2189999.997 Hz 'Receive freq = 2189999.997 Hz - 4000000 Hz = '-1810000.003 Hz' (LSB) ' ' ' 'Tuning word for 1810 KHz CW transmit: ' '1.81e6 * 134.217728 = 242934087.68 Dec = E7AE147 Hex = '00001110 01111010 11100001 01000111 Bin