LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulate Signal Express VI over generation problem

Solved!
Go to solution
Highlighted

Hi everyone, 

I'm building this Simulate signal VI to generate waveform within a dedicated period of time determined by Elapsed TIme express VI both in the same loop. So that I can control exactly the output signal period for further application. 

Waveform generator.png

For instance, the simulation signal period is 6s and time elapsed for the while loop to run is 3s, therefore I should always obtain 1/2 period signal generated when the while loop terminated. But somehow, the Simulate signal express VI is by chance over generate extra 1 point that ruins the expected output signal. 

2-horz.jpg

Please help me to fix this,

Thank in advance.

0 Kudos
Message 1 of 9
(914 Views)
Highlighted

Don't do it that way!  Get rid of the Elapsed Time Express VI, the Simulate Signal Express VI, learn about Waveforms and use the Waveform Generation VIs, and do a little arithmetic to generate precisely the points you want.  It helps to understand what LabVIEW means by a Triangle Wave, to understand what Frequency and Phase mean with such a wave, and a few other things that I don't think you fully understand.

 

Bob Schor

0 Kudos
Message 2 of 9
(884 Views)
Highlighted

Great reply sir, thank you!

But can you give me a brief example of how it can be done?

I think Waveform Generation VI is not well explained and is not commonly used. Since the timing between loop iteration and the single signal point generation is also critical to my program, this indirectly determined by the Sample per second (Hz) in Simulate Signal Express VI.  

 

0 Kudos
Message 3 of 9
(867 Views)
Highlighted

Well, you didn't describe what you wanted to do very clearly.  Have you looked at the Examples that ship with LabVIEW?  There are a number of examples showing Waveform Generation (some using the Waveform Generation functions, not the Express VIs) and playing them through various output devices.

 

Suppose you want to generate a Triangle Wave and output it at 100 points/second.  I'm assuming you'll specify the waveform so that you'll get the appropriate waveform -- in your example, your rising phase lasts 1.5 seconds, or 150 points, and your falling phase is another 150 points, and if this is supposed to be one period of a triangle wave, then the Wave has a non-zero offset and a phase lag of 90°.  Here is a Snippet (LabVIEW 2018) that generates one cycle of a 0.33 Hz (roughly 3-second period) Triangle Wave with a 90° phase lag at 100 Hz and for 300 points.  I plotted it, setting the Plot to display Relative Time (so it starts from 0) and displaying the scale as seconds (with one decimal point)(right-click the Chart and set its Properties) -- I get a Triangle Wave from -1 to 1 (I leave it as an Exercise for the Reader to modify it so it goes from 0 to 10).

Generate Triangle WaveGenerate Triangle Wave

So how much time does it take to do this (not counting the plotting)?  About 30 microseconds, i.e. 300 times faster than it takes to generate a point "in real time" (= 10 milliseconds).  So you could generate a waveform, play it out "slowly" (one point every 10 milliseconds), and when you are done, generate another 300 points, play it out, generate, play, etc.  Or, if you are really worried about the time to generate the points, do the following:

  • Generate the first set of points.
  • In a loop,
    • Display (300 times slower than the generation time) a point in the waveform.
    • The first time (or the last time, or even every time) through the loop, generate the next set of points.

Now when your loop finishes, you have the next set of samples ready to go, so you repeat with no delay (note that if you generate during the last time through the loop, you just replace the (now empty) array of data with the newly-generated "next" part of the waveform).  Incidentally, what you see here, a "vague" statement of when to generate the data in the algorithm above and a "better" way to do it in the preceding sentence, is an example of "thinking while designing", and getting the main points first and letting the details "suggest themselves to you".

 

Bob Schor

Message 4 of 9
(863 Views)
Highlighted
Solution
Accepted by topic author VD89410A

Thank you so much for your detail explanation,

My idea is that I need the loop to run simultaneously with the point generation process. Because some code needs also to proceed inside it at the time between iterations.

So I use the sampling rate to determine the loop iteration time, then together with the period (1/frequency) to control the spacing between points and the number of the cycle that I want to generate.

Untitled.pngTriangle Waveform.png

 

0 Kudos
Message 5 of 9
(855 Views)
Highlighted

Everything is fine except for your plot.  You are updating once/second, presumably by sending values to a D/A converter.  This is the output you will get:

4-point triangle wave.png

The value is 0 for a second, then 1, then 2, then 1, then 0.  Is this what you want?  I suspect that it is not.  If you are generating a signal digitally, you need to think about the update rate and how you go from one point to another.

 

Bob Schor

0 Kudos
Message 6 of 9
(849 Views)
Highlighted

Yes, that is exactly what I need, except the number of sample per generation is 1.

I'm controlling a thermal bath by sending this kind of signal to modify its temperature that following the triangle or sine wave. The update rate and the way it goes from one point to another should be even lower (longer) more or less.

0 Kudos
Message 7 of 9
(847 Views)
Highlighted

You might have mentioned this earlier, but if so, I didn't notice it (I apologize).  Here's a "thought experiment" to consider:

  • You have a very sluggish device (a water bath, say) that you want to control (its temperature, say).  So you decide to give it a different temperature every second, knowing it will be sluggish, and lag behind your desired temperature.  You give two "up" temperatures, and then two "down", then two "up", then two "down", and so on.  Let's say you change temperature every 5 seconds.
  • Suppose it takes a minute to reach the desired temperature.  In that minute, you've gone up and down three times!  What do you expect will happen?
  • When designing a Control System, you need to think a bit more about your problem before starting to code!

Bob Schor

0 Kudos
Message 8 of 9
(842 Views)
Highlighted

No, you did an excellent point out! 
That I need to use the for loop (controllable iteration) with waveform generator VI, which allows deeper modification. Especially, the sample rate is actually a VI input gate, therefore I can directly intervene to change the iteration time and value (step) different between two consecutive generation points. 

In the case of high thermal inertia (like a thermal bath), I can just make the iteration time extra slow (a couple of minutes perhaps). Otherwise, if it's too fast then the lag behind the desired temperature will occur.

0 Kudos
Message 9 of 9
(841 Views)