Quantcast
Channel: Counter/Timer topics
Viewing all articles
Browse latest Browse all 1271

Edge counting & pause trigger

$
0
0

Dear all,

 

Hello, can I ask a question about pause trigger & edge counting?

I'm using USB-6212, python 3.7.6, windows 10, NIDAQmx 19.6 and PyDAQmx1.4.3

(Please let me know if you have any idea not only in python, but also in C, etc. Probably I can translate it to python.)

 

I have one TTL signal which I use for triggering.

I take AI data when the TTL signal is low (using pause trigger and callback function)

 

Meanwhile, I also want to count falling edge of TTL signal, cause I want to know how many times the TTL signal went to low.

 

For example, I want to take 1000 data while the TTL signal is low. I take 1000 events (TTL low), do not take event (TTL high), take 1000 events again (TTL low), and repeat the sequence. And I want to distinguish every 1000 events(I mean I want to distinguish the first 1000 events, the second 1000 events, the third 1000 events and so on). I call the callback function when there is 100 events stored in the buffer, so I cannot count the # of triggers in the callback function.

 

Is that possible to do this job?

 

I wanted to use counter, but I have no idea how can I use it with pause trigger + callback function.

I tried to put

nidaq.DAQmxCreateCICountEdgesChan(AItaskHandle,b"/Dev%d/ctr0"%num,"",DAQmx_Val_Falling,0,DAQmx_Val_CountUp)
but don't know where can I read it. (and not completely sure if ctr0 matches PFI0)

Maybe I should not use callback function and trigger but do this job by reading DI one by one and find the falling edge and signal low?(Take one DI(PFI0), try to find falling edge and the state(high/low) every time, take one AI data, save one AI data somewhere(file or array, etc) if the DI is low using while(taskStarted) loop seems not elegant.)

 

 

Here is a piece of my code.

import PyDAQmx as pydaqmx
import PyDAQmx.DAQmxCallBack as pydaqmxcb
nidaq = ctypes.windll.nicaiu
 
...
 
nidaq.DAQmxSetDigLvlPauseTrigSrc(AItaskHandle, b"/Dev%d/PFI0" %num)
nidaq.DAQmxSetPauseTrigType(AItaskHandle, DAQmx_Val_DigLvl)
nidaq.DAQmxSetDigLvlPauseTrigWhen(AItaskHandle, DAQmx_Val_High)
nidaq.DAQmxRegisterEveryNSamplesEvent(AItaskHandle,1,1000,0,EveryNCallback,id_AIdata)
 
...
 
def EveryNCallback_py(taskHandleeventTypenSamplescallbackData_ptr) :

DAQmx_Val_GroupByScanNumber = 1

callbackData = pydaqmxcb.get_callbackdata_from_id(callbackData_ptr)
read = uInt32()
nidaq.DAQmxReadAnalogF64(taskHandle,nSamples,float64(-1),DAQmx_Val_GroupByScanNumber,AIdata.ctypes.data,Length,ctypes.byref(read),None)
return 0

EveryNCallback = pydaqmx.DAQmxEveryNSamplesEventCallbackPtr(EveryNCallback_py)
 
...
 
 
Thank you in advance!
 

Viewing all articles
Browse latest Browse all 1271

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>