Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How to output multiple timed samples on a single digital line

Solved!
Go to solution

Hello,

 

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:

 

    int numSamples=3000;

    TaskHandle taskHandle;
    DAQmxCreateTask("",&taskHandle);

    DAQmxCreateDOChan(taskHandle, "Dev1/line2", "", DAQmx_Val_ChanPerLine);

    DAQmxCfgSampClkTiming(taskHandle,"",1000 /*samplingRate*/, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,numSamples);

    DAQmxStartTask(taskHandle);

    int32 samplesWritten;
    DAQmxWriteDigitalLines (taskHandle, 3000, true /*autoStart*/, 100,DAQmx_Val_GroupByScanNumber,writeArray, &samplesWritten, NULL);

    DAQmxWaitUntilTaskDone(taskHandle, 100);

    DAQmxStopTask(taskHandle);
    DAQmxClearTask(taskHandle);

 

 

All responses will be highly appreciated!

Petro

 

0 Kudos
Message 1 of 7
(4,082 Views)

Peter,

 

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?

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 2 of 7
(4,047 Views)

Hi Jason,

 

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 task

Create digital output channel with DAQmxCreateDOChan

Configure 1 ms timing for the task with DAQmxCfgSampClkTiming, finite samples

Start task

Write samples from array with DAQmxWriteDigitalLines (also tried DAQmxWriteDigitalU8, same result)

Wait until done with DAQmxWaitUntilTaskDone

Clear task

 

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.

 

Thank you,

Peter

0 Kudos
Message 3 of 7
(4,042 Views)

Peter,

 

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.  

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 4 of 7
(4,018 Views)

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.

 

Thanks,

Peter

0 Kudos
Message 5 of 7
(4,011 Views)
Solution
Accepted by topic author Peter_09876

Peter,

 

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! 

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 6 of 7
(4,003 Views)

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:

 

DAQmxCfgSampClkTiming(dlTask,"/Dev1/Ctr0InternalOutput",1000000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,numSamples);

 

 

Thanks,

Petro

0 Kudos
Message 7 of 7
(3,994 Views)