I have something that works now, but I want to know if there is a better way. I am using a 6023E, I have a Hall Effect switch that goes low then high each rev when a magnet goes by. I have the signal connected to the GATE pin on counter0. I poll the card for the RPM over and over using code based closely on the example STCsinglePeriodMeasure. While this works, I'm not sure exactly what this code is doing. Do I need to call the entire thing every time? The problem is I need to reset and arm the counter each time before starting the counter, and calling everything was the only way I could get it to work. I'm looking for a way to either trim this down, or maybe there is another way altogether that is more apporpriate. Here's the code:
iDevice% = 1
ulGpctrNum& = ND_COUNTER_0
ulArmed& = ND_YES
ulTCReached& = ND_NO
iYieldON% = 1
iStatus% = GPCTR_Control(iDevice%, ulGpctrNum&, ND_RESET)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Control/RESET", iIgnoreWarning%)
iStatus% = GPCTR_Set_Application(iDevice%, ulGpctrNum&, ND_SINGLE_PERIOD_MSR)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Set_Application", iIgnoreWarning%)
iStatus% = GPCTR_Change_Parameter(iDevice%, ulGpctrNum&, ND_SOURCE, ND_INTERNAL_100_KHZ)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning%)
iStatus% = GPCTR_Change_Parameter(iDevice%, ulGpctrNum&, ND_GATE, ND_DEFAULT_PFI_LINE)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Change_Parameter/GATE", iIgnoreWarning%)
iStatus% = GPCTR_Change_Parameter(iDevice%, ulGpctrNum&, ND_INITIAL_COUNT, ulCount&)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning%)
iStatus% = GPCTR_Control(iDevice%, ulGpctrNum&, ND_PROGRAM)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Control/PROGRAM", iIgnoreWarning%)
' Loop until 'ulGpctrNum' is no longer armed, or run window is closed.
Do
iStatus% = GPCTR_Watch(iDevice%, ulGpctrNum&, ND_ARMED, ulArmed&)
DoEvents
Loop While ((ulArmed& = ND_YES) And (iStatus% = 0)) And RunWindow.ExitStatus = "Running"
If RunWindow.ExitStatus = "Running" Then
'Run window wasn't closed, so read data.
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Watch/ARMED", iIgnoreWarning%)
iStatus% = GPCTR_Watch(iDevice%, ulGpctrNum&, ND_COUNT, ulCount&)
iRetVal% = NIDAQErrorHandler(iStatus%, "GPCTR_Watch/COUNT", iIgnoreWarning%)
iStatus% = GPCTR_Watch(iDevice%, ulGpctrNum&, ND_TC_REACHED, ulTCReached&)
If (ulTCReached& = ND_YES) Then
MsgBox "Counter reached terminal count! RPM value may be incorrect"
Else
'ulCount is the period in microseconds, RPM = 1/val*(100000ms/s)*(60s/min)
RPM = 6000000 / ulCount&
' Debug.Print RPM
RunWindow.RPM.Text = Str(RPM)
End If