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

Using quadrature encoder with callback function

$
0
0

Hello hello,

I have a rotary encoder (A-B signal) hooked up to a DI module (NI 9423) and I want it to be my source for a callback. This encoder measures distance and I now want to enter a callback function every meter for instance.

When I am only moving in one direction, everything is fine. With the DAQmxCreateCOPulseChanTicks function I set the source to "/Dev1/PFI0" and it will call the testCallback after 1 revolution (1024 ticks) only taking channel A from the encoder into account.

 The problem is that I need it to be dependent on the actual position. Meaning I need channel B as well. So how can I achieve that? As you can see I am trying to achieve this in C++ and it seems rather difficult to me.  

 

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

DAQmxErrChk (DAQmxCreateCOPulseChanTicks(taskHandle,"Dev1/ctr0","", "/Dev1Mod1/PFI0",DAQmx_Val_Low,0,1024,1024));

DAQmxErrChk (DAQmxCfgImplicitTiming(taskHandle,DAQmx_Val_ContSamps,1000));

DAQmxErrChk (DAQmxRegisterSignalEvent(taskHandle, DAQmx_Val_CounterOutputEvent, 0, testCallback, NULL));

DAQmxErrChk (DAQmxStartTask(taskHandle));

The examples provided from NI are quite helpful however none of them, targets this kind of application. With these I also achieved to calculate the current position (“DAQmxCreateCIAngEncoderChan“).

Maybe there is some sort of workaround. Maybe I could create a 2nd callback for channel B and then handle the 2 channels myself.... 

 


Viewing all articles
Browse latest Browse all 1271

Trending Articles



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