I would like to output an arbitrary-shape pulse train on a single digital line (for NI-USB-6229). The goal is to control the acceleration, running phase and deceleration of a stepper motor.
To do this, I am trying to write an array of samples ("writeArray" in the code below) to "Dev1/line2", one sample per millisecond. However, I am not seeing anything happening on this line. What am I doing wrong? Here is the C code:
DAQmxCreateDOChan(taskHandle, "Dev1/line2", "", DAQmx_Val_ChanPerLine);
DAQmxCfgSampClkTiming(taskHandle,"",1000 /*samplingRate*/, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,numSamples);
DAQmxWriteDigitalLines (taskHandle, 3000, true /*autoStart*/, 100,DAQmx_Val_GroupByScanNumber,writeArray, &samplesWritten, NULL);
All responses will be highly appreciated!
Solved! Go to Solution.
Can you run any of the example programs? Can you run any program/test panel that proves the card is working?
Are you error checking? If not I would encourage you to do this as it will really help us narrow down what is going wrong with you program. If you are unsure how to do this you can refer to any of the example programs.
What do you currently see when you run the program? I realize you see nothing on the output side monitoring your digital lines, but does the computer take a long time to "complete" the program, or a short time? Does this seem normal can you monitor different parts of you program to narrow down where the error is happening?
I can run pretty much everything else - analog inputs, analog outputs, single line scalar value digital output (using DAQmxWriteDigitalScalarU32), etc. All test panels are also working as they should.
I have never tried outputting an array of samples with DAQmx, so I am not even sure how this process is supposed to work, and the documentation has not been of much help so far. What I would like to do is the following:every millisecond, I need to update the signal on "Dev1/port0/line2" with either logical high or low, from an array of values that I create beforehand.
The program as I have it now does not hang - it simply does nothing, and I could not narrow down where the error is so far.
Here is the outline of what I am doing:
Create digital output channel with DAQmxCreateDOChan
Configure 1 ms timing for the task with DAQmxCfgSampClkTiming, finite samples
Write samples from array with DAQmxWriteDigitalLines (also tried DAQmxWriteDigitalU8, same result)
Wait until done with DAQmxWaitUntilTaskDone
Does this seem right to you?
I could not find any examples where a finite array is output onto a digital line, I would appreciate if you could point me to one.
This looks like a good general outline of what you need to be doing.
What language are you using so I can most effectively get you the correct examples? How many samples are we writing here? What happens if we try to right significantly less samples? What about at a slower rate?
What error checking have we tried? Usually whenever these programs don't do anything it is because of an error or some type of problem that occured.
I think I've gotten to the bottom of it... It looks like the M-series devices (and my USB-6229 in particular) are not capable of "Buffered finite digital output", if I understand the documentation correctly. I think the documentation says that the digital lines on these devices lack access to the sample clock. Buffered finite ANALOG output works on my device.
I got the output that I needed for the stepper motor by using buffered analog output, and it works fine. But it seems like a waste to use an analog line to produce an essentially digital signal, with only two voltage levels.
Am I correct about finite digital output on M-series?
I haven't added error checking into the program, I plan to do it in the next couple of days. The program is written in MS Visual C++, and it uses C-style NI-DAQmx API.
It is not that these devices lack access but rather (from the 622X manual): "The digital subsystem does not have its own dedicated internal timing engine. Therefore, a sample clock must be provided from another subsystem on the device or an external source." Choices would include:Any PFI, RTSI, AI Sample or Convert Clock, AO Sample Clock, Ctr n Internal Output, and many other signals.
If you current solution is working fine you should do that!
You are right, it worked when I chose the "/Dev1/Ctr0InternalOutput" as source. Here's how to do it, in case other people run into the same question: