03-03-2009 01:20 PM
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
03-03-2009 03:13 PM
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
03-03-2009 03:21 PM
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
03-04-2009 01:49 AM
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
03-04-2009 08:26 AM
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,
03-04-2009 08:31 AM
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,
03-04-2009 09:07 AM
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
03-04-2009 09:48 AM
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,
03-04-2009 10:17 AM
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
03-05-2009 06:58 AM
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.