Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Frequency Measurement Gives Sporadic Errors

Hi,
I am using the Component Works CWCounter object with a PCI-6025E DAQ card to measure frequency of a squarewave input to the PFI9 pin. The frequency ranges from 20Khz to 95Khz and seems to measure correctly except that when the measurement is repeated say 20 times, then about 3 out of 20 times the frequency comes back wrong at almost double the actual frequency! This occurs at random.

Is it something I'm doing incorrectly or could it be a Windows/CPU speed/resource/interrupt type of problem?

Here is the basic setup in VB6 where it measures pulse period and then inverts the result to convert to frequency:

Form1.CWDAQTools1.RouteSignal 1, cwrsPinPFI9, cwrsSourceNone
With Form1.CWCounter1
.Rese
t
.CountDirection = cwctrUpDir
.Counter = 0
.MeasurementType = cwctrPulsePeriodFallingEdge
.TimebaseSource = cwctrNIDAQChoosesTB
.TimebaseSignal = 20000000
.Configure
End With
Form1.CWCounter1.Configure
Form1.CWCounter1.start
While IsRunning = True And TimeOut > 0 ' wait until measurement is completed
DoEvents
TimeOut = TimeOut - 1
Wend

If period > 0 Then Freq = 1 / CSng(period)

Private Sub CWCounter1_AcquiredData(Measurement As Variant, ByVal OverFlow As Boolean)
period = Measurement
IsRunning = False
End Sub

Any suggestions? I can't seem to figure out why the measurement is correct only about 85% of the time. Are there some options or configurations that I'm not utilizing on the CWCounter object? Any help is appreciated.

Thanks,
Tony Gioiosa
0 Kudos
Message 1 of 3
(3,454 Views)
There are Visual Basic examples that are already built that you can install when you install NI-DAQ support for the Visual Basic environment. Examples are great for checking out your own code against the example.

Pulse period measurements can have some error due to possible synchronization of the gate and source signals. Synchronization of the signal pulses cause the final count to be off by +/- 1.

If you are using a 20 MHz timebase as your source for period measurement, then you can calculate the possible error of your frequency result as F/(20MHz-F), where F is the frequency you are measuring. If the resulting calculation is too high, then you should consider measuring frequency directly to get more accurate results. The downside of measuring frequency direc
tly is that you need more than one counter to get the job done.
0 Kudos
Message 2 of 3
(3,454 Views)
Thought I would add to this since I had the same problem and solved it....if the signal coming into the gate is not a true TTL signal (i.e. a square wave that is really analog 0-5V) then the rise time may not be perfectly vertical, causing the counter to count an extra edge sometimes. It's tricky becuase you can't see it on a digital scope but it usually shows up as a reading that is a multiple of the frequency you are expecting. What worked for me was putting a Schmidt trigger chip between the signal and the gate to make the rising edge perfect....
0 Kudos
Message 3 of 3
(3,454 Views)