Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffered event counting with 6602 card and VB6

Hello All,

I am trying to do some buffered event counting using a 6602 card, DAQmx driver under Visual Basic 6. Basically, I would like to replicate what Chris Erven did in Labview (see his posts) for photon time stamping.
I have a simulated photon source on counter 0. I am using the 80 MHz timebase to time tag the pulses on counter 1.
I post my code below.

On the 'DAQmxStartTask', I get a run-time error -89120 (fffea3e0) saying that the 'Source terminal to be routed could not be found on the device'.
I am puzzled about this. Can anybody help?

My code looks like this:
DAQmxErrChk DAQmxCreateTask("", taskHandleTS)
DAQmxErrChk DAQmxCreateCICountEdgesChan(taskHandleTS, "Dev1/ctr1", "", DAQmx_Val_Edge1_Rising, "0", DAQmx_Val_CountDirection1_CountUp)
DAQmxErrChk DAQmxSetCICountEdgesTerm(taskHandleTS, "Dev1/ctr1", "Dev1/80MHz Timebase")
DAQmxErrChk DAQmxCfgSampClkTiming(taskHandleTS, "/Dev1/Ctr0InternalOutput", 1, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_ContSamps, 10000)
DAQmxErrChk DAQmxStartTask(taskHandleTS)

Thank you in advance
0 Kudos
Message 1 of 9
(5,895 Views)
Hi Atacama,

I think all you need to do is remove the Dev1/ form the source terminal name. Your function should read:

DAQmxErrChk DAQmxSetCICountEdgesTerm(taskHandle, "Dev1/ctr1", "80MHzTimebase")

Regards

Jon Bowers  
Applications Engineer
NI UK & Ireland
0 Kudos
Message 2 of 9
(5,862 Views)
Thank you very much for your help. It solved it!

I am now trying the counts on ctr1.
Here is my code below. Nothing happens, it loops continuously.
Shall I use "Dev1/ctr1" or "/Dev1/Ctr0InternalOutput" as the channel name ?
What else can be wrong ?

While TaskIsRunning = True
    DAQmxErrChk DAQmxGetCITCReached(taskHandleTS, "Dev1/ctr1", fReached)
    If fReached Then
        DAQmxErrChk DAQmxGetReadAvailSampPerChan(taskHandleTS, lAvailableSamples)
    End If
   
    DoEvents
Wend
0 Kudos
Message 3 of 9
(5,860 Views)
I am not sure exactly what you are trying to achieve. Why are you reading the Available Samples Per Channel property after the terminal count has been reached? When you say your code does nothing, do you mean it never reaches the terminal count or that the property you are reading never changes value?. What do you expect it to do?

Regards

Jon Bowers
Applications Engineer
NI UK & Ireland
0 Kudos
Message 4 of 9
(5,860 Views)
Hi Jon, I am trying to do some buffered counting and only read the data if a large number is available. I attach a Labview version of what I am trying to do. My program does not do anything means that the terminal count is never reached. If I remove this condition, I can actually read some data. Thanks.
0 Kudos
Message 5 of 9
(5,850 Views)
Jon,

Thank you again for your help.

I now have some problems to retrieve the data. I want to read my buffer back when data are ready.
I am trying to use the DAQmxReadCounterF64 function but it does not work.
It works fine if I loop on DAQmxReadCounterScalarF64 to read the data points one by one but it is very slow obviously.
Visual basic complains that the 4th parameter of DAQmxReadCounterF64 cannot be an array.

What is wrong?

dim dData(1 to 1000) as double
DAQmxReadCounterF64(taskHandleTS, -1, 10, dData, 1000, lSamplesRead, ByVal 0&)

Atacama
0 Kudos
Message 6 of 9
(5,836 Views)
You need to pass the data array as a Double. Try DAQmxReadCounterF64(taskHandleTS, -1, 10, dData(0), 1000, lSamplesRead, ByVal 0&) instead.

As to your teminal count not being reached, if you just read back the values can you see them increasing?

Regards

Jon B
Applications Engineer
NI UK & Ireland
0 Kudos
Message 7 of 9
(5,831 Views)
Jon,

Thank you so much. I can now read my data back.

The last question I have is regarding DMA transfers:
Apparently I can decide to use or not the DMA transfer. For speed reasons, I want to use DMA.

If I don't configure it, does the system uses DMA transfers by default, or do I need to specify it?

Regards,

Atacama
0 Kudos
Message 8 of 9
(5,830 Views)
Yes, the DMA transfer method will be used by default if you do not configure it otherwise.

Regards

Jon B
Applications Engineer
NI UK & Ireland
0 Kudos
Message 9 of 9
(5,823 Views)