OSCILLOSCOPE

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form osill 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "O-sill"
   ClientHeight    =   6255
   ClientLeft      =   4305
   ClientTop       =   3510
   ClientWidth     =   9165
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6255
   ScaleWidth      =   9165
   Begin VB.Frame Frame6 
      Caption         =   "About"
      Height          =   1575
      Left            =   6120
      TabIndex        =   22
      Top             =   4680
      Width           =   3015
      Begin VB.Label Label7 
         Caption         =   "harper@nata2.org"
         ForeColor       =   &H8000000D&
         Height          =   255
         Left            =   840
         TabIndex        =   24
         Top             =   840
         Width           =   1455
      End
      Begin VB.Label Label3 
         Caption         =   "Written by Harper Reed for CSC-302"
         Height          =   255
         Left            =   240
         TabIndex        =   23
         Top             =   600
         Width           =   2655
      End
   End
   Begin VB.Frame Frame5 
      Caption         =   "Function Generator Settings"
      Height          =   1215
      Left            =   6120
      TabIndex        =   21
      Top             =   3480
      Width           =   3015
      Begin VB.OptionButton outputOff 
         Caption         =   "off"
         Height          =   255
         Left            =   720
         Style           =   1  'Graphical
         TabIndex        =   28
         Top             =   240
         Value           =   -1  'True
         Width           =   855
      End
      Begin VB.OptionButton outputOn 
         Caption         =   "on"
         Height          =   255
         Left            =   720
         Style           =   1  'Graphical
         TabIndex        =   27
         Top             =   480
         Width           =   855
      End
      Begin MSComctlLib.Slider DAC_OUT_smplrt 
         Height          =   255
         Left            =   1080
         TabIndex        =   25
         Top             =   840
         Width           =   1815
         _ExtentX        =   3201
         _ExtentY        =   450
         _Version        =   393216
         Min             =   1000
         Max             =   6000
         SelStart        =   5000
         TickFrequency   =   1000
         Value           =   5000
      End
      Begin VB.Label Label10 
         Caption         =   "Output"
         Height          =   255
         Left            =   120
         TabIndex        =   29
         Top             =   240
         Width           =   615
      End
      Begin VB.Label Label11 
         Caption         =   "Sample Rate"
         Height          =   255
         Left            =   120
         TabIndex        =   26
         Top             =   840
         Width           =   975
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "Graph Refresh Rate"
      Height          =   855
      Left            =   3240
      TabIndex        =   11
      Top             =   5400
      Width           =   2775
      Begin MSComctlLib.Slider scrollRefresh 
         Height          =   255
         Left            =   120
         TabIndex        =   16
         ToolTipText     =   "Refresh Rate"
         Top             =   240
         Width           =   2535
         _ExtentX        =   4471
         _ExtentY        =   450
         _Version        =   393216
         Min             =   25
         Max             =   500
         SelStart        =   25
         TickFrequency   =   100
         Value           =   25
      End
      Begin VB.Label Label5 
         Caption         =   "500ms"
         Height          =   255
         Left            =   2040
         TabIndex        =   13
         Top             =   480
         Width           =   615
      End
      Begin VB.Label Label4 
         Caption         =   "25ms"
         Height          =   255
         Left            =   120
         TabIndex        =   12
         Top             =   480
         Width           =   495
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "DAC Settings"
      Height          =   975
      Left            =   0
      TabIndex        =   10
      Top             =   4440
      Width           =   6015
      Begin MSComctlLib.Slider DAC_channel 
         Height          =   255
         Left            =   1080
         TabIndex        =   19
         Top             =   600
         Width           =   4815
         _ExtentX        =   8493
         _ExtentY        =   450
         _Version        =   393216
         Min             =   1
         Max             =   6
         SelStart        =   1
         Value           =   6
      End
      Begin MSComctlLib.Slider DAC_sampleRate 
         Height          =   255
         Left            =   1080
         TabIndex        =   17
         Top             =   240
         Width           =   4815
         _ExtentX        =   8493
         _ExtentY        =   450
         _Version        =   393216
         Min             =   100
         Max             =   7000
         SelStart        =   100
         TickFrequency   =   1000
         Value           =   100
      End
      Begin VB.Label Label8 
         Caption         =   "DAC Channel"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   20
         Top             =   600
         Width           =   975
      End
      Begin VB.Label Label6 
         Caption         =   "Sample Rate"
         Height          =   255
         Left            =   120
         TabIndex        =   18
         Top             =   240
         Width           =   975
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Graph Controls"
      Height          =   855
      Left            =   0
      TabIndex        =   4
      Top             =   5400
      Width           =   3135
      Begin VB.OptionButton manual 
         Caption         =   "Manual"
         Height          =   255
         Left            =   2040
         Style           =   1  'Graphical
         TabIndex        =   9
         ToolTipText     =   "Use Manual"
         Top             =   480
         Value           =   -1  'True
         Width           =   975
      End
      Begin VB.OptionButton DAC 
         Caption         =   "DAC"
         Height          =   255
         Left            =   2040
         Style           =   1  'Graphical
         TabIndex        =   8
         ToolTipText     =   "Use DAC"
         Top             =   240
         Width           =   975
      End
      Begin VB.CommandButton startBtn 
         Caption         =   "Start"
         Height          =   495
         Left            =   120
         TabIndex        =   7
         ToolTipText     =   "Start"
         Top             =   240
         Width           =   495
      End
      Begin VB.CommandButton stopBtn 
         Caption         =   "Stop"
         Enabled         =   0   'False
         Height          =   495
         Left            =   720
         TabIndex        =   6
         ToolTipText     =   "Stop"
         Top             =   240
         Width           =   495
      End
      Begin VB.CommandButton pauseBtn 
         Caption         =   "Pause"
         Enabled         =   0   'False
         Height          =   495
         Left            =   1320
         TabIndex        =   5
         ToolTipText     =   "Pause"
         Top             =   240
         Width           =   615
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Manual Settings"
      Height          =   975
      Left            =   0
      TabIndex        =   1
      Top             =   3480
      Width           =   6015
      Begin MSComctlLib.Slider scrollAmp 
         Height          =   255
         Left            =   600
         TabIndex        =   15
         ToolTipText     =   "Amplitude"
         Top             =   600
         Width           =   5295
         _ExtentX        =   9340
         _ExtentY        =   450
         _Version        =   393216
         Min             =   1
         Max             =   2000
         SelStart        =   1
         TickFrequency   =   100
         Value           =   600
         TextPosition    =   1
      End
      Begin MSComctlLib.Slider scrollFreq 
         Height          =   255
         Left            =   600
         TabIndex        =   14
         ToolTipText     =   "Frequency"
         Top             =   240
         Width           =   5295
         _ExtentX        =   9340
         _ExtentY        =   450
         _Version        =   393216
         Min             =   1
         Max             =   10000
         SelStart        =   5000
         TickFrequency   =   1000
         Value           =   5000
      End
      Begin VB.Label Label2 
         Caption         =   "Ampl"
         Height          =   255
         Left            =   120
         TabIndex        =   3
         Top             =   600
         Width           =   375
      End
      Begin VB.Label Label1 
         Caption         =   "Freq"
         Height          =   255
         Left            =   120
         TabIndex        =   2
         Top             =   240
         Width           =   375
      End
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   50
      Left            =   120
      Top             =   3120
   End
   Begin VB.PictureBox picGraph 
      BackColor       =   &H00FFFF00&
      FillStyle       =   6  'Cross
      Height          =   3375
      Left            =   0
      MousePointer    =   2  'Cross
      ScaleHeight     =   -4150.235
      ScaleMode       =   0  'User
      ScaleTop        =   2000
      ScaleWidth      =   100
      TabIndex        =   0
      ToolTipText     =   "Graph"
      Top             =   0
      Width           =   9135
   End
End
Attribute VB_Name = "osill"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim frequency As Double


Dim amplitude As Double
Dim DAC_buffer(999) As Integer
Dim DAC_out_buffer(10000) As Integer
Function data(n, freq, amp, cyclepnts)
    data = amp * Sin(2 * 3.1415 * n * freq / cyclepnts)
End Function

Private Sub DAC_Click()
DAC.Value = True
    manual.Value = False
End Sub

Private Sub Form_Load()
  amplitude = scrollAmp.Value
    frequency = scrollFreq.Value / 1000
End Sub

Private Sub manual_Click()
    DAC.Value = False
    manual.Value = True
    
End Sub

Private Sub outputOff_Click()
Status = WFM_Group_Control(1, 1, 0)
End Sub

Private Sub outputOn_Click()
    Status2 = WFM_Group_Control(1, 1, 0)
    Dim samplerate As Double
    Dim amplitude_ As Double
    Dim frequency_ As Double
    Dim cyclepoints As Double
    amplitude_ = scrollAmp.Value
    frequency_ = scrollFreq.Value / 1000
    samplerate = DAC_OUT_smplrt.Value * 10
    cyclepoints = samplerate / frequency_
    For n = 0 To cyclepoints
        DAC_out_buffer(n) = amplitude_ * Sin(2 * 3.1415 * n / cyclepoints)
    Next n
    Status2 = WFM_Op(1, 1, 1, DAC_out_buffer(0), cyclepoints, 0,
samplerate)
End Sub

Private Sub pauseBtn_Click()
Timer1.Enabled = False
startBtn.Enabled = True
stopBtn.Enabled = False
pauseBtn.Enabled = False
End Sub




Private Sub refresh_DAC_OUT()
 Status2 = WFM_Group_Control(1, 1, 0)
    Dim samplerate As Double
    Dim amplitude_ As Double
    Dim frequency_ As Double
    Dim cyclepoints As Double
    amplitude_ = scrollAmp.Value
    frequency_ = scrollFreq.Value / 1000
    samplerate = DAC_OUT_smplrt.Value * 10
    cyclepoints = samplerate / frequency_
    For n = 0 To cyclepoints
        DAC_out_buffer(n) = amplitude_ * Sin(2 * 3.1415 * n / cyclepoints)
    Next n
    Status2 = WFM_Op(1, 1, 1, DAC_out_buffer(0), cyclepoints, 0,
samplerate)
End Sub

Private Sub scrollAmp_Scroll()
amplitude = scrollAmp.Value
If outputOn.Value Then
Status2 = WFM_Group_Control(1, 1, 0)
    Dim samplerate As Double
    Dim amplitude_ As Double
    Dim frequency_ As Double
    Dim cyclepoints As Double
    amplitude_ = scrollAmp.Value
    frequency_ = scrollFreq.Value / 1000
    samplerate = DAC_OUT_smplrt.Value * 10
    cyclepoints = samplerate / frequency_
    For n = 0 To cyclepoints
        DAC_out_buffer(n) = amplitude_ * Sin(2 * 3.1415 * n / cyclepoints)
    Next n
    Status2 = WFM_Op(1, 1, 1, DAC_out_buffer(0), cyclepoints, 0,
samplerate)
End If

    
    
End Sub


Private Sub scrollFreq_Scroll()
frequency = scrollFreq.Value / 1000
If outputOn.Value Then
Status2 = WFM_Group_Control(1, 1, 0)
    Dim samplerate As Double
    Dim amplitude_ As Double
    Dim frequency_ As Double
    Dim cyclepoints As Double
    amplitude_ = scrollAmp.Value
    frequency_ = scrollFreq.Value / 1000
    samplerate = DAC_OUT_smplrt.Value * 10
    cyclepoints = samplerate / frequency_
    For n = 0 To cyclepoints
        DAC_out_buffer(n) = amplitude_ * Sin(2 * 3.1415 * n / cyclepoints)
    Next n
    Status2 = WFM_Op(1, 1, 1, DAC_out_buffer(0), cyclepoints, 0,
samplerate)
End If
End Sub

Private Sub scrollRefresh_Change()
Timer1.Interval = scrollRefresh.Value
End Sub


Private Sub startBtn_Click()
Timer1.Interval = scrollRefresh.Value
Timer1.Enabled = True
startBtn.Enabled = False
stopBtn.Enabled = True
pauseBtn.Enabled = True
End Sub



Private Sub stopBtn_Click()
startBtn.Enabled = True
pauseBtn.Enabled = False
stopBtn.Enabled = False
Timer1.Enabled = False
picGraph.Cls
End Sub

Private Sub Timer1_Timer()

If manual.Value Then
    picGraph.Cls
    picGraph.PSet (0, data(0, frequency, amplitude, 100))
    For i = 1 To 99
    picGraph.Line -(i, data(i, frequency, amplitude, 100))
     Next i
ElseIf DAC.Value Then

Status = DAQ_Op(1, DAC_channel.Value, 1, DAC_buffer(0), 999,
DAC_sampleRate.Value * 10)
    'Status = DAQ_Op(1, 2, 1, DAC_buffer(0), 999, 50000)
    picGraph.Cls
    picGraph.PSet (0, DAC_buffer(0))
    For i = 1 To 99
    picGraph.Line -(i, DAC_buffer(i))
    Next i
End If

End Sub


