Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-DAQmx DAQmxReadCounterF64 function

Here is VB6 code to use Ctr0 on PXI-6254 (in slot 2) to do 'PULSE WIDTH' measurement:

 

Dim taskHandle As Long

Dim ctrData As Double
Dim sampsPerChanRead As Long

Dim MinVal As Double

Dim MaxVal As Double

 

MinVal = 0.001

MaxVal = 1.0

 

Line 1: DAQmxErrChk DAQmxCreateTask("", taskHandle) 'Create Task

Line 2: DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle, "PXI1Slot2/Ctr0", "", MinVal, MaxVal, DAQmx_Val_TimeUnits3_Seconds, edge, "") 'Add Ctr channel to the task

Line 3: DAQmxErrChk DAQmxStartTask(taskHandle(taskNo%)) 'Arm counter and start measuring 'Arm and start measurement

 

'some time later following call is made

Line 4: DAQmxErrChk DAQmxReadCounterF64(taskHandle, 1, 10#, ctrData, 1, sampsPerChanRead, ByVal 0&) 'Read the pulse width

 

Observation:

 

1. It seems that if there is nothing connected to the Ctr0 input pin or there is no pulse at the input pin then Line4 above times out after 10 seconds, i.e., VB6 program feezes up for 10 seconds.

 

2. It was also observed that if I use 'Simulated NI-DAQmx Device' for PXI-6242's Ctr0 (set up in MAX) then Line 4 returns right away.

 

Questions:

 

1. Is there any way to make Line 4 'asynchronous' and exit and return pulse width value measured 'so far'? For example, if actual pulse widht is , say, 83 ms, and when Line 4 is executed only 40 ms pulse is done then I would like to see DAQmxReadCounterF64 return 0.040 s. When I get two consecutive readings same, I will know Pulse is done. This way, my 'Pulse Width' value display on the screen counts up starting from zero and stops when pulse is over. NOTE: I do not like to use NI-DAQmx CALLBACKs in VB6 because I think they are not reliable.

 

2. If I use DAQmxIsTaskDone function, will it tell me when pulse width measurement is over?

 

3. If answer to Q2 is 'yes' then what happens if second pulse starts before I get a chance to read the first pulse width value?

 

4. Why does 'Simulated NI-DAQmx Device' behave differently for Line 4?

 

Thank you.

 

0 Kudos
Message 1 of 2
(5,731 Views)

Hello,

 

The functionality you are requesting for may not be plausible since counter tasks return values at rising/falling edges (see the link 1 below, section on Counters, Chapter 7 of the M-Series User Manual). A recommended approach would be to use a Digital Input Task; this would require VB6 code manipulation on your end, to read a set number of samples periodically (also, a change in your signal from low/high or vice versa would need to be taken into account). DAQmx Is Task Done function checks if the measurement or generation is finite and the task is done when you acquire/generate the final sample or when you call the Stop Task function/VI. If the measurement/generation is continuous (including on-demand timing), the task is not done until you call the Stop Task function/VI. In addition, the task is done if a fatal error is generated while performing the measurement or generation, or you abort the measurement or generation. NI-DAQmx tasks for simulated devices are verified just as they are on real devices, hence all resources necessary for counters, and so on, are counted and reserved for NI-DAQmx simulated devices just as they are on real devices. However, an important thing to note about simulated DAQmx Counter data is that its always returned as 0 (see link 2 below).

 

1. M-Series User Manual (Chapter 7: Counters): http://digital.ni.com/manuals.nsf/websearch/2025C99AB0614F9E8625748000577B9A

2. NI DAQmx Simulated Devices: http://zone.ni.com/devzone/cda/tut/p/id/3698

 

Regards,

 

Ali M

Applications Engineer

National Instruments

Message Edited by Ali M on 04-05-2010 05:47 PM
0 Kudos
Message 2 of 2
(5,696 Views)