LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Digital output

Solved!
Go to solution

Hello

 

I have been rattling my head on this for the last couple of days with no luck.

 

What I am trying to do is the following:

 

send a signal into a NI9421 Module using a momentary switch, when the module receives this signal it should output a signal on the NI 9472. These 2 steps I have completed and are working however it is the next part which I am having trouble with.

 

When the input signal is removed from NI9421 (momentary switch opens) I would like to keep receiving a signal from the NI9472 for a period which can be easily adjusted.

 

I have tried to put in delays/waits (FOR loops behaving as counters),while loops etc but all this does is delays the time between the input turning on before the output turns on. For example, If I put in a delay of 5 secs, the input needs to be closed 5 second before the output turns on, and the output will then remain on for a further 5 sec.

 

again what I am looking for is the input just to receive a pulse on the NI9421and the output to remian on for lets say 5 sec in the NI9472

 

Any help is much appreciated.

 

Thanks

John 

 

0 Kudos
Message 1 of 19
(4,585 Views)

Well, let's lay out what you're trying to do, step by step.  (This is what I think you're trying to do, anyway.)

 

1.  Read input signal from 9421.

2a.  IF input = F, goto step 1

2b.  IF input = T, write T value to one of the lines on 9472.

         2.b.1  Wait x sec

3.  Goto step 1

 

Ok.  Does that sound about right?

 

Let's assume that it does, for the purposes of this post.  Very well.  How do we accomplish step 1 repetitively?

 

We put it in a loop.

 

How do we accomplish step 2?

 

We wire the result from step 1 (T or F) to a case structure.  If the 9421 is returning a F value, we execute the False case of the case structure, which has nothing in it.  If the 9421 has returned a T value, we execute the True case of the case structure.

 

Inside the True case is your code for the write to the 9472.  Write a T value on your output line.  Insert a time delay.  Wire a F value on your output line to turn the line back off. (You can use the "Time Delay" express VI, which has an error wire input and output.  Wire the error output from your DAQmx Write function to the error input on the time delay function.  Wire the error output of the time delay function to your second DAQmx Write function.) 

 

Is that helpful?

0 Kudos
Message 2 of 19
(4,582 Views)

Hi Dianne

 

Thanks for the response. Just so you are aware I am very new to using labview.

 

I have attached the Vi images for the false and true, I hope this might keep us on the same path.

 

The False statement work OK (e.g.) nothing comes out when the switch is not pressed. 

 

The True statement is behaving like the following.

 

When the momentary switch is Pressed, it will take the "delay time e.g. 2 sec" before the output turns on for a period of the delay time (e.g. 2 sec).

 

Have I misinterpreted your suggestions.

 

Thanks 

 

John

0 Kudos
Message 3 of 19
(4,563 Views)

Hi John,

 

Please don't post .docx attachments...they can contain nasty stuff and I am unwilling to open them.  Will you please post your code or a .png image instead?

 

It sounds like you didn't quite do what I told you to do, but you're getting closer.  My guess is that you have your time delay in the wrong place.  Post your code and I'll take a look!

 

d

0 Kudos
Message 4 of 19
(4,553 Views)

Hey DianeS

 

Attached is the Vi i used.

 

Thanks again

 

John

0 Kudos
Message 5 of 19
(4,538 Views)

Hi John,

 

Thanks for posting your code.  It's much easier to help someone when you can see exactly what it is they're doing.  Smiley Happy

 

You didn't do what I told you to do.  Read the final paragraph of my first post again.  To reiterate, here is what should be inside your T case:

 

1. Wire a T value to your DAQmx Write function.

2. Wire the output error wire of the DAQmx Write function to the input error terminal of the Time Delay Express VI.

3. Wire the value of your time delay to the time input of the Time Delay Express VI.

4. Wire the output error wire of the Time Delay Express VI to the input error terminal of a second DAQmx Write function

5. Wire a F value to the second DAQmx Write function.

 

You didn't do any of that.  I see no error wires anywhere.  Your DAQmx Write function is outside your True case, not inside it.  There is only one DAQmx Write function (but that's ok if you don't want your channel to go low again -- although your original post says that you do).

 

Do you understand the concept of dataflow?  A structure (or function, or subVI) cannot finish executing until everything inside it has finished executing.  Therefore your case structure can't finish executing until the time delay has elapsed, which is why you're seeing the time delay before your output channel turns on.  That's why you need to put the DAQmx Write functions inside the case structure.  The error wire between functions, as I've specified above, will ensure that one function will finish executing before the next function starts.

 

Just out of curiosity, why are you using a multichannel version of DAQmx Write and Read when you only have data for a single channel?  Is this eventually going to be a multichannel operation?  If it's only going to be one line, use the single channel versions of DAQmx Read and Write.  It will simplify your code a bit with respect to the selector for your case structure. 

 

I am assuming by your code that you want to perform this operation only once, and that your input signal has been set previous to your running the VI.  I assume this because you have no loop.  If this is a repetitive operation, you need a loop, which will cause you further problems given the use of Express VIs.  But we can deal with that later if necessary.  One thing at a time.

 

Ok.  So now program exactly what I've outlined above, complete with error wires, and let me know how you do.  If you come back and tell me it's all messed up, and I see no error wires dictating dataflow, I will scold you.  Smiley Wink

0 Kudos
Message 6 of 19
(4,525 Views)

Hi DianeS,

 

I was using multichannel because I didn't fully understand the difference so thanks for the advice.

I am very new to this.

Please see attached vi. I have added the errors I think:) .

This vi is almost behaving how I want it to. Except I had to add a boolean true/false control button to set the case true or false.(which is not what I want)

I want to know how to convert the digital input value I receive to a true/false value entering my true/false case structure.

Thanks in advance

0 Kudos
Message 7 of 19
(4,498 Views)

Hi DianeS,

I figured out how to "read" the digital input to the case structure by adding a read DAQmx. 

This is now working how I would like so thanks alot for your help.

See attached; What do you think? Is this what you were suggesting? 

Thanks again

 

0 Kudos
Message 8 of 19
(4,485 Views)
Solution
Accepted by JDonne

Nicely done!  That is indeed what I was suggesting.  I've tidied it up a bit and completed it for you (it's always best to explicitly stop and clear your tasks, so I just added that).

 

I've also attached an example of how to run your code in a loop (i.e. if you want to query the input line and trigger the output again and again, instead of just once).  You may not want to do that, but if you do, this will show you how.

 

Well done!  I'm glad you decided to go with the DAQ functions instead of the Express VIs -- the functions are a much better way to program.

 

No scolding from me today.  Smiley Very Happy 

0 Kudos
Message 9 of 19
(4,478 Views)

Thanks DianeS for everything. One headache down and more to come i guess HeHe.

 

The problem I have is that I am trying to learn via google, youtube and NI dev zone.

 

I have been given a project with no experience in labview and this is what the hardest thing is.

 

Regards

John

0 Kudos
Message 10 of 19
(4,459 Views)