LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine for generating and viewing different waveforms to a chart

Solved!
Go to solution

Untitled.pngHi,

I have been trying to create a simple program which would allow me to switch between different interfaces ( each of which would generate a different wave: sin, PWL, ramp etc.)

I also have a button to clear the wave if needed.

However, on switching between wave cases, the previous wave created is retained. How would I clear this?

I don't want to clear on multiple additions of the same wave, but only when adding a new wave type would I want to clear.

 

Thanks

 

0 Kudos
Message 1 of 8
(2,765 Views)

I forgot to attach the VI, I am attaching it here.

All the waves are for the time being set as a sin wave until I figure this problem out.

 

0 Kudos
Message 2 of 8
(2,745 Views)

Use a Feedback Node to compare the previous wave type to the current.  If they are different, you clear the history.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 8
(2,734 Views)

Here's what I hope is an instructive Exercise for you -- attach a numeric indicator to the Index of your While Loop and run your program.  Do you notice that almost all the time, LabVIEW is "very busy doing nothing"?  The only time the counter slows down is when you do "Add Waveform" and it needs to do some calculation.  That's a sure sign you are "doing something wrong".

 

Here's a suggestion about how to start thinking about fixing it.  Open LabVIEW, click File, "New ..." (the three dots are important!), find From Template, Frameworks, Design Patterns, and choose Producer/Consumer Design Pattern (Events).  Let it build, then study this design.  I think this is what you want -- when you push a button, you want to "do something", and otherwise, you want to simply "wait" (or do nothing).  You might even be able to do (almost) everything in the Event Loop, alone.

 

Do you know about Event Loops?  If not, they are sure to be discussed in one of the early LabVIEW Tutorials (or you can Google "LabVIEW Event Loops" ...).

 

Bob Schor

Message 4 of 8
(2,716 Views)

 wrote:

Hi,

I have been trying to create a simple program which would allow me to switch between different interfaces ( each of which would generate a different wave: sin, PWL, ramp etc.)

I also have a button to clear the wave if needed.

However, on switching between wave cases, the previous wave created is retained. How would I clear this?

I don't want to clear on multiple additions of the same wave, but only when adding a new wave type would I want to clear.

 

Thanks

 


Hi mrtea,

The way you have coded clearly states you are beginner in LabVIEW, i would like to suggest few modifications to you code and not going to comment anything on architecture.

 

1. When ever you use a while loop place the timer commonly in loop instead of adding timer in every case. when you place it inside the case structure the loop runs independently at a higher rate and whenever the particular case structure is called the loop slows down a bit. This is what been said by @Bob_Schor as below


Here's what I hope is an instructive Exercise for you -- attach a numeric indicator to the Index of your While Loop and run your program.  Do you notice that almost all the time, LabVIEW is "very busy doing nothing"?  The only time the counter slows down is when you do "Add Waveform" and it needs to do some calculation.  That's a sure sign you are "doing something wrong".


Making this change will also make clear chart case to work properly.

 

However since your title states state machine i would suggest you to learn the architecture better and also use event structures to perform the kind of actions easily. Also Place a control in While loop's stop terminal instead of a constant "F" it means you cannot stop your code while running the only option is to "ABORT" it .Hope you know Stop and abort are not same.

 

Hope this helps

 

Kudos are welcome Smiley Happy

 Image result for Ni CLD logo

 

Certified LabVIEW Developer 
Best LabVIEW Programmer @NIDAYS 2015

 

Certified LabVIEW Developer
Best LabVIEW Programmer @NIDAYS 2015
0 Kudos
Message 5 of 8
(2,694 Views)

Finally had a chance to come back to this. 

Here is an update. 

The while loops only increment now when 'Add Waveform' is pressed. 

Is the issue of the loop spending a lot of time doing nothing still there as a result?

XY Graph for looking at the immediate grpah you have produced. 

The other two are for seeing all the wave-forms added together.

(is there a way to add it to the end rather than the start as it is doing currently?)

 

Eventually, I will need to include:

- a feature to reject some waveforms after analysing them in the XY Graph and not add it to the larger waveforms seen in Waveform Graph 3 and Waveform Graph. 

- a feature to clear all waveforms

 

Hopefully the above makes sense.

Larger question is can you guys see any issues that I've not spotted yet?

Thanks.

 

P.S ignore the commented out code and I haven't had a chance yet to put the X axis on to the other two graphs. 

0 Kudos
Message 6 of 8
(2,647 Views)
Solution
Accepted by mrtea

1. Get in the habit of putting your buttons' terminals in their respective event case.  This will make it easier to find said case (double click on the button and it jumps to the terminal, which is conveniently hiding in its event case) as well as handle the latching mechanism.

2. Since you are only adding to the XY Graph in the Add Waveform case, put all of that code into that event case.

3. Same as 2 except for the array going into the shift register.  Only add to it in the event case.  Have all the other cases wire straight through.  There is a nice feature called "Linked Tunnels" to make this easier for you.  This will also fix the unneeded Feedback Node you have in there.

 

2 and 3 will also make things A LOT easier for you to add in your two new features.

Attached is a partially cleaned up VI.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 8
(2,642 Views)

I see, thank you very much. 

0 Kudos
Message 8 of 8
(2,628 Views)