LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting program does not work well

Solved!
Go to solution

Hello,

 

I'm trying optical measurement using avalanche photodiode (APD).
I created counting task on MAX and confirmed the task counted the pulse edge from APD correctly (i.e. if the signal is 1 MHz, the count value increased 1,000,000 /s).
However, when the task loaded to my CVI program, the task does not return the expected count value.
My program is like this:

 

qw=0.;
GetCtrlVal (pnl_panelHandle, PNL_GATEFREQ, &gatetime);			//gate time is read from the UI panel in ms.
timeout = gatetime/1000 ;						//convert gatetime from ms to s.
DAQmxLoadTask ("CI0_TaskHandle", &CI0_TaskHandle);			//load the MAX task.
DAQmxStartTask (CI0_TaskHandle);					//start the task.
DAQmxReadCounterScalarF64 (CI0_TaskHandle,timeout, &qw, NULL);	    //read count value and pass it to qw.
Delay(timeout*1.2);												
DAQmxStopTask (CI0_TaskHandle);						//stop the task.
return qw;

 

in the program, this counting is repeated.
This program returns very low qw value. For example, even if gate time is 1000 ms (thus timeout is 1 s), most of qw is 0 or 1.
When the bright light is irradiated to APD, qw value increases to ~30. So the program is working, but the maximum value is too low.
Is there any problem in my program? I'm not sure about it...

0 Kudos
Message 1 of 4
(2,288 Views)
Solution
Accepted by topic author atkjmb

You are reading the count immediately after starting the task. I think you should put the delay before the read. Timeout value in the read function is not a gate. It is the maximum duration the function is going to wait for reading. It does not guarantee a waiting duration of 1.2 sec. 

Is the task working as expected when you run it from MAX? 

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 4
(2,271 Views)

The program worked when putting delay function before the read function. I misunderstood about the read timing.

Thank you very much!

0 Kudos
Message 3 of 4
(2,254 Views)

Nice, glad it worked. Please don't forget to mark my post as acceptable solution. Some other person might also benefit. Cheers.. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 4
(2,250 Views)