LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Set of time parameter in the sin generation

Greetings everyone! I'm currently facing an issue regarding the precise timing of sinusoidal signal generation. In my program, I aim to generate a sinusoidal signal with an amplitude of 0.5 and an offset of 1. However, I'm encountering a delay between the output generation of the sinusoid and the input signal I'm reading, which is set at 500 Hz. In addition to my previous query, I would like to mention that my ultimate goal is to analyze the frequency response of a motor. To achieve this, I plan to utilize sinusoidal generation at various frequencies.

 

I have included a graph for reference, where the green line represents the signal I generate, and the red line represents the signal I am reading. It is evident that there is a noticeable delay between the two signals.

 

I'm having trouble understanding the relationship between the timing of the sinusoidal generation and the input signal reading. Could someone provide some guidance on this matter? Your assistance would be greatly appreciated.

Download All
0 Kudos
Message 1 of 12
(926 Views)

Sorry, I cannot look at your code (unless you save for previous and reattach), but your two signals have different frequencies, so how do you define "delay"?

0 Kudos
Message 2 of 12
(919 Views)

this is the file with labview code

0 Kudos
Message 3 of 12
(912 Views)

Well, all you have is a free-running toplevel loop using no obvious timing whatsoever (where you output a single scalar and read an array of two data points (all in no particular order!) with each iteration). Where is the queue used?

 

You need to use hardware timing.

 

(You really should get rid of the dynamic data and all the to/from dynamic data, etc. Way too opaque)

0 Kudos
Message 4 of 12
(892 Views)

I suggest that you write a "small" program first, one that acquires N-channels of sampled data at 500 Hz, but sampling 500 (or 1000) samples at a time.

 

If you want accurate and precise timing, you cannot use the PC's clock to take multiple samples -- it just is not precise enough to do this.  Fortunately, DAQmx hardware has more reliable clocks that only time the DAQ hardware, so if you take 500 points at 500 Hz, it will reliably take 1 second per sampling.

 

One second should give you enough time to send the data to a Graph.  So write a simple program to do this and plot the results.  Note you will get a 2D Array from the NChan NSamp DAQmx Read, which can (and should) be directly wired into your Load Cell and Input Motor graphs (please don't use the Dynamic Data Wire.  You should also be able to generate the appropriate 1D Array of a Sine Wave within the 1s you are waiting for the data.  Much better to process your data in "chunks" (using "hardware" timing) than one-at-a-time, using Windows timing and much messier "point-by-point" processing.

 

Bob Schor

0 Kudos
Message 5 of 12
(885 Views)

Thank you for your answer, but if I put the hardware timing in the DAQmx the labview give me an error: 

"Possible reason(s):

Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.

Property: SampQuant.SampMode
Requested Value: Hardware Timed Single Point
Possible Values: Finite Samples, Continuous Samples

Task Name: _unnamedTask<1CA9E>"

0 Kudos
Message 6 of 12
(872 Views)

ccarra25@uic.edu wrote:

Thank you for your answer, but if I put the hardware timing in the DAQmx the labview give me an error: 

"Possible reason(s):

Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.

Property: SampQuant.SampMode
Requested Value: Hardware Timed Single Point
Possible Values: Finite Samples, Continuous Samples

Task Name: _unnamedTask<1CA9E>"


We cannot tell what you did from this description.

0 Kudos
Message 7 of 12
(838 Views)

ccarra25uicedu_0-1687979477737.png

I did a simple program but I still have problem with the input signal. Can you suggest any improvement?

It seems that I generate a sinusoidal signal but the analog output didn't get this, so i acquire noise data.

0 Kudos
Message 8 of 12
(832 Views)

Stop using that code you keep showing -- it is fatally "broken" (because you are asking it to do something that makes little sense, and the way to find out about that is to "see for yourself", which is precisely what I'm trying to get you to do without my "doing it for you", which is not my style of teaching).

 

  1. Make two copies of your "Newcontrol" routine.  Call one "Analog Input", call the other "Analog Output".  
  2. Open "Analog Input".  Remove everything associated with the AO code.  Remove the code involved with timing (near the top).  Remove everything having to do with saving data.
  3. Now scale everything down so that the Error Line and the Task/Channel line run horizontally without bends.  Get rid of most of the blank space.  You should be able to get the VI to take about half the height of a laptop screen and about 2/3 the width, so you can "see everything".  Add back the missing Error Wires connecting the DAQmx functions on the left.
  4. Just to remind yourself, wire a constant to the DAQmx Timing VI.  Note that it will default to 1000, meaning that since you did not specify it, DAQmx will try to read 1000 Samples if sampling continuously.  This is a Good Thing!
  5. Now fix the DAQmx Read.  Set it to Analog, Multiple Channels, Multiple Samples, 2D Dbl.  This will "break" the 1D Dbl wire going to the Chart (just keep one Chart).  Delete the broken wire, and rewire the Chart with the 2D Wire.
  6. Here is a subtle point.  DAQmx is sampling 2 Channels at 500 Hz for 1000 points.  Think about how you would save this in a 2D Array.  The first row is the first sample of 2 channels, and the 1000 row is the 1000 sample.  But a 2D Chart wants to see 2 channels of 1000 samples, which it thinks of as 2 rows, 1000 columns.  Do you know how to transpose the data for the chart?  [Hint -- read the previous sentence out loud].

Run this VI.  If you have a waveform generator, use it as an input to one of the A/D channels.  If not, simply touch one of the A/D channels to inject 50 or 60 Hz "noise" into the system.

 

So what about generating an analog signal to "drive" the system?  It depends -- do you want the "driving signal" to depend on the analog response you are measuring (above)?  And if so, how quickly do you want it to respond?  If you are trying to build a closed-loop control system, this is a much trickier problem that requires specialized (and fast) hardware, such as an FPGA that can respond almost instantaneously, which leaves DAQmx out.  Otherwise, take a separate While Loop and build your Analog Output code following the same principles as outlined above.  Note that, again, you can pre-compute 1000 points of your Waveform, start it going, and while it is outputting the first set of points, you are generating (and doing a DAQ Write for) the next bunch of points, making the output continuous and uninterrupted.

 

Do these one at a time.  Keep your VIs compact and neat.  Don't add Bells and Whistles at the beginning of your code development -- wait until "something works".

 

Bob Schor

Message 9 of 12
(804 Views)

If you have your generation and measurement tasks running:

If you want to find a fequency response by applying sine exitations , you migth need to add a delay after changing the exitation to measure the steady state 😉

Or you apply a whatever (broad bandwidth ?) signal and go the frequency domain / correlation  way ...

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 10 of 12
(784 Views)