Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure not default PFIs as inputs for aux and gate in counter 0?

Solved!
Go to solution

Hi, NI community,

 

 

I am having problems on a DAQ 6212 trying to use PFI12  and PFI13 as the Aux and Gate input signals for the counter 0.

 

 

My application should simply measure the time difference between the two raising edges of two signals attached to PFI12 and PFI13.

 

The DAQ returns me the following error message when I run my program.

 

***************************************************************************

DAQmx Error: Specified route cannot be satisfied, because it requires resources
that are currently in use by another route.
Property: DAQmx_CI_TwoEdgeSep_FirstTerm
Property: DAQmx_CI_TwoEdgeSep_FirstEdge
Source Device: Dev1
Source Terminal: PFI10

Required Resources in Use by
Source Device: Dev1
Source Terminal: PFI12
Destination Device: Dev1
Destination Terminal: Ctr0Aux

Task Name: T3

Status Code: -89137

***************************************************************************

 

 

My code looks like this. (Please note: since the world of NI DAQ is totally new to me, my code comments could be wrong):

 

 

 

************************************************************************

 

        #define DAQmxErrChkTest(functionCall) if( DAQmxFailed(gErrorTest=(functionCall)) ) goto Error; else

 

 

        int32 gErrorTest;
        float64 f64readDelay;
        TaskHandle taskHandleT3;

 

        // Create a task

        DAQmxErrChkTest( DAQmxCreateTask("T3",&taskHandleT3) );

        // Connect PFI12 to the conter 0 start input (correct??)

       DAQmxErrChkTest (DAQmxConnectTerms ("/dev1/PFI12", "/dev1/Ctr0Aux", DAQmx_Val_DoNotInvertPolarity));


       // Connect PFI13 to the conter 0 stop input (correct??)

       DAQmxErrChkTest (DAQmxConnectTerms ("/dev1/PFI13", "/dev1/Ctr0Gate", DAQmx_Val_DoNotInvertPolarity));


        // Associate a two edge separation channels measurement with task3. Configuring the edge measurement parameters.

DAQmxErrChkTest (DAQmxCreateCITwoEdgeSepChan(taskHandleT3,

"/dev1/ctr0",

"",

0.001,

5.0,

                                                                                        DAQmx_Val_Seconds,

DAQmx_Val_Rising,

DAQmx_Val_Rising,

""));
  

       // Start reading the edges

       DAQmxErrChkTest (DAQmxStartTask(taskHandleT3));


       // Read the measurement

       DAQmxErrChkTest (DAQmxReadCounterScalarF64(taskHandleT3,10.0,&f64readDelay,0));
        printf("Measured Pulse Width: %.9f sec\n",f64readDelay);

Error:
    if( DAQmxFailed(gErrorTest) )
    {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        printf("DAQmx Error: %s\n",errBuff);
    }

    DAQmxStopTask(taskHandleT3);
    DAQmxClearTask(taskHandleT3);


    printf("End of program, press Enter key to quit\n");
    getchar();
 ************************************************************************

 

I have been experimenting with the  DAQmxSetCITwoEdgeSepFirstTerm() and DAQmxSetCITwoEdgeSepSecondTerm().

I believe they configure the parameter in charge of the edge channels. 

I got similar error messages.

 

On the default counter 0 PFI9 and PFI10 inputs I have succeeded to measure the time difference between edges.

However, I need to perform the measurement on the indicated PFIs.

 

 

Could you please copy-modify-paste my program, so that I can see explicitly what I did wrong?

 

I appreciate very much your help!

 

Thanks in advance.

 

 

 

 

 

 


 

 

0 Kudos
Message 1 of 3
(3,926 Views)
Solution
Accepted by topic author mkus

Hi NI community,

 

 

I got myself the answer for the described problems.

 

Maybe this code can be useful to you

 

 

The corrected (in blue) code looks as follows:

 

        #define DAQmxErrChkTest(functionCall) if( DAQmxFailed(gErrorTest=(functionCall)) ) goto Error; else

 

 

        int32              gErrorTest;
        float64           f64readDelay;
        TaskHandle     taskHandleT3;

 

        // Create a task

        DAQmxErrChkTest( DAQmxCreateTask("T3",&taskHandleT3) );

        // This is not needed

       //  DAQmxErrChkTest (DAQmxConnectTerms ("/dev1/PFI12", "/dev1/Ctr0Aux", DAQmx_Val_DoNotInvertPolarity));


       // This is not needed

      // DAQmxErrChkTest (DAQmxConnectTerms ("/dev1/PFI13", "/dev1/Ctr0Gate", DAQmx_Val_DoNotInvertPolarity));


        // Associate a two edge separation channels measurement with task3. Configuring the edge measurement parameters.

DAQmxErrChkTest (DAQmxCreateCITwoEdgeSepChan(taskHandleT3,

"/dev1/ctr0",

"",

0.001,

5.0,

                                                                                        DAQmx_Val_Seconds,

DAQmx_Val_Rising,

DAQmx_Val_Rising,

""));
 
  

        // Erase the old counter input settings before setting new ones.

        // Since the 3rd parameter in DAQmxCreateCITwoEdgeSepChan is "" (no name for the channel), here the 2nd parameter must be also "" (no name)
        DAQmxErrChkTest (DAQmxResetCITwoEdgeSepFirstEdge(taskHandleT3, ""));
        DAQmxErrChkTest (DAQmxResetCITwoEdgeSepFirstTerm(taskHandleT3, ""));
        DAQmxErrChkTest (DAQmxResetCITwoEdgeSepSecondEdge(taskHandleT3, ""));
        DAQmxErrChkTest (DAQmxResetCITwoEdgeSepSecondTerm(taskHandleT3, ""));
       
        // Setting the new PFI as counter inputs.
        // Since the 3rd parameter in DAQmxCreateCITwoEdgeSepChan is "" (no name for the channel), here the 2nd parameter must be also "" (no name)
        DAQmxErrChkTest (DAQmxSetCITwoEdgeSepFirstEdge(taskHandleT3, "", DAQmx_Val_Rising));
        DAQmxErrChkTest (DAQmxSetCITwoEdgeSepFirstTerm(taskHandleT3, "", Counter0NewAux ));
        DAQmxErrChkTest (DAQmxSetCITwoEdgeSepSecondEdge(taskHandleT3, "", DAQmx_Val_Rising));
        DAQmxErrChkTest (DAQmxSetCITwoEdgeSepSecondTerm(taskHandleT3, "", Counter0NewGate));

        // This also set the new counter inputs
        //DAQmxSetChanAttribute( taskHandleT3, "", DAQmx_CI_TwoEdgeSep_FirstTerm, "/Dev1/PFI14", 0 );
        //DAQmxSetChanAttribute( taskHandleT3, "", DAQmx_CI_TwoEdgeSep_FirstEdge, DAQmx_Val_Falling, 0);
        //DAQmxSetChanAttribute( taskHandleT3, "", DAQmx_CI_TwoEdgeSep_SecondTerm, "/Dev1/PFI15", 0 );
        //DAQmxSetChanAttribute( taskHandleT3, "", DAQmx_CI_TwoEdgeSep_SecondEdge, DAQmx_Val_Falling, 0);

        // Start reading the edges

       DAQmxErrChkTest (DAQmxStartTask(taskHandleT3));


       // Read the measurement

       DAQmxErrChkTest (DAQmxReadCounterScalarF64(taskHandleT3,10.0,&f64readDelay,0));
        printf("Measured Pulse Width: %.9f sec\n",f64readDelay);

Error:
    if( DAQmxFailed(gErrorTest) )
    {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        printf("DAQmx Error: %s\n",errBuff);
    }

    DAQmxStopTask(taskHandleT3);
    DAQmxClearTask(taskHandleT3);


    printf("End of program, press Enter key to quit\n");
    getchar();
 ************************************************************************

 

The "gurus" in this forum may say if this code is correct or has some problem.

As stated before, I am an absolute NI DAQmx newbie.

However, measurements with the DAQmx HW were succesful.

 

 

For the NI development team I have one request:

please, make more C code examples related re routing of PFI's.

It is so difficult to find how this is done.

It has taken me days of forum research to run this simple program that changes counter0 default inputs. And it seems I am not the only one out there having the same problems.

 

The DAQmxGetCITwoEdgeSepSecondEdge()

DAQmxResetCITwoEdgeSepSecondEdge()

DAQmxsetCITwoEdgeSepSecondEdge()

and other of the like functions are documented so generally in the NI-DAQmx C Reference Help, that it is quite hard to understand when and how to use these functions correctly.

 

Anyhow, once I got it running... everything looks beautiful. 🙂

 

 

Greetings,

 

 

0 Kudos
Message 2 of 3
(3,908 Views)

I forgot to copy in the former code the definitions of Counter0NewAux and Counter0NewGate

 

They are:

 

 

// To configure the AUX input of counter 0 to be PFI11 

const char Counter0NewAux[]="/dev1/PFI11";   //

 

// To configure the AUX input of counter 0 to be PFI13 

const char Counter0NewGate[]="/dev1/PFI13";

 


The DAQmx box is in my PC the device 1, therefore the dev1 in the declaration. In your PC/laptop it might be another number.

 

 

Greetings.

0 Kudos
Message 3 of 3
(3,906 Views)