Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to measure the frequency of a clock using counter in LabVIEW?

Solved!
Go to solution

Hi guys,

 

Anyone know how to measure the frequency of a signal fed into LabVIEW (using the FPGA in PXI-7813R), by using a counter in LabVIEW? 

 

Essentially, I want to use this counter as a sort of Logic Analyzer.

 

Thanks, Anoop

0 Kudos
Message 1 of 13
(7,457 Views)

I would compute it in the FPGA (count clock cycles between rising edges).  I guess you could do this in Windows too.  But that would require sampling the clock and counting samples between rising edges and multiplying by the sample rate.  Again, it would be easier to do in the FPGA.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 13
(7,441 Views)

Thanks for the reply crosrulz.

 

how to you count the clock cycles between rising/falling edges? Do you mean manually counting them over a cycle (which has to be identified first) or by using some sort of tool in LV, which would calculate the frequency?

 

 

0 Kudos
Message 3 of 13
(7,436 Views)

Like I said, this is easier in the FPGA.  Want you need to do is use a Single Cycle Timed Loop.  In the loop, read your clock as a digital input.  If it transitions from FALSE to TRUE reset the cycle count (stored in a shift register).  The next time you have a F->T transition, send the count up to the host.  The frequency will be the count divided by the FPGA clock (should be 40MHz).  As far as I know, there is not a built in function to do this, but it is simple enough to code up.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 13
(7,434 Views)

"If it transitions from FALSE to TRUE reset the cycle count (stored in a shift register).  The next time you have a F->T transition, send the count up to the host"

 

When you say the above, do you mean, do you mean i have to reset the cycle count when there is a transition?

 

On a seperate note, do you know why most digital lines float high even when there aren't any input connected to them?

0 Kudos
Message 5 of 13
(7,429 Views)

@The_Sugarman wrote:

"If it transitions from FALSE to TRUE reset the cycle count (stored in a shift register).  The next time you have a F->T transition, send the count up to the host"

 

When you say the above, do you mean, do you mean i have to reset the cycle count when there is a transition?

 

On a seperate note, do you know why most digital lines float high even when there aren't any input connected to them?


Yes, when you have a certain transition (completed clock), reset the counter (so you start counting the number of FPGA clock cycles until the sampled clock completes a period).

 

Many DIO have weak pull-up resistors built into the card.  So when left to float, they go high.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 13
(7,425 Views)

The resetting have to be manual right? If so, this would lead to inaccuracies wouldn't it?

0 Kudos
Message 7 of 13
(7,422 Views)
Solution
Accepted by RedAG

I'm not sure what you mean by "manual".  It is all handled in a case structure.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 13
(7,412 Views)

Ah ok. But what would I have in the Host to read/display the data obtained from FPGA? A loop and a display?

 

Also, is it possible to incorporate this code into an existing code (a serial combination of vi's as ooposed to a vi within a vi)?

 

0 Kudos
Message 9 of 13
(7,408 Views)

@The_Sugarman wrote:

Ah ok. But what would I have in the Host to read/display the data obtained from FPGA? A loop and a display?

 

Also, is it possible to incorporate this code into an existing code (a serial combination of vi's as ooposed to a vi within a vi)?

 


I would use a DMA to send the data to the host.  The host can then just read the DMA.  You will likely get a lot of readings unless you have an enable/disable transfer setup (another command to send to the FPGA to start/stop sending the counts).  If you get a lot of samples, perform an average.  You then take the count and divide by the 40MHz to get your clock frequency.

 

You can put this FPGA code wherever you want.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 13
(7,404 Views)