Frequency of count pulses to VM167

Hi, I am very happy with the performance of the VM167, having purchased 3 units to date with only one problem: Sometimes, on opening I get a card error and the only way to clear it is to pull out the USB plug, replace it and start again. This always works.

Another question is whether it is possible to generate in Excel a display of the frequency of pulses input on Input 1? Could this be done by counting pulses over a 1 second interval? Please suggest the code, if possible.

Thanks.

[quote]Another question is whether it is possible to generate in Excel a display of the frequency of pulses input on Input 1? Could this be done by counting pulses over a 1 second interval? Please suggest the code, if possible.[/quote]Yes, to get display of the frequency of pulses you can use 1 sec timer interval and reset the pulse counter after each read.
Please see the Excel code example in this thread:
viewtopic.php?f=3&t=7849
You’ll get the frequency reading if the pulse count is high enough within one second.
If not, you have to use e.g. 10 sec timer and divide the pulse count by 10 to get the frequency in Hz.

Hi,
I am using such a timer set at 0.1sec to update the counter (say this is called counter 1) value in the spreadsheet in real time.
Is it possible to do something like the following:

Create counter2
Set m=0
save counter1 value to a cell (1,30)
At each scan, increment m=m+1
when m=10,
counter1-saved value save to cell(1,8)
reset m=0
cell(1,8) will then refresh every 1 second, showing a count value of between 10 & 100, which will be the frequency of counts.

Is this possible?

[quote]Create counter2
Set m=0
save counter1 value to a cell (1,30)
At each scan, increment m=m+1
when m=10,
counter1-saved value save to cell(1,8)
reset m=0

cell(1,8) will then refresh every 1 second, showing a count value of between 10 & 100, which will be the frequency of counts.

Is this possible?[/quote]Yes, this should be possible.
I think you should also reset the counter.

I’m afraid that this is the extent of my programming skills! Could you please suggest the code?

Here is some example code.
Counted pulses over 1 second interval are displayed in cells 1,1 and the average over 10 seconds is displayed in cells 1,2. [code]Option Explicit
Private Declare Function OpenDevices Lib “vm167.dll” () As Long
Private Declare Sub CloseDevices Lib “vm167.dll” ()
Private Declare Sub InOutMode Lib “vm167.dll” (ByVal CardAddress As Long, ByVal HighNibble As Long, ByVal LowNibble As Long)
Private Declare Function ReadAnalogChannel Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib “vm167.dll” (ByVal CardAddress As Long, ByRef Buffer As Long)
Private Declare Sub OutputAllDigital Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Data As Long)
Private Declare Sub ClearDigitalChannel Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib “vm167.dll” (ByVal CardAddress As Long)
Private Declare Sub SetDigitalChannel Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub SetAllDigital Lib “vm167.dll” (ByVal CardAddress As Long)
Private Declare Function ReadDigitalChannel Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib “vm167.dll” (ByVal CardAddress As Long) As Long
Private Declare Function ReadCounter Lib “vm167.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub ResetCounter Lib “vm167.dll” (ByVal CardAddress As Long)
Private Declare Sub SetPWM Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Channel As Long, ByVal Data As Long, ByVal Freq As Long)
Private Declare Sub OutputAllPWM Lib “vm167.dll” (ByVal CardAddress As Long, ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Function VersionDLL Lib “vm167.dll” () As Long
Private Declare Function VersionFirmware Lib “vm167.dll” (ByVal CardAddress As Long) As Long
Private Declare Function Connected Lib “vm167.dll” () As Long
Private Declare Sub ReadBackPWMOut Lib “vm167.dll” (ByVal CardAddress As Long, ByRef Buffer As Long)
Private Declare Function ReadBackInOutMode Lib “vm167.dll” (ByVal CardAddress As Long) As Long

Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long

Dim TimerID As Long
Dim TimerSeconds As Single
Dim n As Long
Dim CardAddress As Long
Dim Cards As Long
Dim OldCount As Long

Sub Button1_Click()
Cards = OpenDevices()
Select Case Cards
Case 0
ActiveSheet.Cells(1, 8) = “Card open error.”
Case 1
ActiveSheet.Cells(1, 8) = “Card 0 connected.”
CardAddress = 0
Case 2
ActiveSheet.Cells(1, 8) = “Card 1 connected.”
CardAddress = 1
Case 3
ActiveSheet.Cells(1, 8) = “Cards 0 and 1 connected.”
CardAddress = 0
Case -1
ActiveSheet.Cells(1, 8) = “Card not found.”
End Select
If Cards > 0 Then
InOutMode CardAddress, 1, 1
TimerSeconds = 1 ’ the timer interval is now 1 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End If
n = 0
OldCount = 0
ResetCounter CardAddress
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim Count As Long
Count = ReadCounter(CardAddress)
ActiveSheet.Cells(1, 1) = Count - OldCount
OldCount = Count
n = n + 1
If n = 10 Then
ActiveSheet.Cells(1, 2) = OldCount \ 10
n = 0
OldCount = 0
ResetCounter CardAddress
End If
End Sub

Sub Button2_Click()
KillTimer 0&, TimerID
CloseDevices
ActiveSheet.Cells(1, 8) = “Card closed”
End Sub[/code]

Works great!
Thanks for the support, as always!

No problem
Thank you for the reply.
Enjoy!