LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to fix the analog output value for a specific time?


@uranus999 wrote:

Dear Alex,

 

I have tried out your program, replacing the Random Number with DAQ. But it just doesn't seem correct, as the analog output cannot be connected to the DBL. I am attaching the program which I have wrote at the moment (after the replacement). My other question is, I still won't be able to control the output voltage value of 5V, right.

I am really sorry about all the questions.Smiley Sad

 

 


Hey uranus999,

 

I'm sorry, my explanation wasn't too clear. What I've given you is a format for how your solution can be attempted; if you play around with the VI you'll see that on a button press, it'll start indicating a constantly changing random number for five seconds, then stop. This displays the functionality which you requested; being able to do something for five seconds on a button press. My idea was instead of the random number and indicator, you could instead place your DAQ assistant which outputs a particular value.

 

So, say you only wanted to output a 5V for five seconds and a 0V until the button is pressed again, you could place a DAQ assistant in the 5s long while loop programmed to output this voltage, and in the false case of the button press you could place a DAQ assistant with a 0V output. This isn't the most elegant solution though, but it will work. 

 

Here's another solution you can try implementing, however it's worth trying to understand the flaws that exist with it and how to find ways of improving it:

 

Relay2.png

 

In this example, an infinite loop is used to control the operation of the program. Using an Elapsed Time express VI, configured to a 5s count, the user presses a button to initiliase the counter by resetting it. By using the Time Elapsed? boolean out, by implementing a NOT on this function, you can derive whether to drive a high or low on the boolean indicator. I used a false constant on the Auto Reset function of the timer in order to prevent it from rolling over and restarting the count, which disallows the control interaction. All you could do to drive a digital line of a DAQ Assistant by using a build array function to put it in the appropriate digital control format. 

 

Problems with this implementation:

  • You should avoid using the Elapsed Time? function because it rolls over, i.e. the counter restarts after it has been running for a long time. As the output of this function relies heavily on this function, it would be problematic to leave this program dormant for some time because eventually the counter would roll over again and produce an undesirable output. However, through clever manipulation of timestamps you could create your own function to determine whether time had elapsed that wouldn't roll over.
  • The infinite loop to control this program will hog a lot of CPU; it will use as much processing as possible to run as fast as it can. It'd be good to implement some timing like I recommended in the previous post. For GUI interaction, it's good to use Event Driven code; try checking out the Event Based Producer/Consumer Design Pattern which I think could be built upon to produce the kind of functionality you want in an efficient way. If you don't have a base/student edition of LabVIEW then you'll be able to make use of Event Structures, which are great for GUI.
  • This method of implementation will always output a signal to the Relay straight away; perhaps you could find away to make sure it doesn't initialise in this state. Here's a hint, try using Shift Registers and the Set Start Time Function to remove this unwanted behaviour.

In these two posts I've made, I've used quite different methods to produce what is relatively the same function. There are many ways you can attempt this, some more efficient than others  (The methods I've submitted to you aren't too efficient, but they serve as a good introductory coding since you're new to LabVIEW). It might be worth looking at some of the lower level VIs used for DAQ, to delegate this timing task down to the hardware level. There are a lot of possibilities regarding implementation of this code, so just have fun with them!

 

Anyway, here is the code which will output a 5V signal to a digital line on a button press. You'll need to reconfigure the DAQ assistant for your hardware.

 

Relay3.png 

 

I'd like to see how you get on!


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

Download All
0 Kudos
Message 11 of 22
(1,702 Views)

Dear Alex,

 

Thank you for your reply. 

At the current moment, Labview still looks difficult to me, but I am slowly understanding it. Anyway, I have a few questions, actually and I hope that you don't mind answering them.

i) So, in the current program, it can only give an output of 5V signal, right. So, if I want to change the output voltage, for example, to 6V, I cannot use the digital output line, is it? 

ii) My other question is, why is analog output not chosen? Is it because it cannot generate a constant output voltage compared to the digital output?

iii) And if I want the DAQ to generate another output voltage but at different time than the first output voltage, does that mean I have to create another Elasped Time function for it?

 

I am sorry for all the questions again but I really do appreciate your advice on this matter.

 

Thank you so much.

 

Regards,

uranus999

 

 

0 Kudos
Message 12 of 22
(1,687 Views)

@uranus999 wrote:

Dear Alex,

 

Thank you for your reply. 

At the current moment, Labview still looks difficult to me, but I am slowly understanding it. Anyway, I have a few questions, actually and I hope that you don't mind answering them.

i) So, in the current program, it can only give an output of 5V signal, right. So, if I want to change the output voltage, for example, to 6V, I cannot use the digital output line, is it? 

ii) My other question is, why is analog output not chosen? Is it because it cannot generate a constant output voltage compared to the digital output?

iii) And if I want the DAQ to generate another output voltage but at different time than the first output voltage, does that mean I have to create another Elasped Time function for it?

 

I am sorry for all the questions again but I really do appreciate your advice on this matter.

 

Thank you so much.

 

Regards,

uranus999

 

 


Hey again uranus999,

 

Really, don't worry about it! Ask as many questions as you like.

 

  • If you wanted to change the output voltage to something like 6V, you should implement a case structure based on the timer instead that interfaces with the analogue output. If the elapsed time case is true, output a analogue signal of one type and in the false case do another; this way you'll still be able to maintain the overall structure of the code I've provided you. As you mentioned you wanted to output a 5V signal, I just assumed you were using a digital line, so my apologies.
  • You can use an Analogue Output configured DAQ Assistant with a 'Simulate Signal' Express VI to output the constant 6V signal; configure the Simulate Signal Express VI as a DC signal with a 6V offset (Or use a control to change the offset input of the Simulate Signal). You'll find this express VI very useful for producing a variety analogue signals through analogue output ports.
  • It really depends how you want to implement this time delay; if it is related in any way to the Elapsed Time VI you could base another case structure based on it's current operation; if it's completely separate then you could use a whole new concurrent while loop which uses the same structure as the examples I've given you but controlled by a different button. 

I know what it's like starting with LabVIEW, especially when you're used to text based programming; things can really seem difficult to begin with because you do have to think about your programming in a different way than usual, at least that's how I found it. But once you get used to it you'll find yourself using the same design patterns again and again, so as long as you're constantly practicing and trying out new things you'll find things get easier and even more interesting as you go along. Your ability in LabVIEW will come with experience, so just try to play around as much as you can! If you go to LabVIEW > Help > Find Examples... you'll view a ton of example code that you can download and play around with. It's a really great starting point for learning how LabVIEW programming works and just why LabVIEW is applicable across so many different industries, and it's even great to refer to when you're an experienced programmer (There are some quite advanced coding examples there), I find myself using it every day!

 

So remember, the forums are here for a reason; ask as many questions as you want, we're all learning!


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 13 of 22
(1,684 Views)

Dear Alex, 

 

Thank you for your reply again. I really really do appreciate it.

So, my understanding is correct. In order to generate other voltage apart from 5V, I have to use the analog output function, right.

I will give it a try again and hope it will works. I will write to you again on how it goes.

 

The thing is, I have also tried looking at some forum discussions as well, and some of the people seems to face similar problem as mine. However, when I want to try the examples out, it seems like it is only compatible with higher versions of the Labview program. 

 

I hope to be able to use Labview well soon. I know its a very useful program, only problem is I don't understand it yet.

 

Regards,

uranus999

 

0 Kudos
Message 14 of 22
(1,673 Views)

Dear Alex, 

 

Thank you for your reply again. I really really do appreciate it.

So, my understanding is correct. In order to generate other voltage apart from 5V, I have to use the analog output function, right.

I will give it a try again and hope it will works. I will write to you again on how it goes.

 

The thing is, I have also tried looking at some forum discussions as well, and some of the people seems to face similar problem as mine. However, when I want to try the examples out, it seems like it is only compatible with higher versions of the Labview program. 

 

I hope to be able to use Labview well soon. I know its a very useful program, only problem is I don't understand it yet.

 

Regards,

uranus999

 

0 Kudos
Message 15 of 22
(1,673 Views)

Sorry for the delay.  The two VIs posted earlier were not the ones I meant to post.  Sorry again, not sure what happened.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Download All
Message 16 of 22
(1,663 Views)

Dear Moreese,

 

Thank you for your kind reply.

As I mentioned in my previous reply, I am still  wondering where will the voltage generated goes? I plan to use my DAQ to generate the output voltage but I still don't really understand how it is possible. Do you mean that if I add a DAQ as a control, the voltage of maybe 6V can be generated?

I am really sorry for the questions, which might seems easy for most of you but confusing to me.

 

Regards,

uranus999

0 Kudos
Message 17 of 22
(1,642 Views)

Dear Alex,

 

I have tried changing the DAQ from digital output to analog output with the addition of a controller of the offset. I am wondering how I can control the output voltage to be generated for only 10 seconds. I have attached the current program which I have modify to this mail.

With the current program (which I have changed from your previous reference), the time elaspe function do not seem to be playing any role anymore. I am not sure whether my understanding is correct.

 

Sorry for all the questions again. I do appreciate this forum a lot as it really helps me a lot to have the discussion session.

 

Thank you.

 

Regards,

uranus999

0 Kudos
Message 18 of 22
(1,634 Views)

Dear Alex, 

 

I am sorry. I have forgotten to attach the program file in the previous mail.

Thank you again.

 

 

Regards,

uranus999

0 Kudos
Message 19 of 22
(1,633 Views)

Yes, you should be able to generate using the DAQ device.  I only use the Simulated Signal express VI for lack of such a device.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 20 of 22
(1,616 Views)