Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with outputting digital data using the NChan Nsamp function

Hello All,

 

I am writing to this form in the hopes of getting some insight in to what I am doing wrong with an application that I am trying to build to output digital data. 

 

I must warn all those who might cringe as they witness how I went about achieving my goals that I have not programmed in labview for over 5 years so I am very rusty. I am fairly certain that there is something incredibly wrong with the way I am attempting to get this system to output digital data.

 

My setup is as follows:

 

NI PCI-6254 Device (dev1)

BNC – 2110 breakout box

Labview Version 2013 32 bit

 

I have another NI card in the system which is designated as DEV 0 in NIMAX as shown below. 

 

1.jpg

I setup my block diagram as follows:

 

2.jpg

 

The way I set this up was to utilize the first three lines in port zero of dev1 as my digital output. I setup the channel for digital output and for each line to have a channel of their own.

 

I set the sample clock to utilize the PFI0 port on the NI card such that I could control the rate at which the pulses are being sent out by the NI card. I have a TTL pulse driving the PFI0 input. I set the sample rate to around 500 and the active edge to rising. I have the sample mode set to finite samples and I have an indicator for the number of samples written by the digital output write function.  

 

The reason I chose such a low rate is because I have my ttl clock to around 8 Hz so it would be easy to watch the transitions when the function wrote the digital data out to the selected lines. 

 

3.jpg

 

The problem that I have with this setup is that I do not get any digital output on the P0, P1, and P2 outputs when this program is running. I have tested these outputs using the test panels in NI MAX and they do in fact work when toggling the logical state in the test panel run mode. I am not sure why this program is indicating that it is writing 8 samples per channel and yet I see nothing on the output when I monitor all of the channels with a scope.

 

Another thing I found perplexing is that when I initially set this up I configured the N samples N channels data type to U8 but when I attempted to run the program it crashed and indicated that I needed to set it to 32 bits. I do not understand why I needed to set it to 32 bit when the source array elements are U8.

 

I am quite certain I am doing something incredibly stupid but I have spun my wheels for more than a week on this so now I am appealing to the experts. I would really like to stick with the method of feeding an array of data in to the Nchannel and N sample function. I am aware of the wiring a Boolean array method and I was hoping to not have to go that route. I appreciate and assistance anyone can provide me.

Thank you in advance.

 

- Randy

 

0 Kudos
Message 1 of 6
(6,208 Views)

Hi,

 

I would suggest taking a look at some of the built-in examples in LabVIEW 2013.  If you go to Help --> Find Examples, then Browse through the folders: Hardware Input and Output --> DAQmx --> Digital Output.  There are several examples that set up continuous, finite, or SW-Timed output.

 

As far as the code you have now, you are missing a "Start Task" VI before the "Clear Task" VI.  Essentially when you call the "DAQmx Write" VI, you are writing the digital output signal to the task.  In order to actually write to hardware you must start the task, using the "Start Task" VI, followed by the "DAQmx Wait Until Done" VI to ensure all the data is written before the task gets stopped/cleared.

 

I would also suggest using a continuous output setup instead of using the outer while loop you currently have.  The while loop will greatly slow down your program since you are re-initializing the task each time and then erasing it.  Take a look at the examples I mentioned above for more explanation on this.

 

 

 

Regards,

0 Kudos
Message 2 of 6
(6,162 Views)

Hello Lindsey,

 

I have actually looked at those examples and I have tried everything you suggested and I experianced errors each time I attempted to use the wait function.  

 

I had the task creation functions outside of the while loop but each time I would clear the task the task parameters were lost and I would get an error. If I didn't clear the task and left that function outside of the while loop, the write node would generate an error upon the second iteration of the loop. I attempted to use a stop function after the write function and I ended up with the same error mode. 

 

I had a start function after the write function but I removed it and wired a boolean true constant to the auto start terminal of the write function.

 

I had the setup task outside the loop and also the clear task outside of the loop but when I set it up both ways the program generated errors. If you like I can produce each one of these configurations and provide screen shots of each error mode. 

 

 Questions:

 

I have the timing function being triggered by a 8 hz clock which is why I didn't think the wait function was necessary. It is my understanding that the timing feature will cause 1 sample to be written per clock pulse. Am I correct in making the previously stated assumption? 

 

I am also curious why my U8 array seems to be read in from the write function as being 32 bit. When I try to use the U8 data type N sample N channels it indicates that the data source is wider than the sink. 

 

 

Thank you for any insight you can provide and I will work on generating the screen shots that will illustrate the errors I have been experiancing. The only reason I am re initializing the task each time is because every other method I have used thus far either generates an error or the task is erased in the process and the configuration is lost outside of the loop. 

 

- Randy 

0 Kudos
Message 3 of 6
(6,157 Views)

Hi again,

 

Could you try running one of the sample programs included with LabVIEW with your hardware, and show us screenshots of the exact errors you are seeing?

 

In regards to your questions, you still need the “DAQmx Wait Until Done” VI.  This VI will ensure that all of the data you send to the “DAQmx Write” VI is actually written before the task is stopped or erased.  Without this VI, you may not write all of your intended data to the digital out lines.

 

For your second question, are you saying you receive this error when you set the “DAQmx Write” VI to “Digital 2D U8 NChan NSamp”?  Also what is the exact error you are receiving?

 

 

Regards,

0 Kudos
Message 4 of 6
(6,055 Views)

Hello Lindsey,

 

Yes I most certainly can, unfortunately I have been temporarily asked to focus on another project so I have been unable to commit a great deal of time to this so far. I will try to generate those screen shots today and also provide you with all the error codes that are generated. 

 

I thank you for your quick response and I hope to have that information posted really soon! 

 

- Randy 

0 Kudos
Message 5 of 6
(6,019 Views)

Hello Lindsey,

 

I was finally able to commit some time to this project today and I did make some progress. I decided to move all of the task creation elements out of the while loop and I also added the wait and stop function after the write function. Once I made the changes I just explained, the DAQ board started outputting pulses on Port0 Line 0. I decided to check the other lines and I was disappointed to see that only one of the lines was outputting any data.

 

I am including a screen shot of the latest version of the block diagram below:

 

block-diagram.JPG

 

Here is the front Panel:

 

front-panel.JPG

 

 

This is a screen shot of the scope that I am using to monitor the output lines:

 

CH1 - Yellow - line 0

CH2 - Green - line 1

CH3 - Blue - Line 2

CH4 - Orange - Clock Pulse for timing function

 

scope_0.jpg

 

As you can see, there is no data on line 1 or line 2. Could you provide me any insight as to why this might be happeneing? 

 

 

 

The issue I was having with the mismatch of data types is when I fed my 2D U8 array in to a N sample N channel write function with the U8 data type selected and the error code I was recieving was 200565. I was able to resolve it by changing the write function to a 32 bit data type but I am uncertain why it reads a 2D U8 array as a 32 bit data source. 

 

32bit-write-issue.JPG

Thank you in advance for any help you might be able to provide. 

 

~ Randy 

 

 

0 Kudos
Message 6 of 6
(6,008 Views)