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.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring and comparing an industrial frequency voltage

Solved!
Go to solution

Hello. 

I'm pretty new at working with NI hardware, so I'm sorry if my question would seem silly for you.

 

There are some laboratory benches in our university built on NI DAQmx PCI-6024E hardware. The software provided with benches doesn't satisfy with its functionality, so I decided to develop some of mine.

One of tasks is measuring an industrial frequency voltage, getting its amplitude and current frequency. I could successfully read an AnalogWaveForm from the analoginput channel and even display it. But the trouble is that the wave on the graph is "jumping" all the time, not letting to estimate it. I think that the trouble is in the approach I use:

            public void wave(Task myTask, string channel, out AnalogSingleChannelReader Reader)
            {
                myTask = new Task();
                myTask.AIChannels.CreateVoltageChannel(channel, "",
                        (AITerminalConfiguration.Rse), -3, 3, AIVoltageUnits.Volts);
                myTask.Control(TaskAction.Verify);
                Reader = new AnalogSingleChannelReader(myTask.Stream);
            } 
        private void timer1_Tick(object sender, EventArgs e)
        {
            Wave1 = Reader[1].ReadWaveform(Convert.ToInt32(slide1.Value));
            waveformPlot2.PlotWaveform(Wave1);
        }
        private AnalogSingleChannelReader[] Reader = new AnalogSingleChannelReader[2];
        private NationalInstruments.DAQmx.Task[] myTask = new NationalInstruments.DAQmx.Task[3];
        AnalogWaveform<double> Wave1;

Changing the number of samples with slide1 improves a situation a bit, but doesn't solve the problem.

But visual part of this task is not the most important. 

What I really have trouble with is getting the amplitude and frequency of the wave. Now I use this method to get the amplitude, but I think it's not the best and the fastest way, so I would be really happy if you proposed something better:

            public static void get_ampl(AnalogWaveform<double> Wave, int n, double kt, out double ampl)
            {
                Array rr = Array.CreateInstance(typeof(double), n);
                Array.Copy(Wave.GetScaledData(), rr, n);
                Array.Sort(rr);
                ampl = Math.Abs(Convert.ToDouble(rr.GetValue(0))) * kt;
            }

kt is just a scale index.

Moreover, I have absolutely no idea how to deal with frequency measurement. There are a lot of examples I found that work with frequency measurement task, but my DAQ hardware doesn't support this function. I thought about some algorithm that could detect indexes of the max and min values in raw data read from the device, but couldn't make it work:

            public static void get_freq(AnalogWaveform<double> Wave, int n, out double freq)
            {
                double a, b;
                Array rr = Array.CreateInstance(typeof(double), n);
                Array sorted = Array.CreateInstance(typeof(double), n);
                Array.Copy(Wave.GetScaledData(), rr, n);
                Array.Copy(rr, sorted, n);
                Array.Sort(sorted);
                a = Array.IndexOf(rr, sorted.GetValue(0));
                b = Array.IndexOf(rr, sorted.GetValue(n-1));
                freq = Math.Abs((a - b) / n);
            }

I will be really glad for any help.

0 Kudos
Message 1 of 7
(2,929 Views)

What version of DAQmx are you using? Also, to clarify you are using Measurement Studio for your application, right?

 

Since you're new to programming with NI hardware, you might want to check out these resources. Here's a document on how to use DAQmx in text-based environments, and a page with example code that you can reference:

 

Using NI-DAQmx in Text Based Programming Environments

Text Based NI-DAQmx Data Acquisition Examples

 

Hope this is helpful!

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 7
(2,849 Views)

Hello, Francine.

 

Thank you for your answer.

Of course, I'm new to the program, but I would never wrote on the forum before learning examples. So all of these links were read by me a lot of time ago.

 I'm using DAQmx version 16.0.1 and Measurement Studio v.15. Yes, you are right - I use it in my application.

At the moment of writing the original post I couldn't clearly understand the principle of Tasks and working with them. But in some days I could get a normal sine wave with help of Sample Clock:

            public void wave2(Task myTask, out AnalogMultiChannelReader Reader)
            {
                myTask = new Task();
                myTask.AIChannels.CreateVoltageChannel("Dev1/ai0:1", "Ur,Uc",
                        (AITerminalConfiguration.Differential), -5, 5, AIVoltageUnits.Volts);
                myTask.AIChannels.CreateVoltageChannel("Dev1/ai2:4", "Pdv,Pr,d",
                        (AITerminalConfiguration.Rse), -2, 3, AIVoltageUnits.Volts);
                myTask.Timing.ConfigureSampleClock("", 1000, SampleClockActiveEdge.Rising,
                    SampleQuantityMode.ContinuousSamples, 100);
                myTask.Control(TaskAction.Verify);
                Reader = new AnalogMultiChannelReader(myTask.Stream);
            }

Also, now I can calculate the effective value using standard NI RootMeanSquared function. 

The only thing I can't deal with is calculating the frequency.

0 Kudos
Message 3 of 7
(2,838 Views)

There's an example of acquiring frequency from an Analog Input in .NET that you can take a look at. The examples are automatically installed when you download NI-DAQmx and you can usually find them in this folder: 

C:\Documents and Settings\All Users\Shared Documents\National Instruments\NI-DAQ\Examples\ 

 

The example is called Continuously Acquire Frequency - Internal Clock - SCXI 1126

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 7
(2,833 Views)

Thank you for the answer.

It's noted in the name of the example, that Frequency is acquired using Internal Clock. There's no such input channel on my hardware, so I need to count frequency just from voltage measurements.

0 Kudos
Message 5 of 7
(2,827 Views)
Solution
Accepted by topic author AlSeed

You can check out this link for functions you can use in .NET:

http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/keyninetanalysis/#Digital Signal Processing

 

In particular, maybe you can use the SingleToneInformation class (4th class listed on the page) or use PeakDetector (2nd class listed) and calculate the frequency based on the peaks.

Francine P.
Applications Engineering
National Instruments
Message 6 of 7
(2,814 Views)

Thank you a lot! I think that's right the thing I need! I will check it out next time I get to the hardware.

 

0 Kudos
Message 7 of 7
(2,812 Views)