LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I reduce the time from the detection of a input threshold to changing the output?

Hi,

 

I am using LabWindows 8.1 and a PXI-4461 with Vista (home) on a 2.81 GHz Dual Core Processor.  I wrote code to do the following:

(1) output a ramp, input a signal concurrently (precise sychronization of these two is not important at this point)

(2) if the input signal rises above 0.5 V, hold the output constant for 2 seconds, while continuing the input

(3) finish the ramp

 

More info: I do a continuous sampling, with 4 samples per Write, to do the output.  The input is read and analyzed with RegisterEveryNSamples (where N = 4).  The communication between the tasks is through a global variable "trap," which is set to 1 when threshold is reached.  I achieve holding the output constant by stopping the task (maintain existing value = true), and then restarting after the pause.  At 40kHz and 4 samples per Write, the limit imposed by the discrete data blocks would be  0.1 msec, but in fact I am getting delays of about 2.5 msec.  My write buffer is 120x4 samples, just so that there is space for me to write.  I do need to save the input data after the acquisition, preferably the whole sweep, but most importantly the data while the output is held constant.  

 

So my questions are:

 

(a) Does it really take 2 ms to stop a task? When I put in "Timer()"  functions as below, I get a difference of 0.002, which is of course limited to the resolution of the Timer() function. Returning from a function (the EveryN callback) should not take that long, right?

 

(b) Can you suggest any better ways of doing this?

 

 

/*****begin excerpt *****/

 

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(inputTaskHandle,DAQmx_Val_Acquired_Into_Buffer,4 ,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxWriteAnalogF64(outputTaskHandle,480,0,10.0,DAQmx_Val_GroupByChannel,outData,&written, NULL));

DAQmxErrChk (DAQmxStartTask(inputTaskHandle));
DAQmxErrChk (DAQmxStartTask(outputTaskHandle));

       
    for (count =120;count<10000; count++)
    {
        if (trap==0) {
            DAQmxErrChk (DAQmxWriteAnalogF64(gTaskHandle,4,0,10.0,DAQmx_Val_GroupByChannel,&outData[count*sampsToWrite],&written,NULL));
        } else {
                DAQmxErrChk (DAQmxStopTask(outputTaskHandle));
                time2 = Timer();
                done = 1;
                ProcessDrawEvents();
                ProcessSystemEvents();
                Delay (2.0);
                trap = 0;
                count++;
                DAQmxErrChk (DAQmxWriteAnalogF64(outputTaskHandle,480,0,10.0,DAQmx_Val_GroupByChannel,&outData[count*4],&written,NULL));
                count = count+119;
                DAQmxErrChk (DAQmxStartTask(outputTaskHandle));

        }
       
    }

 

/*****end excerpt *****/

 

 

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples,void *callbackData)
{
    ...


    DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,nSamples,10.0,DAQmx_Val_GroupByScanNumber,&readData[inCount*nSamples],nSamples,&numRead,NULL));
   
   
    if (trap == 0 && done == 0) {
        for (i=0; i<nSamples; i++) {
            if (readData[inCount*nSamples+i] > 0.5) {
                trap = 1;
                time1 = Timer();
                break;
            }
        }
    } else done = 1;
   
    inCount++;
   

Error:
    ...
    return 0;
}

 

I would appreciate any help or advice! Thanks.  (Sorry about oddities in the code.)

0 Kudos
Message 1 of 1
(2,809 Views)