LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Square wave control action

I have my program attached and what it does is that when I turn the boolean Purge Control button ON, my graph will show a square wave and when I turn the button OFF, my graph will show just a straight line. However what I want is that when I turn off my purge control for instance, I want to be able to see on my graph that my square wave is transitioning into a straight line and vice versa. When you run the program you can either just see a square wave generation or a straight line can't see both. How could I go about doing this? Any help is greatly appreciated.

0 Kudos
Message 1 of 9
(3,596 Views)

What part of Data Flow don't you understand?  You have a Loop, inside of which is a Case Statement that produces a Signal that gets graphed, meaning the entire signal is plotted.  Do you notice that every second, an entire 1-second's worth of data is plotted, overwriting what was there before?

 

And what are inside the two Case Statements?  One says "Make a flat line 1 second long at 1KHz", while the other says "Make a 10Hz square wave 1 second long at 1KHz".  If you plot the first, you get a flat line.  If you plot the second, you get a Square Wave.  By the rules of Data Flow, you always generate 1000 points of one of those two waveforms every second (depending on the position of the pushbutton when you enter the loop -- it doesn't matter what you do when you are inside the loop), so you can only see one of two things in the plot.

 

If you had used a chart, which has some history, you'd see Square, Flat, Flat, Square, etc. as you pushed the button, one second at a time.

 

if you want more control, learn DAQmx and stop using simple Express VIs that have limited flexibility. There's an excellent White Paper to get you started -- search the Web for "Learn 10 Functions in NI-DAQmx" and read the article that it finds.  Post your code, we'll try to help.

 

Bob Schor

0 Kudos
Message 2 of 9
(3,592 Views)

I have tried running this code but it doesn't work:
 
int T=0;
int t_on=0; //time the square wave is on
T= 1/f; //period= 1/f
t_on=DC*t;// time on= duty cycle*t_total
 
mod(t,T); //modulus operation
 
if (T<t_on){
x=A;} //x is output and A is amplitude
 
else{
x=0;}
 
It just gives me a straight line on what ever amplitude value I input. Any help is appreciated
0 Kudos
Message 3 of 9
(3,527 Views)

Your VI is running so fast that any new values speeds through the chart history almost instantly.

 

Why are you using a formula node and text based code?

0 Kudos
Message 4 of 9
(3,519 Views)

I have to usea formula node

0 Kudos
Message 5 of 9
(3,514 Views)

Why would you have to use a formula node?  Is it some sort of requirement for a class assignment?  (And if so, why are they using LabVIEW to create text code.?)

 

Use real LabVIEW functions.

0 Kudos
Message 6 of 9
(3,511 Views)

No I'm trying to use this program for a system that I want to run at my co-op workplace, I tried it using the square wave signal generator however for some reason my supervisor told me that I should do it using a formula node as it will give me more freedom to do what I want with it....

0 Kudos
Message 7 of 9
(3,507 Views)

If you're the co-op and he is the supervisor, you are probably going to have to listen to what he tells you even though it is unfortunate because he obviously has no clue as to what he is talking about.  He might as well have your start writing code in BASIC.

 

Attached is a version of your VI cleaned up using LV code.  And a wait put in so it slows it down so you can see changes.  There was one line in the formula node of mod(T,t);  But I have no idea how that is supposed to be used since it isn't assigned to any variable.  If it was used, then you would use the Quotient&Remainder function in LabVIEW to get the same results.

0 Kudos
Message 8 of 9
(3,500 Views)
Two points:

1. Always deliver the best solution possible and ignore hand-waving about "more flexibility" unless they can provide justifications/explanations.

2. Never ask permission to do what you know is right. You can always get another job. You only have one reputation and it has to last a lifetime.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 9
(3,482 Views)