Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

CounterOutputEvent Callback

Solved!
Go to solution

We have searched the forums and looked for examples but have not been able to find anything that works. We are working in C which makes the examples and help that much less avaliable.

 

Hardware:

NI6612

 

We are suppling an external signal "clock" (10Mhz) that we are down sampling by using a counter.

 

We are using the count edges chan function and trying to attach Register Signal Event with CounterOutputEvent so that we can get a call back. But this gives us the error "Event souce signal specified is not supported with the measurement type and/or sample timing type of the task."

 

DAQmxCreateTask("",&taskHandle);

DAQmxCreateCICountEdgesChan(taskHandle,"/Dev1/ctr1","",DAQmx_Val_Rising, 10, DAQmx_Val_CountDown);

... (other configuration to enable reset and specify port to reset on)

DAQmxRegisterSignalEvent(taskHandle, DAQmx_Val_CounterOutputEvent, 0, CallBack, NULL);

 

 

Currently we are getting the counter to reset to original value when it reaches zero and count down again. This happens in hw and we dont need to monitor the counter. We have tried to set the counter output to pulse so that we can do change detection on a different port but this did not work. the O-scope did not show a signal being generated so that may be the reason change detection event did not trigger.

 

Please help us on how to get a callback when the counter reaches zero.

0 Kudos
Message 1 of 6
(3,938 Views)

I'm still a little unclear on the overall application. From how you are calling DAQmxCreateCICountEdgesChan it looks like your counter resets every 10 counts. I think the event is failing to register because it is for a counter output task.

 

Does this mean you want to trigger the callback at a rate of 1MHz? I am not sure that your application will be able to keep up with callbacks at that rate.

 

That being said, if you want to derive a lower frequency signal from this signal you probably want to use a counter output task instead. DAQmxCreateCOPulseChanTicks() declares an output that will stay low for a specified number of input clock ticks and then go high for a specified number of ticks.

 

Dale S.
RF Systems Engineer - NI
0 Kudos
Message 2 of 6
(3,900 Views)

Thank you for your response.

 

The overall idea is that I need the code in the callback to happen consitently and be timed from the external input. I was mistaken by the 10Hz divide, we are actually needing the callback every 50Hz so divide by 200,000. The 50Hz callback should be doable.

 

The reason I went with the DAQmxCreateCICountEdgesChan is because all my timing needs are internal and exporting a 50Hz signal is not useful to me. Routing a signal back into the card and doing a change detection event is not ideal.  The perfered method would be for everything to happen internally.

 

 

 

0 Kudos
Message 3 of 6
(3,891 Views)
Solution
Accepted by topic author UCbrian

So, determining output vs input tasks can be tricky when it comes to counters. It's an output task because you are generating a signal based on some timebase that you are counting. Since it's an output task, you will need to choose an output terminal. This doesn't have to be an external terminal though (use ctr1InternalOutput).

 

Then, you can use DAQmxCfgSampClkTiming() or DAQmxSetTimingAttribute() to choose the terminal that you are supplying the external timebase on (Source).

Dale S.
RF Systems Engineer - NI
Message 4 of 6
(3,880 Views)

Hi Dale,

searching the forum I found this post and I guess I have the same problem as you had, however I am not quite at the solution yet. I am using C++.

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. So basically I want a function to be called after x-counts.

 

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?

 

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));

 

0 Kudos
Message 5 of 6
(2,844 Views)

[Edit:  deleted this response after answering same question, with a little more detail over in new thread here.]

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 6 of 6
(2,838 Views)