Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

external triggering of USB-6341 X series

I have a USB-6341 and I want to trigger its PFI0 in order to run a buffered pulse train in a single digital output line (P0.0).    I am able to load the DLL library and all the following code  works with no error or warning. But nothing comes out of output line!

 

data   = uint32([ones(1,10000000)  zeros(1,10000000)  ] );

rate = 0.5;

taskh1 = uint32(1);

DAQmx_Val_ChanForAllLines=int32(1);
DAQmx_Val_Rising = int32(10280);
DAQmx_Val_FiniteSamps = int32(10178);
DAQmx_Val_GroupByChannel = uint32(0);

sampsPerChanToAcquire = uint64(length(data));

sperchan = int32(sampsPerChanToAcquire);


[errCode,taskName,DOtaskhandle] = calllib('nicaiu','DAQmxCreateTask','',taskh1);

[errCode,lineNames,nameoflines] = calllib('nicaiu','DAQmxCreateDOChan',uint32(DOtaskhandle),['Dev1/port0/line0'],'',DAQmx_Val_ChanForAllLines);
[errCode,clockType] =  calllib('nicaiu','DAQmxCfgSampClkTiming',uint32(DOtaskhandle),'OnboardClock',rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps, sampsPerChanToAcquire);


numSampsPerChannelWritten = libpointer('int32Ptr',0);

reserved = libpointer('uint32Ptr',[]);
data2 = libpointer('uint32Ptr',data);

 

[errCode,writeArray,numSampsPerChan,zz] = calllib('nicaiu','DAQmxWriteDigitalU32',  uint32(DOtaskhandle),sperchan,0,double(0),...

DAQmx_Val_GroupByChannel,data2,  numSampsPerChannelWritten,reserved);

[errCode zz] = calllib('nicaiu','DAQmxCfgDigEdgeStartTrig',uint32(DOtaskhandle), ['/Dev1/PFI0'], DAQmx_Val_Rising);

 

I am using 32 bit Matlab on a 32 bit Windows 7 and the digital speed of my board is up to 1 MHz. The above code was originally for 32 digital output lines in a decimal way, but I changed it a little bit to get output only from one  line. I changed DAQmxWriteDigitalU32 to DAQmxWriteBinaryU32 but I encountered some errors.

 

Any help would be veryvaluable for me.

 

0 Kudos
Message 1 of 7
(3,914 Views)

Hi Lissa,

 

Are you using The MathWorks®, Inc.’s Data Acquisition ToolBox or the NI-DAQmx Tools?  Did you start with a specific example?  

 

Regards,

Mike Altmann
Product R&D
NI
0 Kudos
Message 2 of 7
(3,894 Views)

Thanks for the response.

I am using Matlab 2012a which also has Data Aqcisition Toolbox. I played with its toolbox and I can turn on and of my laser with it, but I need the hardware precise timing for generation buffered pulse trains. NI-DAQmx Tools does not work for Matlab releases after 2008. I am sure that my board receives the trigger, but it does not send anything out.

 

The mentioned example in the previous post does not work. But when I use Matlab DAQ toolbox it works. So I am sure something is wrong in the way that I communicate with NIDAQmx functions.

 

Do you have any suggestion?

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

This is a bit of a shot in the dark, but what happens if you move the call to DAQmxCfgDigEdgeStartTrig such that you call it before calling DAQmxWriteDigitalU32?

 

Other troubleshooting steps:

If you omit the digital triggering, does this work as expected?

You state that you're sure you board receive the trigger, but doesn't send anything out.  How are you verifying that the device receives the trigger?  An easy way to verify would be to run Measurement and Automation Explorer, open a test panel for your device, select the Counter I/O tab, and set your 'Edge Source' to PFI 0.  This would verify that the device is in fact recognizing digital pulses on PFI 0.  If this works, then set the 'Edge Source' to /Dev1/do/StartTrigger and run your application.  If you count an edge, that would imply that your task did get triggered, if not, then there is probably an issue with it's configuration.

 

Hope that helps,

Dan

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

Hi Lissa,

 

The NI-DAQmx Tools for Data Acquisition with The Mathworks, Inc. MATLAB® Software supports up to version 2008b of the MATLAB® Software.  In order to use our Multifunction DAQ products with the MATLAB® Software, you could either revert back to 2008b or earlier, or instead utilize the Data Acquisition Toolbox provided by The Mathworks, Inc.

 

Another option would be to import your .m files into a MathScript node in LabVIEW, and utilize the NI-DAQmx functions all within the LabVIEW development environment.  For more information about the MathScript Module for LabVIEW, you can review the information available at this link:

 

Inside the LabVIEW MathScript RT Module

 

MATLAB® is a registered trademark of The MathWorks, Inc.

 

There is a chance that your program will work but any suggestions we can give you will be shoots in the dark.

Regards,

Mike Altmann
Product R&D
NI
0 Kudos
Message 5 of 7
(3,863 Views)

Hi Lissa,

 

External Triggering is supported with the Data Acquisition Toolbox in 12a. You can use the function addTriggerConnection to add an external trigger for your application.

 

You can post to MATLAB Answers if you have any specific question on your Data Acquistion Toolbox code.

 

Thanks,

Manisha

The MathWorks

0 Kudos
Message 6 of 7
(3,857 Views)

Thank you all for your help.

 

I did test the trigger with Measurement and Automation Explorer and it works. But when I set the 'Edge Source' to /Dev1/do/StartTrigger and run my code nothing would be counted. so something is wrong with my configuration. 

 

When I Matlab DAQ toolbox, I can generate my desired pulse train with the following code but with no external triggering:

 

s = daq.createSession ('ni');
ch = s.addCounterOutputChannel('Dev1', 0, 'PulseGeneration')
s.DurationInSeconds = 4;
s.Channels.DutyCycle = 0.5;
s.Channels.Frequency = 20;
s.startForeground;

 

But when I use Matlab external triggering and send the external triggers, nothing happens:

[tc,idx]= s.addTriggerConnection('external','Dev1/PFI1','StartTrigger')

 

If this Matlab DAQ triggering works, I do not need to use NIDAQmx functions anymore.

 

 

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