Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Determine phase difference using PCI6602 NI Card with NIDAQmx Driver in C language

Hello everyone,

I have 2 frequencies. I want to determine its phase difference and want to check who is leading or lagging among both. For that, I am using PCI6602 NI Card with NIDAQmx driver and writing a code in c language. I have created two tasks and two counter channels for both the counters. I am counting pulses with the help of counters within certain time and then comparing its count value. But it is not giving proper output(eg. if I have frequency A and frequency B as input then output is sometimes 'A is leading' and sometimes 'B is leading') as I am unable to start both counters at the same time. How can I start both counters at the same time? Or Is there any other solution to determine who is leading among two frequencies? 

Thank You.

0 Kudos
Message 1 of 4
(1,192 Views)

I would recommend capturing the signal as analog signal using a single task containing both the channels, this way, you can be sure that both are synchronized using the same sample clock.

 

You can fetch the waveform at a fixed interval and compute the phase of each signal and compute the phase difference.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 4
(1,176 Views)

A few things. 

 

First, the direct answer to your question:  to start counter *input* tasks simultaneously, you need to use the special "Arm Start" trigger.   On the 6602 there are some DIO lines that double as PFI lines.  You can configure both counter tasks to use the PFI terminal as an Arm Start trigger, and then also generate your own triggering pulse with a simple DO task.

 

Second, counting the respective pulses is not going to give you a meaningful measure of phase.  You would need to do something like period measurement (or maybe semiperiod measurement).   Then you could calculate "timestamps" for the edges of interest from the cumulative sum of the periods since the Arm Start trigger.

 

Third, phase might be kind of meaningless.  If the pulse trains are of a different (or varying) frequency, it's unclear what meaning you could derive from a continually changing phase measurement.  There might be *some* meaningful way to characterize the difference, but I doubt it'd be phase.

 

Fourth, even if the pulse trains have the same frequency, phase might be elusive to characterize anyway.  It's liable to be ambiguous.  Leading by 160 degrees looks the same as lagging by 200.  How would you tell them apart?

 

Maybe you can describe your end goal in more detail.  It seems to me that phase measurement isn't going to be the thing you really need.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 3 of 4
(1,145 Views)

@santo_13 wrote:

I would recommend capturing the signal as analog signal using a single task containing both the channels, this way, you can be sure that both are synchronized using the same sample clock.

 

You can fetch the waveform at a fixed interval and compute the phase of each signal and compute the phase difference.


Please ignore my comment, realized late 6602 is counter/timer card and not a typical multifunctional DAQ.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 4 of 4
(1,139 Views)