Real-Time Measurement and Control

cancel
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");
    do{
        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

 

Perhaps I have to associate the clock with the DA converter as well. I have tried to do that but I get a compiler error.

 

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

 

Many thanks for any help.

 

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

ITA - Brazi

cairo@ita.br, jeeves@ita.br

 

0 Kudos
Message 1 of 2
(1,868 Views)
0 Kudos
Message 2 of 2
(1,833 Views)