Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to graph the counter frequency

Hello, does anyone know how to make a graph from a frequency signal that comes from a counter?
It seems that I first need to convert the frequency signal (scalar) into a waveform type.
I do not know how do this. Any suggestions for me?
As a basis I use the "Meas Dig Frequency-Low Freq 1 Ctr.vi" example from NI for the frequency measurement.

Thanks,
Peter
0 Kudos
Message 1 of 4
(4,149 Views)
Peter,

I can't look at the example you mentioned from the PC I'm at now, but I can describe the way I've always done it.

I'm assuming that the incoming frequency varies, and is calculated by timestamping the incoming edges. This would mean that the hardware is doing something like period measurement and the sample rate varies with the varying periods. Such data wouldn't be suitable for the waveform datatype which assumes a constant interval time dt.

I would recommend graphing on an XY Graph. The Y data is your frequency array. The X (time) data is derived from it pretty simply. First send your frequency array through a 1/x function block to create an array of individual interval times. Then perform a cumulative sum of the interval array to produce a Time array for your X axis.

The cumulative sum can be obtained with a For loop with a single shift register initialized to 0. Auto-index the loop with the interval array. Sum each element with the left-hand shift register value. Send the sum to both the right-hand shift register and to an auto-indexed output for cumulative time.

-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 2 of 4
(4,143 Views)

Hi Kevin,

you've outlined the solution quite well in this older post, which is useful in my current application.  I just have a question about building the XY Chart.

 

From the Ni docs I gather that the data can be in the form of a cluster composed of an x and y array.  I used a bundle function to build a cluster of the 2 arrays. The first comes from the for-loop as you described and the second comes from my frequency measurement which is transformed into a speed and then built into an array.  I could not create the input cluster with X and Y as shown in the video. 

 

When I run the program the XY graph axiis and grid bounce around while the counter is counting, but I do not get a plot of speed (derived from frequency) vs time as expected, so likely there is something larger askew with my datatypes or the configuration of the XY graph.  Any ideas where to look?  Is it wrong to simply build an array from the dbl to create the speed array?

 

Thanks 

0 Kudos
Message 3 of 4
(1,637 Views)

Probably the most important thing for you to understand is that an XY *Graph* will not show an accumulation of data over time.  Each time you write data to the graph, you will be *replacing* the previous contents.

 

To show an accumulation of data, you'll need to do the accumulating yourself.  I'm going to recommend you use one of the *other* available data formats for a single plot on an XY Graph.  I'd recommend complex notation if you understand it, otherwise I'd go with a single array of "points", where each "point" is a cluster containing an x (time) value and a y (frequency) value.

 

Another pending problem is that you're trying to read 1 sample at a time from 2 different tasks that will have different sample rates.  The sample rate for frequency measurement is driven by the signal frequency itself, and will very likely vary noticeably, else why would you be measuring it?   Anyway, the problem is that the tasks are filling up their buffers at different rates but you're reading samples from them at the same rate.  One of them is going to fall behind and cause an error.

 

I would read about 1/4 sec worth of AI data first, then read "all available" samples from the counter task to keep pace.  This will update your graph 4 times a second

 

I'll make some minimal mods to your code to illustrate a simple way to accumulate data for the XY graph, but I'd recommend you look into how to use a "lossy queue" to prevent the storage from growing without limit.

 

 

-Kevin P

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 4
(1,622 Views)