02-09-2011 11:55 AM
Hello,
I have a problem implementing a single pulse on an NI USB-6212. I know that Matlab (data acquisition toolbox) dosn't support the access to the counter/timer of the 6212. Thus, I try to use direct calls to the NIDAQmx driver.
The pulse generating system already works in LabView, but i have to implement it in Matlab. The following picture is the screenshot of the working LabView system..
The basic idea of this system is, to generate one pulse with a defined "high-time" and "low-Time". After the first pulse is executed, a second single pulse starts with another defined high- and low-time. The second pulse is triggert with the first pulse and has an offset of high-time + low-time. The output-channel of the first pulse is at ctr0 and the second pulse at ctr1.
Now, I tried to write an matlab-script to generate the first pulse, but it won't work.
%% Load Lib
if ~libisloaded('myni')
disp('Matlab: Load nicaiu.dll')
funclist = loadlibrary('nicaiu.dll','C:\Programme\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h','alias','myni');
%libfunctions('myni','-full') % use this to show the...
%libfunctionsview('myni') % included function
end
disp('Matlab: dll loaded')
disp('')
% After loading a shared library into the MATLAB workspace, use the
% calllib function to call functions in the library.
% The syntax for calllib is:
% calllib('libname', 'funcname', arg1, ..., argN)
%% DAQmx Configure Code
% Taskhandle = libpointer( 'uint32Ptr', 0 );
Taskhandle = uint32(1);
Taskname = 'CounterTest';
[a,b,Taskname] = calllib( 'myni', 'DAQmxCreateTask', Taskname, Taskhandle );
% create channel name for counter input edge count
taskchans1 = ['Dev1/ctr0'];
DAQmx_Val_Seconds = 10364; % Seconds
DAQmx_Val_Low = 10214; % Low
% create channel
% DAQmxCreateCOPulseChanTime(TaskHandle taskHandle, const char counter[], const char nameToAssignToChannel[], int32 units, int32 idleState, float64 initialDelay, float64 lowTime, float64 highTime);
a = calllib( 'myni', 'DAQmxCreateCOPulseChanTime', Taskhandle, taskchans1, '',...
DAQmx_Val_Seconds, DAQmx_Val_Low, 1, 0.5, 1 );
DAQmx_Val_FiniteSamps = 10178; % Finite Samples
m = calllib( 'myni', 'DAQmxCfgImplicitTiming', Taskhandle, DAQmx_Val_FiniteSamps, 1 );
% DAQmxCfgImplicitTiming(TaskHandle taskHandle, int32 sampleMode, uInt64 sampsPerChan);
%% DAQmx Start Code
calllib( 'myni', 'DAQmxStartTask', Taskhandle );
%% DAQmx Wait Code
calllib( 'myni', 'DAQmxWaitUntilTaskDone', Taskhandle, 10 );
However, this script runs without an error, but with no reason, there is no pulse at the output??? ![]()
Has anyone an idea what's wrong with this matlab-code? I hope somebody can help me with this problem...
Robert
02-10-2011 08:53 AM
Hey,
I just found the solution by myself. It was a problem with the taskhandle which has to be [] instead of uint32(1).
Additionally, the taskname has the be empty as well.
Thank you anyway...
Robert