11-11-2010 03:37 AM
(I posted this question also in the Multifunction DAQ section, maybe counter/timer is a more proper section)
I want to count pulses coming from an avalanche photon detector (APD) and reference them to the intensity of a light source. I have written a small vi (using Labview 8.0, attached) to read a counter (to which I have connected the output of the APD) at intervals synchronized with the acquisition of analog data (on which I measure the output of another detector).
The counter is the card PCI-6602, while I collect the analog data with a PCI-6052 (installed on the same computer).
The vi executes successfully about 95% of the times, but in the other 5% the counter does not get sampled the number of times that I require and the DAQmx Read vi that reads the buffer times out (when the vi times out usually all the requested samples are available except the last two or three, for example if I request 5000 samples I may get 4997 and if I request 100 samples I may get 97). I attach the vi here in the hope that someone can tell me what is wrong.
The vi is quite straightforward but let me add a few lines of description so that it is clear what I have in mind when writing it - it is quite possible that I am not doing what I think I am doing and that could be the source of the problems.
First of all I create two DAQ tasks, one "Analog input" and the other "Counter input". I believe I do that correctly, the problem is not likely there.
Then I request the synchronization using the DAQmx Timing vi, Sample Clock. For doing this I wire an instance of the vi at the output of each of the tasks I created. I set the source of the Sample Clock for the analog input task to "Onboard clock" (I understand that by doing so the analog input channel sampling takes its clock from an internal clock of its own board), and I set the source of the Sample Clock for the counter task to /Dev1/ai/SampleClock (Dev1 is the name of the PCI-6052 board); if I understand correctly, this is the same source as the "Onboard clock" for the analog input, so this should already guarantee that the two samplings are performed at the same time if I set the rate for the two instances to be the same; and if I would set the rate of the clock for the counter at one half the rate of the clock for the analog input, then I would get one counter sample every two analog samples (please let me know if I am understanding wrong).I have also verified that the problem does not depend on the clock rate (same problem at 5000 Hz and at 100 Hz).
Both instances of the Sample Clock vi are set to "Finite Samples", and the number of samples is entered as a variable (the same for both). I start the counter task, and I apply to each of the tasks the DAQmx Read set to the proper case.
Sometimes the DAQmx Read fails with error code -200284, and the size of the vector it reads is smaller than what it should be by a couple of units.
The curious thing is that if I select Analog Wfm NChan NSamp instead of Analog Wfm NChan NSamp then the timeout problem becomes worse, happening about 10 to 15% of the time.
What could be the problem? I am doing something wrong? Thanks in advance for all of the answers.
Giovanni
Solved! Go to Solution.
11-11-2010 01:25 PM
Ciao Giovanni,
The two tasks are running in parallel so there is no guarantee which task starts first. I suspect that when you are missing counter samples it is because the analog input task is starting before the counter task. In this case, the counter task would not be ready to accept sample clocks and it may miss a few clock edges by the time it is started.
One way to solve the problem would be to use error wires to ensure the counter task starts before the analog input task. You could also use a sequence structure to do this.
The counter will be sampled off of every edge of the AI sample clock regardless of what you set the "rate" input to. When using an "external" clock (external to the task that is), the driver just uses the rate input to set a few default parameters (e.g. buffer size).
If you have any questions please don't hesitate to ask!
Best Regards,
11-18-2010 11:00 AM
Hi John,
I tried your suggestion today (the sequence version) and in fact now I do not get any error. Thanks a lot for your help.
Giovanni