Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

Programming real-time control in C with the USB-6009 board

Dear all,


I am trying to write a program in C (WinXP, MS Visual C++ 6.0) that uses a USB-6009 board to perform

real-time control, that is, each time the internal clock of the board ticks I need to execute the

following operations:

Step 1: read the values from 1 or more AD converters,

Step 2: perform some calculations with these values,

Step 3: then write some values to1 or more DA converters.

Step 4: wait until the next timer tick and go back to step 1.


I have already studied the documentation of the board and I have a working program.

The problem is, even if I just want to write to the DA the value that I get from the AD, there is a delay larger

than one sampling period between these operations. I am using an osciloscope to measure this delay.


My current program is as follows:

1) create and configure the tasks (AD and DA conversions, 1 input and 1 output):

    DAQmxErrChk (DAQmxCreateTask("",&Tarefa_Entrada));
    DAQmxErrChk (DAQmxCreateTask("",&Tarefa_Saida1));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(Tarefa_Entrada,Canal_Entrada,"", Modo_Aquisicao, Tensao_Min_PE, Tensao_Max_PE, DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxCreateAOVoltageChan(Tarefa_Saida1,Canal_Saida1,"", Tensao_Min_PS, Tensao_Max_PS, DAQmx_Val_Volts,""));

2) create the clock:
    DAQmxErrChk (DAQmxCfgSampClkTiming(Tarefa_Entrada,"",Amostras, DAQmx_Val_Rising,DAQmx_Val_ContSamps, (int64)Buffer));

3) start the tasks:

    DAQmxErrChk (DAQmxStartTask(Tarefa_Entrada));
    DAQmxErrChk (DAQmxStartTask(Tarefa_Saida1));

4) execute the control loop:

    printf("Starting the control loop ...\n\n");
        DAQmxErrChk (DAQmxReadAnalogF64(Tarefa_Entrada, 1, Timeout, DAQmx_Val_GroupByScanNumber, leitura, 2, &num_leit, NULL));
       /* CALCULATIONS*/

        DAQmxErrChk (DAQmxWriteAnalogScalarF64(Tarefa_Saida1,1,Timeout,saida,NULL));
    }while(kbhit()==0); //Loop é interrompido quando alguma tecla é pressionada


What is wrong with this program? How I should modify it?


Many thanks for any help.


Cairo L. Nascimento Jr. and Jeeves L. dos Santos

ITA - Brazi,



0 Kudos
Message 1 of 2

Dear Cairo and Jeeves,


This USB-6009 take a longer time because it´s not used for real-time applications. This board takes the signal from AD and send it through DA, but the calculations aren´t made by the board.


National Instruments has products for applications that requests determinisms and real-time processor.


Refer the follow link for more information about Real-Time, but one important point to consider is how fast your application is.


 Jailton – NIB – SR 1246123
0 Kudos
Message 2 of 2