Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the DAQ voltage takes 7ms, how can i make it faster

I use NI-USB-6229 and calling it using CVI,

 

in order to change the Voltage i made this function, which i call whenever i need to change the voltage level,

the process takes about 7[ms[, which is very long. how can i shorten it? are there parts that i can skip?

 

 

//DAQ:
void SetDaqOut (char channel[],float64  DaqOutVal )
{
    int error;
    int32       written; 
    char        errBuff[2048]={'\0'};
   
    float64 ValArray[]={DaqOutVal};
   
    TaskHandle TaskSetOut;
   
    SetWaitCursor(1);
   
   
    DAQmxErrChk (DAQmxCreateTask("",&TaskSetOut));
    DAQmxErrChk (DAQmxCreateAOVoltageChan (TaskSetOut, channel, "", 0, 10, DAQmx_Val_Volts, ""));
    //DAQmxErrChk (DAQmxCreateAOVoltageChan (TaskSetOut, channel, "", 0, 10,
    //             DAQmx_Val_FromCustomScale , calibrated_teta)); 
    DAQmxErrChk (DAQmxWriteAnalogF64 (TaskSetOut, 1, 1, 10.0, DAQmx_Val_GroupByChannel, ValArray, &written, NULL));
    DAQmxErrChk (DAQmxStartTask(TaskSetOut));
   
   
    DAQmxStopTask(TaskSetOut);
    DAQmxClearTask(TaskSetOut);
   

    Error:
    SetWaitCursor(0);
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
}

 

 

 

thank in advance,

 

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

If you just want to change the voltage, don't create the task and channel and close the task each time.

0 Kudos
Message 2 of 6
(3,396 Views)

so what should i do? save the task pointer and call it each time?

 

something like that?:

 

void SetDaqOut (char channel[],float64  DaqOutVal, int finish_and_clear )
{
    int error;
    int32       written; 
    char        errBuff[2048]={'\0'};
   
    float64 ValArray[]={DaqOutVal};
   
    static TaskHandle TaskSetOut;

    staticc int first_time=1;
   
    SetWaitCursor(1);
   

    if (first_time)

    {
       DAQmxErrChk (DAQmxCreateTask("",&TaskSetOut));

       first_time;

    }

 

    DAQmxErrChk (DAQmxCreateAOVoltageChan (TaskSetOut, channel, "", 0, 10, DAQmx_Val_Volts, ""));
    DAQmxErrChk (DAQmxWriteAnalogF64 (TaskSetOut, 1, 1, 10.0, DAQmx_Val_GroupByChannel, ValArray, &written, NULL));
    DAQmxErrChk (DAQmxStartTask(TaskSetOut));
    DAQmxStopTask(TaskSetOut);

 

 

    if (finish_and_clear)

    {

        DAQmxClearTask(TaskSetOut);

    }
   

    Error:
    SetWaitCursor(0);
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
}

 

 

0 Kudos
Message 3 of 6
(3,388 Views)

Do NOT call the create channel, start task, or stop task each time. You could simply have one function where the task is created, one where you do the write, and one where you stop and clear. And yes, this would require you saving the task and passing it to the write and stop functions.

0 Kudos
Message 4 of 6
(3,380 Views)

thanks,

 

can i use write voltage twice, without soping and clearing?

0 Kudos
Message 5 of 6
(3,330 Views)

You can use it as many times as you want if you don't clear the task. If you stop it, you would need to start it again.

0 Kudos
Message 6 of 6
(3,322 Views)