08-25-2008 12:21 PM
hello--i'm trying to use c function calls to contact a digital counter on
a ni-usb6529 bnc multifunction daq device. i want to count photomultiplier
pulses of a ttl level. i need to read the counter about 10x a second
but i want to gate the counter to a window 10 microseconds long.
i want to use c function calls from the matlab data acquisition environment.
it sounds to me as though i want to configure one of the 2 counters to
recognise a pause trigger on the gate input but i can't understand how
to do that. can anyone offer me any advice? thanks in advance for
any help anyone can offer. i've been able to read the counter and i
can change the number of counts by varying the rate of pulses fed
to the default clock terminal but nothing i do to the default gate
channel has any effect.
08-26-2008 10:24 AM
Hi slgulick,
It sounds like you need to use a standard edge counting example with the addition of the pause trigger. The Pause Trigger can be implemented through the DAQmx Trigger Properties where you can set the Pause Trigger Type, The Pause Trigger Source, and the Pause When properties. This information can be found in the DAQmx C Reference Help (Start>>Programs>>National Instruments>>NI-DAQ>>NI-DAQmx C Reference Help). This installs with the Microsoft Visual C Support option when you are installing the DAQmx Driver.
In the DAQmx C Reference Help, you can expand NI-DAQmx C Properties>>List of Trigger Properties. You can find Pause in the list of triggers and see the associated properties that you can set. You will likely want to set the Pause Trigger Type to Digital Level and set the appropriate Digital Level properties. With this configured make sure that the signal connected to you Pause Trigger Source fits your application and you should be counting the digital events when the pause trigger signal is high.
08-27-2008 02:45 PM
thanks steve for your reply. i've been able to configure a pause trigger and
to use it to gate the counter. i'm trying to do this experiment using c function
calls from matlab. i can read the counter using
countread=0;
countread_ptr=libpointer('uint32Ptr',countread);
empty=[];
empty_ptr=libpointer('uint32Ptr',empty);
disp('NI: Reading Data!')
[a,b]=calllib('myni','DAQmxReadCounterScalarU32',...
taskh1,1,countread_ptr,empty_ptr)
and i can either turn off or turn on the counter by controlling the default gate, pfi9,
and feeding 4v x 50ns pulses into the default source, pfi8. the number of counts
varies with the pulse rate and the duty cycle of the signal i put on the gate, and
i can turn the gate on or off with ttl low or high logic.
my problem now
is timing--i need to position the gate so that it opens at a fairly precise time
with respect to my experiment and i can't find any way to relate the read
of the counter to the gate pulse temporally. i've been able to query the
counter task with
[a,b,c]=calllib('myni','DAQmxGetDevCITrigUsage','Dev1',c)
which returns 34, indicating that for counter input my device can use
pause and arm start triggers but i was unable to configure an arm start
trigger and i don't see how that would help anyway. i've thought of setting up
another channel to look for a trigger but so far i haven't been able to do
this. my whole experiment involves setting a dc voltage and then entering
a loop which waits for a laser trigger, activates the counter to wait for
a 10usec 'pause' window during which it counts ttl pulses from a
photomultiplier, reads the counter and adds the counts to a register, resets
the counter and returns
to await another laser pulse. after a fixed number of loops the dc
voltage is reset and the loop begins again. the laser fires on the order
of 10x/second, there's a delay of between 300usec and 1 millisecond
between the laser trigger and the opening of the 'pause' window, and
ideally the window should be between 1 and 50usec long. since it's
impossible to combine digital input and counter channels in the same task it seems
as though this must be a multitask operation and i can't seem to figure
out how to coordinate the timing between tasks.
thanks again for any help you can offer
sincerely, sid gulick
08-28-2008 03:35 PM
i've managed to write a small matlab routine which does what i want although i'm not certain the timing is really
rocksolid and i haven't taken account of possible sticks which can be thrown in the spokes.
i use the 'nidaq' adaptor from the matlab data acquisition toolbox to set up an analog output and
analog input task, and the c library function calls to access the counter. i set up a pause trigger
for the counter and a dummy analog input to receive a trigger in order to locate the counter in
time. my program outputs a dc voltage, enters an interior loop in which it reads the counter
20 times and resets it after reading it, and then exits to an exterior loop which increments
the dc voltage 10 times. i think i've attached my 'm' file if it's any use to someone with a similar
problem. i'll try to improve the timing--i'm not sure whether the delay between the analog
in trigger and the counter gate is just a fortuitous coincidence of hardware and software or
whether there's really a constant time between the call to the ai read and the call to the
counter read.