VERSION 5.00 Begin VB.Form fmMain BorderStyle = 1 'Fixed Single Caption = "Huff Puff Simulation" ClientHeight = 5895 ClientLeft = 45 ClientTop = 330 ClientWidth = 7380 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 5895 ScaleWidth = 7380 StartUpPosition = 3 'Windows Default Begin VB.TextBox ebMaxDriftHz Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 3780 TabIndex = 18 Text = "800" Top = 960 Width = 675 End Begin VB.TextBox ebMaxHz Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 1020 TabIndex = 16 Text = "1200" Top = 960 Width = 1215 End Begin VB.CommandButton btStop Caption = "Stop" Height = 495 Left = 6300 TabIndex = 15 Top = 720 Width = 975 End Begin VB.TextBox ebSize Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00000000& Height = 330 Left = 5340 TabIndex = 13 Text = "60" Top = 540 Width = 735 End Begin VB.CommandButton btGo Caption = "GO" Height = 495 Left = 6300 TabIndex = 12 Top = 120 Width = 975 End Begin VB.TextBox ebStep Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00C00000& Height = 330 Left = 5340 Locked = -1 'True TabIndex = 11 Top = 120 Width = 735 End Begin VB.TextBox ebDelayStages Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 3780 TabIndex = 9 Text = "256" Top = 540 Width = 675 End Begin VB.TextBox ebVFODivisor Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 3780 TabIndex = 7 Text = "256" Top = 120 Width = 675 End Begin VB.TextBox ebVFO Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 1020 TabIndex = 5 Text = "5,000,000" Top = 540 Width = 1215 End Begin VB.TextBox ebCrystal Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 1020 TabIndex = 3 Text = "32,000,000" Top = 120 Width = 1215 End Begin VB.Frame Frame1 Caption = "Performance" BeginProperty Font Name = "Times New Roman" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = -1 'True Strikethrough = 0 'False EndProperty ForeColor = &H00800000& Height = 4455 Left = 60 TabIndex = 0 Top = 1380 Width = 7215 Begin VB.TextBox eb11 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 30 Top = 3960 Width = 675 End Begin VB.TextBox eb10 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 29 Top = 3600 Width = 675 End Begin VB.TextBox eb9 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 28 Top = 3240 Width = 675 End Begin VB.TextBox eb8 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 27 Top = 2880 Width = 675 End Begin VB.TextBox eb7 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 26 Top = 2520 Width = 675 End Begin VB.TextBox eb6 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 25 Top = 2160 Width = 675 End Begin VB.TextBox eb5 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 24 Top = 1800 Width = 675 End Begin VB.TextBox eb4 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 23 Top = 1440 Width = 675 End Begin VB.TextBox eb3 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 22 Top = 1080 Width = 675 End Begin VB.TextBox eb2 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 21 Top = 720 Width = 675 End Begin VB.TextBox eb1 Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 6420 TabIndex = 20 Top = 360 Width = 675 End Begin VB.PictureBox output Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 3975 Left = 120 ScaleHeight = 3945 ScaleWidth = 6165 TabIndex = 1 Top = 360 Width = 6195 End End Begin VB.Label Label8 Caption = "Max Drift Hz/s" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 2460 TabIndex = 19 Top = 1020 Width = 1275 End Begin VB.Label Label7 Caption = "Max Hz/s" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 120 TabIndex = 17 Top = 1020 Width = 915 End Begin VB.Label Label6 Caption = "Size" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 4740 TabIndex = 14 Top = 600 Width = 555 End Begin VB.Label Label5 Caption = "Step" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 4740 TabIndex = 10 Top = 180 Width = 555 End Begin VB.Label Label4 Caption = "Delay Stages" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 2460 TabIndex = 8 Top = 585 Width = 1335 End Begin VB.Label Label3 Caption = "VFO Divisor" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 2460 TabIndex = 6 Top = 165 Width = 1155 End Begin VB.Label Label2 Caption = "VFO" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 120 TabIndex = 4 Top = 600 Width = 615 End Begin VB.Label Label1 Caption = "Crystal" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 120 TabIndex = 2 Top = 180 Width = 615 End End Attribute VB_Name = "fmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Option Base 0 Const IDLE_PRIORITY_CLASS = &H40 Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long Dim stopIt As Boolean Private Function col(ripple, stepSize As Double) As Integer If ripple > stepSize Then col = 15 Else ' MsgBox Format(ripple, "0.000") + " " + Format(2 + 10 * Log(1 + ripple) / Log(1 + stepSize), "0.000") col = Int(2 + 10 * Log(1 + ripple) / Log(1 + stepSize)) End If End Function Private Sub legend(eb As TextBox, colour As Double, stepSize As Double) Dim num As Double num = Exp((colour) * Log(1 + stepSize) / 10) - 1 eb.Text = "< " + Format(num, "0.00") eb.BackColor = QBColor(colour + 1) End Sub Private Function MaxVal(d1, d2) As Double If d1 > d2 Then MaxVal = d1 Else MaxVal = d2 End If End Function Private Sub btGo_Click() Dim x, y As Integer Dim correctionRate, driftRate As Double Const band As Double = 10000 Dim crystal, vfo, vfoDivisor As Double Dim delayStages As Long Dim tankMultiplier, correctionDivisor, drift As Double Dim i, iterations As Long Dim t As Double Dim xoState, xoXor, xoDelayed As Boolean Dim xo() As Boolean Dim correction, tank, frequency As Double Dim stepSize As Double Dim ripple, rippleMin, rippleMax As Double SetPriorityClass GetCurrentProcess, IDLE_PRIORITY_CLASS output.Cls output.ScaleMode = 3 output.DrawWidth = 1 output.ScaleWidth = CInt(ebSize.Text) output.ScaleHeight = output.ScaleWidth * 0.75 stopIt = False crystal = CDbl(ebCrystal.Text) vfo = CDbl(ebVFO.Text) vfoDivisor = CDbl(ebVFODivisor.Text) delayStages = CLng(ebDelayStages.Text) stepSize = vfo * vfo / (vfoDivisor * delayStages * crystal) ebStep.Text = Format(stepSize, "##0.0") tankMultiplier = vfo * 0.5 / band ReDim xo(delayStages) legend eb1, 1, stepSize legend eb2, 2, stepSize legend eb3, 3, stepSize legend eb4, 4, stepSize legend eb5, 5, stepSize legend eb6, 6, stepSize legend eb7, 7, stepSize legend eb8, 8, stepSize legend eb9, 9, stepSize legend eb10, 10, stepSize legend eb11, 11, stepSize For y = 0 To output.ScaleHeight - 1 For x = 0 To output.ScaleWidth - 1 correctionRate = (x + 1) * CDbl(ebMaxHz.Text) / output.ScaleWidth driftRate = y * CDbl(ebMaxDriftHz.Text) / output.ScaleHeight correctionDivisor = vfo * tankMultiplier / (vfoDivisor * correctionRate) drift = vfoDivisor * driftRate / (vfo * tankMultiplier) tank = 5 t = 0 iterations = 10 * (stepSize / MaxVal((1 + driftRate), correctionRate / 3)) / (vfoDivisor / vfo) rippleMin = 1E+99 rippleMax = 0 i = 0 While i < iterations xoState = (t * crystal - Int(t * crystal) > 0.5) xoDelayed = xo(i Mod delayStages) xo(i Mod delayStages) = xoState xoXor = xoState Xor xoDelayed If xoXor Then correction = 1 / correctionDivisor Else correction = -1 / correctionDivisor tank = tank + drift + correction frequency = vfo + (tank - 5) * tankMultiplier t = t + vfoDivisor / frequency If i > iterations / 2 Then If frequency < rippleMin Then rippleMin = frequency If frequency > rippleMax Then rippleMax = frequency End If If frequency - vfo > 2 * stepSize Then rippleMin = 0 rippleMax = 99999999 i = iterations End If i = i + 1 Wend ripple = rippleMax - rippleMin output.Line (x, output.ScaleHeight - y)-(x + 1, output.ScaleHeight - y - 1), QBColor(col(ripple, stepSize)), BF DoEvents If stopIt Then Exit Sub Next x Next y End Sub Private Sub btRepaint_Click() Refresh End Sub Private Sub btStop_Click() stopIt = True End Sub