‎10-27-2009 07:54 AM - edited ‎10-27-2009 07:56 AM
Hello,
I wish to generate a software triggered asynchronous digital output pulse on a NI USB-6221 DAQ via C or Microsoft Visual C++.
I need to be able to trigger at arbitrary times at rates of up to 3 kHz, a continuous digital pulse train will not meet my needs.
Some examples provided by NI (WriteDigChan.c) have provided a partial solution, which is demonstrated below. Unfortunately, this triggering scheme tops out at 500 Hz on my PC.
Are there any methods similar to what I have below that would be faster?
Thank you for your help.
//--Initialize program and hardware
//--Configure DAQmx digital output channel
DAQmxErrChk (DAQmxCreateTask(...));
DAQmxErrChk (DAQmxCreateDOChan(...);
//--Start task, initialize output state
DAQmxErrChk (DAQmxStartTask(...));
DAQmxErrChk (DAQmxWriteDigitalLines(...));
//Start main program loop
//--Send Trigger
DAQmxErrChk (DAQmxWriteDigitalLines(...));
//--Fetch data from hardware (execution time is variable
//--Set trigger output low
DAQmxErrChk (DAQmxWriteDigitalLines(...));
//--Process data (execution time is variable)
Repeat loop
‎10-28-2009 04:29 PM
Hi Robot Builder,
If I am understanding your code correctly the limiting factor will be how fast you can get the loop to iterate, it looks like you have the bare minimum of code inside the loop so you might be up against a hardware limitation from your system. To get the kind of results you are looking for you may have to look at a Real-Time or FPGA system.
I hope that helps, let us know if you have any more questions.
Thanks
Scott M.
‎10-28-2009 05:06 PM
Scott,
Thanks for your reply. Timing in my software application is rather tight, and at maximum the loop can iterate up to ~3kHz (without the DAQmx calls). Further testing has shown there to be a ~20ms latency associated with the DAQmx calls, which I attribute more to Windows than the DAQ. However, I understand that I'm trying to use the DAQ in a manner that is not really intended, which is fine. It's great with constant rate data. My plan B is to simply create continuous pulse train tasks, and change them as needed but it's not an ideal solution. I still wish to be able to send asynchronous trigger pulses at rates up to 3kHz.
Your suggestion reflects our next step once prototyping has been completed. In the meantime, it'd be nice to send a trigger at will.
- Robot
‎10-29-2009 10:03 AM
Hello Robot,
The limitation you are running into is definitely a limitation of windows. Trying to iterate a software timed solution at rates much faster than 1 kHz is not often a possibility because of the system limitations.
Good news though! The 6221 has correlated digital I/O which means that you can share a clock to do hardware timed DIO. Since the 6221 does not have a direct clock for digital signals, you will have to start an analog task and then share the analog clock with you digital task. From the timing, you can then write specific digital patterns to make up the waveform that you are looking to output. Good luck with your application!
‎10-29-2009 11:07 AM
ColeR,
Interesting suggestion, I'm going to try this out.
Is there a VI that could illustrate the concept? (I find it easy enough to translate a VI to C in this case.)
Thanks,
Robot
‎10-30-2009 09:36 PM
Hi Robot,
Provided you included C Examples when you installed DAQmx, you should have an example called Write Dig Chan-Ext Clk that would be a good place to start if you want to perform clocked Digital Output. You can use an external signal or many clocks on the board as the sample clock for your digital waveform.
There is also the example called ContAI-Read Dig Chan that shows how you can use the AI Sample Clock to clock a Digital line (in this case it's an input but the idea is essentially the same). Another popular method is to use one of the Counters to generate the sample clock (you can use the InternalOutput as the source for your sample clock). There is also a Frequency Generator that you can use on the 6221 which is programmed just like a counter.
The Correlated Digital Output option is nice because it gives you the ability to generate an arbitrary digital waveform and output the values based off of a clock signal. The waveform is software-defined so you can output pulses whenever you wish, but you have to know ahead of time the signal you wish to generate.
Another option for outputting pulses at the rate you need is to use one of the counters. You mentioned that you did not want to do this, but one thing to keep in mind is that the counter can be reconfigured on the fly so you wouldn't have to stop and start the task to change frequencies. I'm not sure we have a C Example available for this, but here's what the LabVIEW code looks like (the false case just has a wait function in it to keep the loop from running too fast and consuming unnecessary processor):
Best Regards,
John