I want to write a code in VB 6.0 which will measure the width of a pulse to calculate the rpm of a rotating shaft.
A gear is mounted on the shaft and a photencoder reads the rotation of the shaft and gives a square wave as the output pulse.
Also I need to plot the change in rpm vs time when there is a load on the shaft.
I did get a code for measuring the pulse width from this website. I attach the same here.
' TachCounter.Vbp
'
' Description:
' This measures time and period of the output from the tachometer circuit.
' It then displays the value of the selected events or time in the CWNumEdit
' control. All of these events are found with the CWCounter control. You
' can use the CWCounter control to perform counting and other measurement
' operations on a data acquisition device like pulse width measuremnet also.
'
' Pin Connection Information:
' The necessary pin connections will vary depending on what operation is
' selected by the user. When the user's selection is made, the Signal Input
' indicator will display the necessary connections. These connections are also
' listed below:
'
' Time - No connection needed
' Period - Connect signal to counter gate
' '
Option Explicit
Dim IsRunning As Boolean
Private Sub CWCounter1_AcquiredData(Measurement As Variant, ByVal Overflow As Boolean)
CWNumEdit1 = Measurement
IsRunning = False
End Sub
'Allows the user to select which counter application they would like to perform.
'Based upon this selection, the corresponding 'Signal Input' caption will be displayed.
Private Sub CWSlide1_PointerValueChanged(ByVal Pointer As Long, Value As Variant)
Select Case Value
Case 1
Label2.Caption = "No connection needed."
CWNumEdit1.FormatString = ".0##"" s"""
Case 2
Label2.Caption = "Connect signal to counter gate."
CWNumEdit1.FormatString = ".0# k""s"""
End Select
End Sub
'Reads the current value of the counter; whether it be a number of events, time,
'period, or pulse width. This value is displayed in the 'Measurement' indicator.
Private Sub Read_Click()
Dim data As Variant, Overflow As Boolean
CWCounter1.ReadMeasurement data, Overflow
CWNumEdit1 = data
End Sub
'Starts the counter operation corresponding to the selection previously made by the
'user.
Private Sub Start_Click()
On Error GoTo ErrHandler
CWCounter1.Reset
With CWCounter1
'Time measurement
.MeasurementType = cwctrTime
.Time = cwctrFrequencyTB
.TimebaseSignal = 100000
'Period measurement
.MeasurementType = cwctrPulsePeriodRisingEdge
.Period = cwctrNIDAQChoosesTB
End Select
End With
CWCounter1.Configure
CWCounter1.Start
IsRunning = True
Exit Sub
rpm = 5 / Period ' I need to use this formula for calculating the rpm
ErrHandler:
MsgBox "DAQ Error: " + Err.Description
End Sub
I would be grateful if some one is able to say what I should be doing as I dont have any prior experience in coding in VB 6.0.
I cant figure out head or tail of codes online. I'm not able to distinguish between VB 6.0 code and VB.net.
I also need to know how I can talk to ports from the DAQ card (NI-DAQ 7).
Many thanks in advance.