09-01-2009 05:46 AM
Hi, I'm trying to figure out how to hook up an event to be fired when a counter has reached a specific value.
We have a counter hooked up to an encoder a constantly counting encoder pulses. I want to set up a counter task to give a callback
as soon as a certain encoder value is reached. I.e give callback when countervalue is 1000. This value should be dynamically changable so next time the countervalue to generate a callback could be any value.
I understand there's workarounds like polling and/or read current values and subtract with offsets from a zerolevel... and so on, but to minimize complexity I'd like to just hook up a Task callback with a changable countervalue parameter.
I'm using DaqMx and have a 6220 but any card can be used.
/J
09-17-2009 02:50 AM
Hi Jonster
You haven't mentioned if you are using LV or not so I'll assume you do. What I would do, if my interpretation of what you want is correct, is to register a dynamic event. Have a look at the examples in the Example Finder under "Hardware Input and Output -> DAQmx -> Events", especially Acq&Graph Voltage-Int Clk-EveryN&DoneEvent.vi
Best Regards
David
NISW
09-17-2009 02:53 AM
Thanks,
I'll have a look.
I'm not using LV but the .NET API
/J
09-21-2009 12:36 PM
In that case you should do something like this;
Task.CIChannels.CreateCountEdgesChannel(
"/Dev1/Ctr0",
"SomeName",
CICountEdgesActiveEdge.Rising,
iTerminalCount - iTrigcount, //iTerminalCount is the maximum value of the counters register, these things are // probably board dependent but constant. iTrigcount is the variable you pass (e.g. 1000)
CICountEdgesCountDirection.Up);
Then you can hook up an eventhandler like so;
Task.CounterOutput += new CounterOutputEventHandler(Task_CounterOutput);
And the eventhandler;
void Task_CounterOutput(object sender, CounterOutputEventArgs e)
{
// Do stuff. Probably the first thing to do here is stop the Task...
}
You can fill this in however you please...
I never used this but it should work I think. Also have a look here to see how you can calculate Terminal Count;
Now here's to hoping you like C# (because I absolutely hate VB 🙂
If necessary and you provide more feedback I can also build you a class that handles the job you need... Let me know!
10-11-2011 10:15 PM
Hi,
I tried to generate an event callback when the counter reached 0 using LabWindow/CVI version 9.1.1 (450) but got an error -200800. Could someone tell me what the problem is? FYI, the code that I have is:
DAQmxErrChk (DAQmxCreateTask("",&Counter1_taskHandle));
DAQmxErrChk (DAQmxCreateCICountEdgesChan (Counter1_taskHandle, "Dev1/ctr1", "", DAQmx_Val_Rising, initialCount, DAQmx_Val_CountDown));
DAQmxErrChk (DAQmxRegisterSignalEvent (Counter1_taskHandle, DAQmx_Val_CounterOutputEvent, 0, CounterOutputCallback, NULL));
DAQmxErrChk (DAQmxStartTask(Counter1_taskHandle));
Thanks,
10-12-2011 08:26 PM
I just want to add that I'm using the counter on the PCIe-6323.
06-30-2016 04:47 AM
I would like to find a solution to the exact same issue and it does not seem to be confirmed or denied anywhere.
KrisJa: It seems like you are starting a new counter that returns a callback after a certain number of counts. This is not what is desired, many counts will be lost before this counter is up and running.
Example of desired functionality:
At counter value X you observe something and you want to act on this after an additional Y counts (then you know the conveyor has moved a certan distance since the observation or a certain time has passed), therefore you want a callback when the running counter has reached the value of X+Y. Or alternatively (and often even better) you want to setup some task and trigger it at count X+Y.
Is there a way to do this on a running counter?
Restarting a counter or setting up a new counter will not be deterministic since there is software timing involved in restarting or starting a new. Using a continously running counter this will be completely hardware timed.
I have to use this on a PCI-6601, using preferably NI-DAQ Traditional (7.x), but I could upgrade to DAQmx if needed.
I am interfacing from either C++ or C#.
It could be on both a counter that is polled or a counter with buffered sampling.
Hope someone has an idea if this is even possible!
Thanks.
07-05-2016 02:04 PM
Simon
I have put in a request for nearly the exact functionality you describe here: http://forums.ni.com/t5/Data-Acquisition-Idea-Exchange/Every-n-encoder-pulses-callback/idi-p/3157548...
NI engineers will only look at it if it receives sufficient kudos!
07-05-2016 02:12 PM
I think you can actually do this.
To get a callback every N counts of a counter (encoder) you need to use additional counters.
First counter counts the encoder using bufferede counting. Buffer a sample every time the second counter has rising edge.
Second counter divides down the encoder pulses by a factor of n, output is the trigger for the first counter.
What i need is on a running counter to dynamically and whenever required sign up for a callback when the counter reaches a value (determinde while the counter is running).