Hello,
I'm trying to take data using pause trigger + callback + counter.
(with USB-6212, python 3.7.6, windows10, NIDAQmx 19.6, PyDAQmx 1.4.3)
For example, I want to take half of sine wave(1kHz) generated by function generator and want to check how many times the trigger signal goes to low. I used sync signal of function generator as a trigger(pause trigger, pause trig when high) and counter(count falling edge).
The sync signal is high for 0.5ms and low for 0.5ms. I read the sine wave with 200kS/s sampling rate, then I should can see 100 data per every sync low.
However, it gives me only 10 data / count if I call DAQmxRegisterEveryNSamplesEvent when there is 10 data stored in a buffer(nSamples). (same thing happens even if I call the function when there is 1~50 data stored in a buffer) I thought DAQmxRegisterEveryNSamplesEvent should be called ~10 times if I set nSamples as 10, but it's not.
It also miss the data in the beginning. I want to see 100 data for every count, 1, 2, 3, 4...and so on, but it gives me nSamples data when the count is 1,9, 57, 72, 89...and finally give me nSamples data per every count from about 200 count. (and steel miss the data some times. ~1 time / thousands of counts)
I'm not familiar with ni yet, so bit confused. Is it cause of low sampling rate of the USB-6212? Or is there another reason?
Please let me know if somebody has an idea or need further information. 🙂
The part of my code is as below. (PFI8 is ctr0 of USB-6212)
import PyDAQmx as pydaqmx
import PyDAQmx.DAQmxCallBack as pydaqmxcb
nidaq = ctypes.windll.nicaiu
nidaq.DAQmxSetDigLvlPauseTrigSrc(AItaskHandle, b"/Dev%d/PFI8" %num)
nidaq.DAQmxSetPauseTrigType(AItaskHandle, DAQmx_Val_DigLvl)
nidaq.DAQmxSetDigLvlPauseTrigWhen(AItaskHandle, DAQmx_Val_High)
nidaq.DAQmxRegisterEveryNSamplesEvent(AItaskHandle,1,1000,0,EveryNCallback,id_AIdata)
nidaq.DAQmxCreateCICountEdgesChan(CItaskHandle,b"/Dev%d/ctr0" %num,"",DAQmx_Val_Falling,0,DAQmx_Val_CountUp)
nidaq.DAQmxStartTask( AItaskHandle ) # analog input task
nidaq.DAQmxStartTast( CItaskHandle ) # counter task
and inside EveryNCallback,
I read counter
def EveryNCallback_py(taskHandle, eventType, nSamples, callbackData_ptr) :
nidaq.DAQmxReadCounterScalarU32(CItaskHandle,float64(0),countdata.ctypes.data,None)
callbackData = pydaqmxcb.get_callbackdata_from_id(callbackData_ptr)
read = uInt32()
nidaq.DAQmxReadAnalogF64(taskHandle,samples_per_chan,float64(-1),DAQmx_Val_GroupByScanNumber,AIdata.ctypes.data,Length,ctypes.byref(read),None)
return 0
EveryNCallback = pydaqmx.DAQmxEveryNSamplesEventCallbackPtr(EveryNCallback_py)