Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

PCI 6602:How can I use the digital lines of the board and in the same time to generate pulse train using a counter?

Solved!
Go to solution

Hello!

 

My problem appeared when I tried to update my code from Traditional NI-DAQ Legacy to DAQmx.

I am using 2 counters (counter 5 and counter 7)  from PCI-6602, to generate pulse train, and also the Digital I/O lines of the port 0 (the lines form 0 to 7). What I do in my application is that I am starting to generate the pulse train on the output of the 2 counters, and after that I am playing with the state of the digital lines.

In traditional there was no problem using the counters and the digital lines in the same time, everything was going perfectly, but in DAQmx this is not possible.

 

What happens: I start to generate pulse train on the output of the counters,  no errors encountered, but when I try to modify the state of one line of the digital port the generation of the pulse train is stopped. This is happening when I start the task associated to the digital port.

 

My question is: it is possible to create a channel on the digital lines without altered the channels created for the counters?

 

Another thing what I manage to see using the  "Measurement & Automation Explorer" and Test panels for PCI-6602, basically is the same thing, I generate pulse train on the output of the counter 7 and try to start a task on the digital line, but I get one error :

 

"Error -200022 occurred at Test Panel
Possible Reason(s):
Measurements: Resource requested by this task has already been reserved by a different task.
Device: Dev4
Terminal: PFI8"


Instead if I use the counter 0 or counter 1 to generate pulse train I don't encounter the same problem.

 

Which resources are used by the counters 2 to 7 from the PCI-6602 board and the counters 0 and 1 do not use?

 

Thank in advance for any replies!

 

Ciprian

0 Kudos
Message 1 of 8
(5,871 Views)

You should be able to set channels 8-31 for digital or counter output individually (after checking in the 6602 manual).  I did receive an error in Mesurement and Automation Explorer the same as you did but did not when I ran a program that wrote a static voltage to a digital line (0-7) and use a counter output such as 5 or 7.  Measurement and Automtion Explorer must set up all the lines for digital or counter output and not be able to change them individually.  Do you have some code that you could attach (or screenshot)?  I attached the program (LV 8.6) I tested that writes a digital output on lines 0-7 and uses counter 5 to ouput a pulse train. 

 

 

Regards,
Jordan F
National Instruments
0 Kudos
Message 2 of 8
(5,844 Views)

Hello Jordan, thank you for your reply.

 

I am sorry but I can not see or run your example, I don't use LabView, I use Visual C++ for developing.

 

Here is the code for generating the pulse train:

 

GeneratePulseTrain(unsigned long ulCount1, unsigned long ulCount2)

{

    short nStatus = 0;
    

...................................................................................................................


    nStatus = DAQmxCreateTask("",&m_taskHandle);

 

    nStatus = DAQmxCreateCOPulseChanTicks (m_taskHandle, "Dev4/count5", "", NULL, DAQmx_Val_Low, 0.0, ulCount1,ulCount2);


............................................................................................................................
 

    if( bTriggerMode == true) // if hardware trigger is enabled
    {
        nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_ArmStartTrig_Type, DAQmx_Val_DigEdge);
        nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_DigEdge_ArmStartTrig_Edge, DAQmx_Val_Rising);
        nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_DigEdge_ArmStartTrig_Src,"Dev4/PFI17" );
    }

    //set the internal timebase
    nStatus = DAQmxSetCOCtrTimebaseSrc(m_taskHandle,"Dev4/count5","20MHzTimeBase" );
  
    nStatus = DAQmxStartTask(m_taskHandle);
    return nStatus;
}

 

And the code where I try to set the digital line:

 

SetChannelState(short nState)
{
    short nStatus = 0;
    uInt8 wrtBuf0[1]={0};
      
......................................................................

  
    nStatus = DAQmxCreateTask("",&m_taskHandle);
   
    // Configure line as output 
    nStatus = DAQmxCreateDOChan (m_taskHandle, "Dev4/port0/line0", "", DAQmx_Val_ChanPerLine);


    nStatus = DAQmxStartTask(m_taskHandle);
  
    wrtBuf0[0] = nState;
    nStatus =DAQmxWriteDigitalLines (m_taskHandle, 1, 0, 0, DAQmx_Val_GroupByScanNumber , wrtBuf0, NULL, NULL);

 

    nStatus = DAQmxWaitUntilTaskDone(m_taskHandle,10);

    nStatus = DAQmxStopTask(m_taskHandle);

    nStatus = DAQmxClearTask(m_taskHandle);


    m_taskHandle = 0;


    return nStatus;      
}

 

 

 

0 Kudos
Message 3 of 8
(5,832 Views)

Try running two different examples simultaneously, GenDigPulseTrain_Continuous and WriteDigChan, to see if you receive any errors or if this works.  That way we can eliminate your code from the issue and narrow it down to the hardware.  The examples can be found in:

 

C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples

 or

Programs>>National Instruments>>NI-DAQ>>Text-Based Code Support>>Visual C++ Examples

 

Let me know if you see any errors or have any unexpected behavior.

Regards,
Jordan F
National Instruments
0 Kudos
Message 4 of 8
(5,787 Views)

I have run the examples and I have discovered something.

If I start the task with digital channel before I start the pulse train generation, the application run without any problems.

If I start the pulse train generation before starting the task with digital out channel the pulse generation is stopped.

 

From my point of view this is not ok.

 

Do you have any idea why this is happening?

 

ciprian
0 Kudos
Message 5 of 8
(5,766 Views)
Solution
Accepted by topic author Reload

After doing some actual testing on this device I found that this is normal behavior for the 6602 board.  This is because when you start a digital task all 32 lines are configured for Digital I/O so it will override your counter operation.  The article linked below explains a little more about this.  You have to start the digital task before the counter task to use the functionality of both in your program. 

 

Counters 2 and Above Do Not Function Properly When Performing Digital I/O on a NI 6601 or 6602

http://digital.ni.com/public.nsf/allkb/43F71527765EEC3886256E93006CD00C?OpenDocument

Regards,
Jordan F
National Instruments
0 Kudos
Message 6 of 8
(5,741 Views)

Perhaps this is a normal behavior in DAQmx (or it is a small bug which has an workaround), but in Traditional this was not an issue.

 

ciprian

0 Kudos
Message 7 of 8
(5,735 Views)

Thank you very much Jordan for all your help.

Using all the information you gave me I managed to do the workaround and continue developing the application.

 

I wish you all the best!

 

ciprian

0 Kudos
Message 8 of 8
(5,733 Views)