07-06-2008 08:57 PM
Hi All,
Please see code below for my problem. I removed error checking to make things easily readable. Whenever I enable callbacks using DAQmx_Val_CounterOutputEven, the following code utilizes 100% CPU even with the 10Hz counter!!!! Am I missing something here? I tried all the options for interrupt based processing instead of busy polling to no avail. This is just unacceptable. These days one can't even deliver an app that is permanently running at 100% cpu without raising some eyebrows...
I must be missing something...
My application requires that I generate TTL level trigger pulses and at the rising edge of each trigger pulse, I also need to execute some very short C code. This code should start running within .5ms of the trigger edge. This should be no problem for a modern CPU. This is why I am using DAQmx_Val_CounterOutputEvent. However, I cannot have NIDaq implement this using busy polling (which I assume it's doing since it's eating 100% cpu). It is simply not acceptable to be running at 100% CPU for several reasons. The documentation and this support site talk about interrupt based processing, and the hardware is obviously capable of it.
So, the 2 questions I have are:
1. What do I have to do in order to have NIDaq use interrupt based processing instead of busy polling (for the DAQmx_Val_CounterOutputEvent callbacks in my application)?
2. In addition to (1), can I make it so that my callback only gets called on the rising edge of the trigger signal instead of both the rising and falling edges? Perhaps I can wire the counter output to a general purpose input and then generate interrupts based on the rising edge that the input measures?
Please help,
Philip
// currently the callback simply does nothing to make sure i'm not causing the 100% cpu problem
static int StaticTriggerCallback(TaskHandle taskHandle, int32 signalID, void *callbackData)
{
// we will get called once for every rising and once for every falling edge (20hz). We would prefer to be called only on the rising edge. Is that possible?
return 0;
}
void TTCameras::StartTimer(void)
{
// Configure DAQmx ct3 as our spin camera trigger. 10Hz
DAQmxCreateTask("", &taskHandle);
DAQmxCreateCOPulseChanFreq(taskHandle, "/Dev1/ctr3", "CameraSpinTrigger", DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, 10.0, 0.5);
DAQmxCfgImplicitTiming(taskHandle, DAQmx_Val_ContSamps, 1000);
DAQmxSetReadWaitMode(taskHandle, DAQmx_Val_WaitForInterrupt);
// I tried this but it does not help:
//DAQmxSetRealTimeWaitForNextSampClkWaitMode(taskHandle, DAQmx_Val_WaitForInterrupt);
// If I register this callback, CPU usage goes to 100%. This callback needs to be done based on interrupts!
DAQmxRegisterSignalEvent(taskHandle, DAQmx_Val_CounterOutputEvent, 0, (DAQmxSignalEventCallbackPtr)StaticTriggerCallback, NULL);
DAQmxStartTask(taskHandle);
}
07-07-2008 03:29 PM