DETAILED DESCRIPTION
Two-Channel PC Based Oscilloscope using USB port of the PC that operates at up to 30 kHz with ±50V input voltage.
Time base 500mS to 20uS, scale 1, 2, 5.
The oscilloscope uses IC PIC18F2550 microcontroller chip from Microchip and mikrobasic compiler.
Proteus. Schematics diagram:
The virtual communication block diagram is in the picture.
I have chosen Mikroe Mikrobasic because I am an expert in programming
Microsoft Visual Basic graphics, VB6-SP6 and Visual Studio Net.
Virtual communication is via the Virtual USB program in Proteus and mcHID.dll from your PC.
The program has a number of sections: data acquisition, bi-directional USB communication with the PC, transmission confirmation with a code.
Before each USB transmission we do a signal synchronization and the packets are intelligently concatenated for on screen image continuity.
It is declared in the VB6-SP6 oscilloscope program and has the following bilateral communication functions:
Option Explicit
Public Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
' HID interface API declarations...
Declare Function hidConnect Lib "mcHID.dll" Alias "Connect" (ByVal pHostWin As Long) As Boolean
Declare Function hidDisconnect Lib "mcHID.dll" Alias "Disconnect" () As Boolean
Declare Function hidGetItem Lib "mcHID.dll" Alias "GetItem" (ByVal pIndex As Long) As Long
Declare Function hidGetItemCount Lib "mcHID.dll" Alias "GetItemCount" () As Long
Declare Function hidRead Lib "mcHID.dll" Alias "Read" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean
Declare Function hidWrite Lib "mcHID.dll" Alias "Write" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean
Declare Function hidReadEx Lib "mcHID.dll" Alias "ReadEx" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean
Declare Function hidWriteEx Lib "mcHID.dll" Alias "WriteEx" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean
Declare Function hidGetHandle Lib "mcHID.dll" Alias "GetHandle" (ByVal pVendorID As Long, ByVal pProductID As Long) As Long
Declare Function hidGetVendorID Lib "mcHID.dll" Alias "GetVendorID" (ByVal pHandle As Long) As Long
Declare Function hidGetProductID Lib "mcHID.dll" Alias "GetProductID" (ByVal pHandle As Long) As Long
Declare Function hidGetVersion Lib "mcHID.dll" Alias "GetVersion" (ByVal pHandle As Long) As Long
Declare Function hidGetVendorName Lib "mcHID.dll" Alias "GetVendorName" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetProductName Lib "mcHID.dll" Alias "GetProductName" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetSerialNumber Lib "mcHID.dll" Alias "GetSerialNumber" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetInputReportLength Lib "mcHID.dll" Alias "GetInputReportLength" (ByVal pHandle As Long) As Long
Declare Function hidGetOutputReportLength Lib "mcHID.dll" Alias "GetOutputReportLength" (ByVal pHandle As Long) As Long
Declare Sub hidSetReadNotify Lib "mcHID.dll" Alias "SetReadNotify" (ByVal pHandle As Long, ByVal pValue As Boolean)
Declare Function hidIsReadNotifyEnabled Lib "mcHID.dll" Alias "IsReadNotifyEnabled" (ByVal pHandle As Long) As Boolean
Declare Function hidIsAvailable Lib "mcHID.dll" Alias "IsAvailable" (ByVal pVendorID As Long, ByVal pProductID As Long) As Boolean
' windows API declarations - used to set up messaging...
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' windows API Constants
Private Const WM_APP = 32768
Private Const GWL_WNDPROC = -4
Private FPrevWinProc As Long ' Handle to previous window procedure
Private FWinHandle As Long ' Handle to message window
' HID message constants
Private Const WM_HID_EVENT = WM_APP + 200
Private Const NOTIFY_PLUGGED = 1
Private Const NOTIFY_UNPLUGGED = 2
Private Const NOTIFY_CHANGED = 3
Private Const NOTIFY_READ = 4
Public Type POINTAPI
Xa As Long
Ya As Long
End Type
Public punct1a() As POINTAPI
Public punct2a() As POINTAPI
Public punct3a() As POINTAPI
Public punct4a() As POINTAPI
Public punct1b() As POINTAPI
Public punct2b() As POINTAPI
Public punct3b() As POINTAPI
Public punct4b() As POINTAPI
Public Function ConnectToHID(ByVal pHostWin As Long) As Boolean
FWinHandle = pHostWin
ConnectToHID = hidConnect(FWinHandle)
FPrevWinProc = SetWindowLong(FWinHandle, GWL_WNDPROC, AddressOf WinProc) 'AddressOf WinProc)
End Function
' Unhook from the HID controller and disconnect...
Public Function DisconnectFromHID() As Boolean
DisconnectFromHID = hidDisconnect
SetWindowLong FWinHandle, GWL_WNDPROC, FPrevWinProc
End Function
' This is the procedure that auto intercepts the HID controller messages...
Private Function WinProc(ByVal pHWnd As Long, ByVal pMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If pMsg = WM_HID_EVENT Then
Select Case wParam
' HID device has been plugged message...
Case Is = NOTIFY_PLUGGED
Form3.OnPlugged (lParam)
' HID device has been unplugged
Case Is = NOTIFY_UNPLUGGED
Form3.OnUnplugged (lParam)
' controller has changed...
Case Is = NOTIFY_CHANGED
Form3.OnChanged
' read event...
Case Is = NOTIFY_READ
Form3.OnRead (lParam)
End Select
End If
' next...intercept
WinProc = CallWindowProc(FPrevWinProc, pHWnd, pMsg, wParam, lParam)
End Function
To access these functions, initialization subroutines, ADC sample packet detection, processing
and transmission of new commands are used to the PIC.
I will fully explain the operation of the device
and I will post all the simulation files in Mikrobasic, Visual Basic and Proteus.
When connecting the USB port to the PC through the virtual proteus port,
it is recognized and the sound of Ding is heard.
The connection takes a few seconds.
The subroutines connect the oscilloscope to the PC with a protected bidirectional channel
by uniquely identifying with VendorID and ProductID.
'************************************************* ****************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'************************************************* ****************
Public Sub OnChanged()
Dim DeviceHandle As Long
' get the handle of the device we are interested in, then set
' its read notify flag to true - this ensures you get a read
' notification message when there is some data to read...
DeviceHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify DeviceHandle, True
End Sub
'************************************************* ****************
' a HID device has been plugged in...
'************************************************* ****************
Public Sub OnPlugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
Label1 = "Osciloscopul-USB conectat"
Else
Label1 = "Nu este Osciloscopul-USB"
End If
End Sub
'************************************************* ****************
' a HID device has been unplugged...
'************************************************* ****************
Public Sub OnUnplugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
Label1.Caption = "Osciloscopul-USB deconectat "
Else
Label1.Caption = "Nu exista "
End If
End Sub
Private Sub Connect_usb_Initializare() 'chemata de load
On Error Resume Next
VendorID = &H1234 ' VendorID PIC18Fxxxx
ProductID = &H1
scon = ConnectToHID(Me.hwnd) ' conectare la HID
If scon = True Then
Erase BufferOut
Erase BufferIn
Label4.ForeColor = vbBlack
Label4.Caption = "Portul USB este activ" & vbCrLf
Else
Label4.ForeColor = vbRed
Label4.Caption = "Portul USB nu este activ"
End If
End Sub
Bilateral communication starts with command "START"
It initializes the Time Base, vertical amplification, synchronization polarity and passes them to the buffer microcontroller, via the function:
hidWriteEx VendorID, ProductID, BufferOut (0)
The microcontroller receives the data, sets the oscilloscope with the PIC and starts to
memorize samples of the 10-bit input signal, 462 samples and sent to the PC in 15 packets of 64 bytes.
Use Microsoft Visual Basic 6-SP6, Proteus 8, and Mikrobasic PRO for PIC.
Please note: PicOscilloscope.exe works only after you have set up
VB6-SP6 on your computer. You can compile the program and customize the oscilloscope
Success!
@gsabac
Authors
- /
- Active Participants
Components & Releases
Fabricate
Delete release
Are you sure you want to delete this Release?
This action cannot be undone.
Unable to download from CircuitMaker
You cannot download files inside CircuitMaker.
Please, open this page in browser and download file from there.
To copy hyperlink, press Ctrl+C with selected text below:
Comments ()