Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Digital frequency measurement speed in labview

Solved!
Go to solution
I am using a USB 6210 device to measure low frequencies of 50 to 1000 Hz. I need to log the frequency every 50ms. I do this in a while loop in labview using a 1 counter low frequency measurement in labview and saving the data using express VI.Each iteration of the loop takes atleast 60 to 100 ms just to read the frequency inside the loop. How do i increase the speed of measurement in Labview ?
0 Kudos
Message 1 of 11
(13,357 Views)

Hi PraveenB,

 

Is the Express VI for logging inside your while loop?  You might consider buffering your writes to limit the time spent in overhead writing to the file, you can implement this with a Producer Consumer architecture which you can read about here.  Or even taking the write outside the loop and do all the writing once the program is done depending on how long this needs to run.

 

If it is still running slow I would like to see your VI or a screen shot of it so that I can more easily assist you.

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 2 of 11
(13,339 Views)

Hi Jason,

 

Thankyou very much for your reply.

 

I removed the express VI datalogging which was inside the while loop. The only thing i am doing inside the while loop is reading the frequency of the signal at the gate of Counter. I varied the input frequency of the signal from 50 Hz to 500 Hz. Every time i measured the time it takes for each iteration for reading the frequency of input signal at the gate. The time taken is around 60 ms. This is true for any input signal frequency and it does not change. So essentially if i am using a single counter low frequency measurement, and trying to read the frequency of a 500 Hz signal at the gate (2 ms period), why does the while loop take 60 ms to read out this value of 500 Hz?

 

According to my understanding, counter is internally using a 20 MHz time base  and counting pulses between two rising or falling edges of the signal at the gate. So the counter should take a maximum of 4 ms to measure the frequency of 500 Hz at the gate input with two rising edges 2 ms apart. But the labview program takes around 60 ms to get the measured value from the counter. Why does it take so long ? Can i make it read faster than this in the while loop ? I have attached the block diagram of my program.

 

Best regards,

Praveen B

 

 

 

  

 

 

 

 

0 Kudos
Message 3 of 11
(13,325 Views)

PraveenB,

 

Your VI is being software timed the way it is currently constructed.  Try adding a DAQmx Timing VI (continuous samples if you so choose) and a DAQmx Start Task VI.

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 4 of 11
(13,305 Views)

Hi Jason,

 

I added a DAQmx Timing VI and DAQmx Start Task VI outside the loop and now the DAQmx Read VI takes around 20ms to read the frequency value. This is sufficient for my work. Thankyou for the suggestion.

 

But now i am facing a different problem. I am using a DAQmx Channel property node channel to set the digital filter minium pulse width and enable it, as my input signal is noisy. I have used this after the DAQmx create channel task VI. But now when i run the program, i get an error in  the  DAQmx Start Task VI task. The error number is -200774. The description is "Terminal has already been configured with a different Minimum Pulse Width by another propery in this task". So how do i override with my property settings ?

 

Attached is the screen shot. 

 

Sincerely,

Praveen B

 

 

 

 

0 Kudos
Message 5 of 11
(13,289 Views)

PraveenB,

 

I just tried a replication of your code and it worked fine.  What is your minPulseWidth, Timing Clock Source, and Sampling Rate.  I set minPulseWidth to 125ns.

 

After which VI is the error being generated?  The Start or the Timing?

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 6 of 11
(13,272 Views)

Hi Jason,

 

I have set the following -

 

minPulseWidth =  6.425e-6    (Property Node)

Timing Clock Souce (Source) = /Dev1/PFI2  (Timing VI) - This is the pin for which i need frequency measurement

Counter(s) = Dev1/Ctr1 (Timing VI)

sample mode = continuous samples  (Timing VI)

samples per channel  (buffer size) = 100 (Timing VI)

rate (samples/second) = 20.00 (Timing VI)

 

I get an error after Start VI. May be the Start VI is receiving the minPulseWidth = 0 from some other SubVI internal to it. I am not sure.

If i dont use the propery node, then it works fine with no error and measures the frequency correctly with the above settings.

 

Sincerely,

Praveen B

0 Kudos
Message 7 of 11
(13,268 Views)
Solution
Accepted by PraveenB

PraveenB,

 

Here is a table of the Counter terminals and related PFI lines.  This can be found in the NI DAQmx Help. (http://digital.ni.com/public.nsf/allkb/CCDFC93878BD8781862570FC00559980?OpenDocument)

 

Default NI-DAQmx Counter Terminals

Counter/Timer SignalDefault Pin NumberSignal Name
CTR 0 SRC1PFI 0
CTR 0 GATE2PFI 1
CTR 0 AUX1PFI 0
CTR 0 OUT6PFI 4
CTR 0 A1PFI 0
CTR 0 Z3PFI 2
CTR 0 B2PFI 1
CTR 1 SRC4PFI 3
CTR 1 GATE3PFI 2
CTR 1 AUX4PFI 3
CTR 1 OUT7PFI 5
CTR 1 A4PFI 3
CTR 1 Z2PFI 1
CTR 1 B3PFI 2
FREQ OUT8

PFI 6

 

When you choose counter 1 in the Create channel VI it automatically reserves the gate which is PFI2.  If you use Counter 0 then PFI 2 will work fine.  Likewise if you use Counter 1 you can use anything but PFI 2.

Message Edited by Jason_D on 10-24-2008 11:43 AM
Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 8 of 11
(13,265 Views)

Hi Jason,

 

I got it right now after configuring the source of the timing VI properly.

Thankyou very much for all your help.

 

Sincerely,

Praveen B

0 Kudos
Message 9 of 11
(13,260 Views)

Hello to you all,

I apologize for resurrecting this old thread, but my issue is similar. I followed the advice and used timing VI, but I'm getting error 200300 Invalid timing type.

The project is simple. I have encoder with 1000 pulses per rev and it is mounted on a shaft. I'm trying to monitor the frequency and thus the rotation of the shaft. At the end there will be 2 channels per each encoder and ~3 encoders total. I'll be using PCI6602 DAQ, but right now for the development I'm using USB6221. Let's say the frequency is between 10kHz and 20kHz. What am I doing wrong??

Thanks

Marty

Message Edited by Czechmarty on 11-02-2009 05:37 PM
Download All
0 Kudos
Message 10 of 11
(11,775 Views)