Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to go over these 10ms of latency ?

Hi all,

 

I am using a PCIe 6341 board and coding under visual c++ 2010. I need to do an analog acquisition of 10 points at 500kHz every 200µs. In order to be fast, I permit the card to overwrite the buffer and take the last 10 points written in the buffer. Unfortunately, the time to take the data is of 10ms which is too slow for me who need to read the data every 0.2ms. What do I do wrong ?

 

My code is :

 

#include "stdio.h"
#include "NIDAQmx.h"
#include <time.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

#define nb_point 10
#define frequence 500000

int main(void)
{
    int32       error=0;
    TaskHandle  taskHandle=0;
    int32       read;
    float64     data[nb_point];
    char        errBuff[2048]={'\0'};
    int64        samplesToAcquire=100000 ;
    int            cpt ;

    // essai pour mesure du temps
    int
        temps_initial,
        temps_final;
    float
        temps_cpu;




    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/

    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",frequence,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesToAcquire));
    DAQmxErrChk (DAQmxSetReadRelativeTo(taskHandle,DAQmx_Val_MostRecentSamp));
    DAQmxErrChk (DAQmxSetReadOffset(taskHandle,nb_point));

    /***********************/
    // debut de mesure avant le lancement de la tache
    /***********************/
    printf("Parti?\n");
    getchar();


    /*********************************************/
    // DAQmx Start Code
    /*********************************************/
    DAQmxErrChk (DAQmxStartTask(taskHandle));

    /*********************************************/
    // DAQmx Read Code
    /*********************************************/
    for ( cpt = 0 ; cpt <11 ; cpt++ )
    {
        temps_initial = clock ();
        DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,nb_point,10.0,DAQmx_Val_GroupByChannel,data,nb_point,&read,NULL));
        /***********************/
        // fin de mesure du temps
        /***********************/
        temps_final = clock ();
        temps_cpu = ((float)temps_final - temps_initial)/CLOCKS_PER_SEC;
        printf("Temps d execution : %f\n",temps_cpu);
        printf("Acquired %d points\n",read);
    }


Error:
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 )  {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmx Error: %s\n",errBuff);
    printf("End of program, press Enter key to quit\n");
    getchar();
    return 0;
}

Thanks a lot for your help

 

0 Kudos
Message 1 of 3
(5,870 Views)

The PC cannot time things sub millisecond. It takes milliseconds for user code to get called when data is available. This means there is no software option to do exactly what you want. There are other options though.

 

1) Just record at full speed and discard the unneeded samples. I'm not sure if your setup can handle this throughput but it is the simplest option.

 

2) Setup a 200us period clock and send it to the trigger input on the card. I don't know if you can do this completely on the one card or not. Maybe you can have two simultaneous tasks running, one the clock generator and the other the analog input? You can setup your analog input task to record 10 samples on the start trigger. This has the benefit of you keeping all the samples without worrying about overwriting.

 

As a general rule, once you are doing anything faster than 100Hz, PC software timing doesn't work. The 10ms is the PC clock update period and thread scheduler interrupt period. You could do things faster by running at a high priority and busy waiting, but that is not a nice way of doing things.

0 Kudos
Message 2 of 3
(5,791 Views)

Thanks a lot for the answer !

 

 

0 Kudos
Message 3 of 3
(5,785 Views)