03-04-2009 08:41 PM
I'm writing some software to scan an image using a series of buffers representing a line of the image on the PCI-6602. So for this, I start with an image size and make a buffer with as many points as are needed to fill out a line on the axis. Then I am using a DIO line as the trigger to switch locations in the buffer. So for each line, the system goes to the first point, then triggers, waits, moves, triggers, etc. To trigger I am sending a simple on-off through the DIO line into the gate of the counter. This setup is currently working well, but for optimization purposes I need to know some more info. With that out of the way, my questions:
1.) In order to do this, I set up a counter on task 1 with edge counting. Then, I set up a sample clock on task 1 and a DIO line on task 2. The PCI-6602 has 8 channels, am I right in assuming that I am using 2 channels for this (one for the counter and the other for the sample clock)?
2.) If so, is there a way to do a trigger based buffered counting without using the second channel, or is the smaple clock the only way to assign a trigger to a counter (not that we need 8 at the moment)?
Thanks in advance!!
03-05-2009
01:33 PM
- last edited on
03-05-2025
09:31 PM
by
Content Cleaner
Tybalt,
According to the product page here I show that the 6602 has 8 counters and 32 DIO lines. So 1 is DIO and 1 is counter if I understand you correctly. Therefore you could do 8 tasks just like this one.
03-05-2009 01:41 PM
Thanks for the reply!
So when I create the "sample clock timer" it isn't using a second channel for that? I'm having a hard time understanding what the sample clock timer is doing in this application. I feel that it's only purpose is to create the buffer, and signal when to switch the buffer. Since I am writing digital output in order to switch the buffer, I feel like things like the "rate" don't really mean anything to me. I'm wondering if there is a better way to do this...
03-05-2009 01:43 PM
03-05-2009 01:47 PM
I will include my code, but it's for matlab. I programmed it before realizing that there is already a package for using nidaqmx in matlab, and its too confusing to go back now :).
function [obj, error] = initialize(obj, N)
%Program to initialize the PCI-6602 DAQ card. Call is made as
%is shown below:
% [error] = initialize(obj, N)
%
%INPUTS
%obj is the object to initialize. obj must be a c_PCI6602
%object.
%N is the number of buffered spots per line to create. This
%will basically be area/step size on stage.
%
%OUTPUTS
%error will be an array of numbers describing the errors in the
%initialization program.
if ~libisloaded('myni')
disp('Matlab: Load nicaiu.dll')
funclist = loadlibrary('nicaiu.dll','nidaqmx.h','alias','myni');
end
disp('Matlab: dll loaded')
%libfunctionsview('myni')
%Calling syntax for calllib() is
%[X1,...,XN]=CALLLIB('LIBNAME','FUNCNAME',ARG1,...,ARGN) and the library
%has been named myni up there.
%Set Up Pointers-------------------
obj.read_array = uint32(ones(1,N+1)); %This sets up an array of the size that we will want in the future.
obj.p_readarray = libpointer('uint32Ptr',obj.read_array); %makes a pointer to the array for the software to reference.
obj.empty = [];
obj.p_empty = libpointer('uint32Ptr',obj.empty);
obj.sampread = int32(0);
obj.p_sampread = libpointer('int32Ptr',obj.sampread);
obj.sampwrit = int32(0);
obj.p_sampwrit = libpointer('int32Ptr',obj.sampwrit);
%Initialize System-----------------
%create task 1 (counting)
task1Name = ''; %type must be character string!
task1Handle = uint32(1); %type must be unsigned integer!
[out1, task1Name, task1Handle]=calllib('myni','DAQmxCreateTask', task1Name, task1Handle);
%create counter [task1] (type CI count edges) = assign counter to Dev1/ctr0
cntrl = obj.counter; %counter definition ex.'Dev1/ctr7'
startval = uint32(0); %starting value for counting (0 is prob best)
% NOTE: taskHandle and taskName are defined up there!
[out2, counter, nameToAssignToChannel]=calllib('myni', 'DAQmxCreateCICountEdgesChan', task1Handle, cntrl, task1Name, obj.DAQmx_Val_Rising, startval, obj.DAQmx_Val_CountUp);
%create daqmx timing sample clock = assign source to PFI#, task to task1, sample mode to finite, edges to rising, rate to 1000
rate = double(1000); %1000 of something.....
numsamps = uint32(N+1); %Produce N+1 samples and cut off the first one to leave N samples
linein = obj.gateport; %gate of counter 7 is PFI10 ex.'/Dev1/PFI10'
[out3] = calllib('myni', 'DAQmxCfgSampClkTiming', task1Handle, linein, rate, obj.DAQmx_Val_Rising, obj.DAQmx_Val_FiniteSamps, numsamps);
out4 = -0; %set values in case if loop is negative
out5 = -0;
if obj.trigger == 0
%create task 2 (timing)
task2Name = ''; %type must be character string!
task2Handle = uint32(2); %type must be unsigned integer!
[out4, task2Name, task2Handle]=calllib('myni','DAQmxCreateTask', task2Name, task2Handle);
%create channel [task2] (type DO digital output) = assign line to Dev1/port0/line7 (this sends to output)
lineout = obj.triggerport; %Port where the ext trigger will come from. ex.'Dev1/port0/line3'
[out5] = calllib('myni', 'DAQmxCreateDOChan', task2Handle, lineout, task2Name, obj.DAQmx_Val_ChanPerLine);
TH2 = sprintf('%.0f', task2Handle);
obj.task2 = str2num(TH2);
end
error = [out1 out2 out3 out4 out5];
TH1 = sprintf('%.0f', task1Handle);
obj.task1 = str2num(TH1);
03-06-2009
06:42 PM
- last edited on
03-05-2025
09:32 PM
by
Content Cleaner
Tybalt,
You have PFI lines 0-7 for DIO only. You also have the rest of the lines for 8 counters. You can see the different lines available here on page 32/62.