LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed Loop Application

Hello,

I am using PCI 6229 card with LV 8.0

I am writing a VI for following application:

I have to turn a 2 digital output line On/OFF based on a separate digital input line (a switch). The sequence of events would be something like:

1. Turn the 1st digital o/p channel ON

2. When digital input is received from a switch (on a separate digital channel). Turn the 1st digital o/p channel OFF

3. Wait for x secs

4. Turn the 2nd digital o/p channel ON

5 .When digital input is received from the switch (on a separate digital channel). Turn the 2nd digital o/p channel OFF

3. Wait for x secs

5. Repeat this N times.

 

Do I need to use timed loops for something like this? Or is there any alternative?

Appreciate the help

Thanks

0 Kudos
Message 1 of 12
(3,827 Views)

Dear bvik,

 

As we are talking about secs (as for timing) I think a general whileloop with a timing VI would be totally OK.

Moreover the aforementioned structure manifesting a state machine would be a perfect choice.

 

It is quite easy to implement the cases as you already enumerated them 🙂 

 

Should you have any questions please feel free to ask.

 

Regards,

Marton

NI Hungary 

0 Kudos
Message 2 of 12
(3,812 Views)

Hi Marton,

 

Thanks for the reply.

 

I am not very familiar with using a while loop and timimg VI together.

If you can give me some more details or maybe direct me to a particular vi, I would really appreciate it.

 

I am having trouble with using one digital input line to trigger two other digital output lines. and then doing this in a loop.

 

Thanks again

 

 

 

0 Kudos
Message 3 of 12
(3,806 Views)

Dear bvik,

 

As a starter I suggest to have a look at these links:

 

Application Design Patterns: State Machines

http://zone.ni.com/devzone/cda/tut/p/id/3024

 

 

Tutorial: Timing, Shift Registers, and Case Structures

http://zone.ni.com/devzone/cda/tut/p/id/7592

 

Anyway the main idea of state machines in LabVIEW is the same like any other programming language (a case structure in a while loop)

 

 

As for the digital output and input:

I think there is no need to use the  triggering that is provided in the driver. You can watch the DI line and if there is a change in that then you write to the other two DO lines accordingly (so you can program the logic).

In Help/Find Examples you can find the Read Dig Chan.vi and the Write Dig Chan.vi , these show you how to use the digital ports.

 

Just tell me if you need further help!

 

Regards,

Marton

 

 

0 Kudos
Message 4 of 12
(3,781 Views)

Marton,

 

So I don't have to use triggering to fire the two digital o/p lines.

Once I get a signal on the digital input, then change the digital output accordingly, is that right?

I'll check it, hopefully it works,

 

But I still have 2 question

 

1. Not sure how to incorporate a delay in the loop after I get a signal on the digital I/p line before firing the digital o/p.

2. This process needs to repeat for N times. Do I need to use a timed loop or something else?

 

Thanks for all the help.

Regards,

 

0 Kudos
Message 5 of 12
(3,766 Views)

Hi bvik,

 

Thanks for the update and I hope your well - don't worry about the other post. 

 

You can use one of the timing VIs such as the wait(ms).vi. Place this in a sequence strucutre and then user error clusters to enforce dataflow, to force the code to wait at the correct point i.e. between the input and output. 

 

If you know the number of iterations required a for loop is ideal - you can just wire N to the N terminal of the for loop. 

 

Hope this helps, 

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 6 of 12
(3,763 Views)

James,

 

I have some analog inputs that i need to monitor throughout the test.

 

When digital i/p is received, i need to wait for x secs before firing the digital o/p line. But during this wait time, i still need to be monitoring the analog i/p channels.

 

If I put wait.vi, i think the entire for loop will stop and i wont get any reading on analog i/p channels.

 

Not sure how to go around this.

Thanks

 

0 Kudos
Message 7 of 12
(3,755 Views)

Hi bvik,

 

Thanks for the reply.


You need to seperate you Analog and Digital Tasks into seperate loops. 

 

You can then use the same clock source (if you have corrlated DIO) to synchronise the two DAQ tasks and use the start trigger and start DAQmx tast.vi to start the tasks together. 

 

You are correct, the wait will pause the entire loop.

 

Hope this helps, 

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 8 of 12
(3,746 Views)

Hi James, So one for loop for analog task and one for digital tasks correct?

 

"You can then use the same clock source (if you have corrlated DIO) to synchronise the two DAQ tasks and use the start trigger and start DAQmx tast.vi to start the tasks together".

 

can you send me an example or sample for this? how do i synchronize two loops with 'start trigger'?

 

THanks

0 Kudos
Message 9 of 12
(3,737 Views)

Hi Bvik,

 

Thanks for the reply and I hope your well today.

 

Here is some example code Ive been writting for you... it follows the steps you posted first off.

 

One improvement would be to used clock DIO, but you can just add a clock source into the DAQmx API to do this. 


Other examples on DIO can be found in the NI Example Finder, Help>>Find Examples>>Hardware Input/Output>>DAQmx...

 

The VI attachted is in LabVIEW 8 (but I wrote it in LabVIEW 8.6.1). I hope it finds you well and please let me know your thoughts - remember to change the dev controls (lines) and maybe look through the code firstly before using, I haven't fully tested it.

 

 Hope this helps,

James. 

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
Message 10 of 12
(3,714 Views)