From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing digital counter frequency input with two analog inputs (accelerometer)

Solved!
Go to solution

I'm trying to add a frequency counter to a data acquisition program that reads analog input data from accelerometers. The frequency counter uses the NI 9402 DIO LVTTL module and the accelerometers are read with two NI 9230 IEPE modules. The analog inputs are read in "Continuous mode" at a sampling frequency. Ideally, I want to read the frequency counter at the same frequency and synchronize the counter and analog inputs. However, the NI example "Counter - Read Pulse Width and Frequency (Continuous)" shows that "Continuous mode" is not quite the same as the analog settings. I'm not able to set the sampling clock to the Onboard Clock like the analog inputs. Is there a way to synchronize them? Or, if this isn't possible, have the Counter Input in continuous output a waveform so I might approximate the frequency at a given time? I'm using the cDAQ-9174 chassis and generating digital signals using the NI 9401 module to test.

Download All
0 Kudos
Message 1 of 8
(3,087 Views)

Hi Schafbo

I found one example that might be useful.

 

Regards,

Astromaut

0 Kudos
Message 2 of 8
(3,032 Views)

Thank you for your reply. I looked over using Implicit timing for frequency measurement, and it may not be necessary to synchronize the clocks. If I am able to take time measurement using Implicit timing with Continuous "block sampling" or Reading n samples per loop, how might I record the time for each of the individual samples?

0 Kudos
Message 3 of 8
(2,998 Views)

Hi Schafbo,

 

When you say you're wanting to record the time for each of the individual samples, is this referring to the time at which each sample event occurred (either real world time or time into the acquisition) or duration of a particular sample or event?

Tyler C.
Technical Support Engineering
National Instruments
0 Kudos
Message 4 of 8
(2,976 Views)

If I record n samples with DAQmx Read in a loop with where timing is set to "Continuous" mode, I would like to be able to record the time with each of those samples. I am not sure if the DAQmx API is able to do this?

0 Kudos
Message 5 of 8
(2,962 Views)
Solution
Accepted by topic author Schafbo

No, the DAQmx API won't do that for you.  You'll need to code it up.

 

Here's the basic idea to get you started -- you need to keep track of the cumulative sum of the interval times represented by each freq measurement.

 

 

-Kevin P

 

times for freqs.png

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 6 of 8
(2,955 Views)

Thanks! I wasn't sure you could process Continuous acquisition data in the loop fast enough without causing the buffer to fill up. This is exactly what I was hoping to do.

0 Kudos
Message 7 of 8
(2,942 Views)

Note: the code I posted is not a "best practice" for efficiency, just a minimal example that would be clearer than lots of words.

 

One important part of preventing buffer overflow is to keep the DAQ loop lean and tight.  I'm not at a LabVIEW machine now to show you code, but here's some description and search terms:

 

1. use a "producer consumer" approach where the only functions in the DAQ loop are DAQmx Read and an Enqueue function where you send all the data.  The DAQ loop is then the producer.  The consumer loop would Dequeue (from the same queue reference) ,then do any processing, array accumulation or display to gui indicators.

 

2. Specific things that aren't optimal in my earlier code (none of which would affect DAQ buffer issues after moving to the producer consumer approach above):

- concatenating arrays on the output boundary of the outer while loop.  This is probably the worst offense to efficiency.

- writing to gui indicators inside the loop.  This is a medium offense.

- doing the inner For loop processing in the same loop as DAQ.  This is probably a fairly minor offense.  (It would probably be even more minor if you specified a constant # samples to read and fed the same constant to 'N' terminal of the For loop.  This would give LabVIEW some clues that it could use to be more memory efficient and reuse the auto-indexed output array.)

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 8 of 8
(2,938 Views)