Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Using both counters on the cDAQ-9172

Hi,

 

I have 3 questions with regards to using counter timer channels from the cDAQ-9172 at the same time - and how counter channels may become hardware reserved.

 

(1) I am trying to use both counters of the cDAQ-9172 chassis. I have an NI-9401 in slot 5.

When I create a task with 1 counter input edge count channel, using either ctr0 or ctr1 by itself works fine.

However, when I try to use both counters at the same time I get an error that I cannot add both counter channels to the same task - so I created 2 separate tasks and started them sequenctially. However I get the following hardware reserved error when I try to start the 2nd channel. (I made sure to reset the chassis and the device before running the test).

 

DAQmx Error: Device cannot be configured for input or output because lines and/or terminals on this device are in use by another task or route. This operation requires temporarily reserving all lines and terminals for communication, which interferes with the other task or route. If possible, use DAQmx Control Task to reserve all tasks that use this device before committing any tasks that use this device. Otherwise, uncommit or unreserve the other task or disconnect the other route before attempting to configure the device for input or output.
Device: cDAQ1Mod5
Digital Port: 0
Lines: 0

Task Name: _unnamedTask<1>

Status Code: -201133

 

(2) I was able to run 2 edge count channels using the NI-9402 in slot 6 of the cDAQ-9172. However, I thought that since the NI-9402 has its own counter in addition to the 2 counters provided by the cDAQ-9172, that I should be able to use 3 counters at the same time, but I can only use 2 counters. When I try to add a 3rd counter 'ctr2', I get the following error:

 

DAQmx Error: Physical channel specified does not exist on this device.

Refer to the documentation for channels available on this device.
Task Name: _unnamedTask<1>

Status Code: -200170


I can also provide the C source code if needed.

I am using NIDAQmx driver version 9.2.1f0 with Windows XP.

 

(3) I was wondering if there is any inter-channel dependencies. For example, if I add a linear position channel, would that use up the same PFI terminals that another counter channel may be using?

 

Thanks,

 

Wael Hemdan

The MathWorks

0 Kudos
Message 1 of 9
(7,470 Views)

Hi Wael,

I will be brief.

1) did you create 1 or 2 tasks? You should use 2 different tasks for counter operations

2) when you create 2nd task, you need yo assure that you don't use the same PFI lines as the other task already running. This mean that if you say PFI0 will be counter 1 output, then you can't use it as counter 2 output.

3) to give us more idea about what you try to do, could you give us code which configures the counters? then we can see clearer what PFI you use in each task

regards,

stefo

Certified-LabVIEW-Developer_rgb.jpg

0 Kudos
Message 2 of 9
(7,466 Views)

Hi,

 

I created a separate task for each counter channel.

 

I did not write any special code to program the PFI channels. When I only have 1 channel added at any one time it works with counter input edge count channel 0 defaulting to PFI terminal 0, and counter input edge count channel 1 defaulting to PFI terminal 4. But if I want to create and run the 2 tasks at the same time, I get hardware reserved error even though I thought the PFI terminals should not be conflicting.

 

Note: The error does not happen in simulation, it only happens when running with actual hardware.

 

Please find attached the source code.

 

Thanks,

 

Wael Hemdan

The MathWorks

0 Kudos
Message 3 of 9
(7,463 Views)

Hi Wael,

 

The NI 9401 can't change its line direction (from input to output or vice versa) while another DAQmx task is running on the same module. If you want to run two tasks on the NI 9401 at the same time, you should use DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Reserve) on both tasks before you call DAQmxStartTask() on either task. The NI 9402 does not have this restriction.

 

Also, the NI 9402 doesn't have any counters built-in. It uses the counters on the chassis, just like the NI 9401.

 

Brad

---
Brad Keryan
NI R&D
Message 4 of 9
(7,459 Views)

Hi Brad,

 

Thanks for the quick reply.

 

I tried calling DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Reserve) on both tasks before calling DAQmxStartTask() but I still get Status Code: -201133.

 

Here's what the new code looks like:

 

#include <stdio.h>
#include <NIDAQmx.h>
#include <Windows.h> // Sleep

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

int main(void)
{
    int         error=0;
    TaskHandle  taskHandle1=0;
    TaskHandle  taskHandle2=0;
    uInt32      data1 = 0;
    uInt32      data2 = 0;
    char        errBuff[2048]={'\0'};

    DAQmxErrChk (DAQmxCreateTask("",&taskHandle1));
    DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle1,"cdaq1mod5/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));

    DAQmxErrChk (DAQmxCreateTask("",&taskHandle2));
    DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle2,"cdaq1mod5/ctr1","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));
    
    DAQmxErrChk (DAQmxTaskControl(taskHandle1, DAQmx_Val_Task_Reserve));
    DAQmxErrChk (DAQmxTaskControl(taskHandle2, DAQmx_Val_Task_Reserve));

    DAQmxErrChk (DAQmxStartTask(taskHandle1));
    DAQmxErrChk (DAQmxStartTask(taskHandle2));
    
    printf("Continuously polling. Press Ctrl+C to interrupt\n");
    while( 1 ) {
        DAQmxErrChk (DAQmxReadCounterScalarU32(taskHandle1,10.0,&data1,NULL));
        DAQmxErrChk (DAQmxReadCounterScalarU32(taskHandle2,10.0,&data2,NULL));

        Sleep(100);
        printf("\rctr0: %d, ctr1: %d",data1, data2);
        fflush(stdout);
    }

Error:
    puts("");
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    
    DAQmxStopTask(taskHandle1);
    DAQmxClearTask(taskHandle1);

    DAQmxStopTask(taskHandle2);
    DAQmxClearTask(taskHandle2);

    if( DAQmxFailed(error) )
        printf("DAQmx Error: %s\n",errBuff);
    printf("End of program, press Enter key to quit\n");
    getchar();
    return 0;
}

 

 

--> DAQmx Error: Device cannot be configured for input or output because lines and/or terminals on this device are in use by another task or route. This operation requires temporarily reserving all lines and terminals for communication, which interferes with the other task or route. If possible, use DAQmx Control Task to reserve all tasks that use this device before committing any tasks that use this device. Otherwise, uncommit or unreserve
 the other task or disconnect the other route before attempting to configure the device for input or output.
Device: cDAQ1Mod5
Digital Port: 0
Lines: 0

Task Name: _unnamedTask<1>
Status Code: -201133

 

 

0 Kudos
Message 5 of 9
(7,433 Views)

Hi whemdan,

 

I was able to run your code without getting the error. Are you running any other commands to the 9401 while running this application? This could cause the error to appear.

Steven K.
National Instruments
Software Engineer
0 Kudos
Message 6 of 9
(7,382 Views)

Hi,

 

Thank you for the quick reply.

 

The problem is not reproducible with simulated hardware, and specifically happens with the cDAQ-9172 (and not with the cDAQ-9178). I am not sure what else might be different between my run and your run. I did make sure the device is reset before running my code - and the only thing running is the attached code.

 

I'm using NIDAQmx driver version 9.2.1f0.

 

Did you reproduce the problem without the task reserved fix suggested by Mr. Brad K, then see it go away by adding code to manually reserve the task.

(I'm getting the problem with and without reserving the task)...

 

Thanks,

 

Wael Hemdan

The MathWorks

0 Kudos
Message 7 of 9
(7,365 Views)

Hi whemdan,

 

I ran your code on an actual 9172 with a 9401 on slot 5. When I commented out the reserving code, I received the same error that you received. With those lines of code uncommented, the application did not throw an error. I am however using NI-DAQmx 9.2.3. Would you be able to try your application on another computer? Also try updating to the latest version of DAQmx. It is linked here.

Steven K.
National Instruments
Software Engineer
0 Kudos
Message 8 of 9
(7,353 Views)

Thanks for the post Brad,

Im using LV2013 and was running with the same problem.

 

please keep using the forum!

 

regards,

 

 

0 Kudos
Message 9 of 9
(6,592 Views)