Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

measure pulse width cont - failure in example? NI-DAQmx

Hello!

I tried the "PulseWidth-Buff-SampClk-Cont.c"-Example. I got the following error:

DAQmx Error: Invalid timing type for this channel.
Property: DAQmx_SampTimingType
You Have Requested: DAQmx_Val_SampClk
You Can Select: DAQmx_Val_Implicit, DAQmx_Val_OnDemand

Task Name: _unnamedTask<0>

Status Code: -200300



Here is the Example-Code:
-------------------------------------------------------
#include <stdio.h>
#include <NIDAQmx.h>

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

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

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateCIPulseWidthChan(taskHandle,"Dev1/ctr0","",0.000000100,0.838860750,DAQmx_Val_Seconds,DAQmx_Val_Rising,""));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI0",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
    //DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/dev1/PFI13",1.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
    //DAQmxErrChk (DAQmxCfgImplicitTiming(taskHandle,DAQmx_Val_ContSamps,1000));

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

    printf("Continuously reading. Press Ctrl+C to interrupt\n");
    while( 1 ) {
        /*********************************************/
        // DAQmx Read Code
        /*********************************************/
        DAQmxErrChk (DAQmxReadCounterF64(taskHandle,1000,20.0,data,1000,&read,0));

        printf("Acquired %d samples\n",read);
        fflush(stdout);
    }

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;
}



What could i do?

Thanks

Andreas

0 Kudos
Message 1 of 4
(4,334 Views)

As the errormessage says, you are using the wrong timing type. In the sourcecode you commented out the following line:

 //DAQmxErrChk (DAQmxCfgImplicitTiming(taskHandle,DAQmx_Val_ContSamps,1000));

Try removing the //, so that the line is executed.

0 Kudos
Message 2 of 4
(4,317 Views)
Hello Andre!

That did it! I commented the line out because it doesn't exist in the original example. I copied it from another code-example. Thought i still tried it this way. Know it works. But i'm not sure what i'm doing exactly. And: why do i need this line explicit. Is it recommendable to use the DAQmxCfgImplicitTiming(... always? Could you explain it to me? I'm a complete noob, sorry. 😕

Thanks anyway!
Andreas
0 Kudos
Message 3 of 4
(4,314 Views)

The help says this:

Sets only the number of samples to acquire or generate without specifying timing. Typically, you should use this function when the task does not require sample timing, such as tasks that use counters for buffered frequency measurement, buffered period measurement, or pulse train generation.

 

So this line is only needed for specific applications. The counter has no sampleclock, like the analog input or the analog output, so you can not use this, but have to use implicit timing instead.

Hope this helps!

André

 

0 Kudos
Message 4 of 4
(4,309 Views)