02-21-2022 10:18 PM
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.
02-21-2022 11:29 PM
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.
02-22-2022 04:41 AM
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
02-22-2022 08:04 AM
@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.