From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Using multiple PFI inputs for a single trigger

Hi,

 

I'm currently using an X-series PCIe-6323 multifunction card running on a Windows 7 PC. For this problem I'm programming in visual c++. I want to trigger an analogue output based on either of two digital inputs (which I must keep separate from each other) but when I try and specify two PFI channels for the start trigger, I get an error.

 

As al alternative, I tried setting up two separate analogue output tasks, each generating the same signal but delivered to different output channels (which I can then combine) and each with a different PFI channel specified as the start trigger. However, this also generated an error (perhaps because you can't have two AO tasks running at once even if they are controlling different AO channels).

 

Can anyone suggest a workaround?

 

 

0 Kudos
Message 1 of 9
(4,895 Views)

Hello KNY, 

Have you had a look at the published examples for this? The location of these can vary depending on your computer environment. 

http://digital.ni.com/public.nsf/allkb/E0D14AB889CBF8E5862572B8006B22D3

In particular I hope that the Analog Out -> Generate Voltage example code can be of some use to you. 

Through these I believe it is possible to define two output tasks that generate the same signal (and hence implement your alternative solution). 

Let me know if this is able to help at all. 

Kind regards, 
Matthew 

0 Kudos
Message 2 of 9
(4,832 Views)

Hi Matthew,

 

Thanks for your post. I've just taken a look at the examples, but I can't see any that launch more than one analogue task at the same time.

 

Just to clarify, I'm not having any problem setting up a single AO task and triggering that with a digital input to a PFI line. It's specifically trying to do this with two tasks at once that returns an error indicating a conflict between the tasks. Hence I suspect that this may not be possible with my card.

 

I could go to a software loop, but I'd rather not have the additional latency to initiate the analogue output. Hence at this point I've asked my lab technician to build me a logical AND gate in the external electronics. Still, I'd be interested to hear of a workaround if there is one, for future reference.

 

Best,

 

Kielan.

0 Kudos
Message 3 of 9
(4,810 Views)

Hi Kielan, 

Thank you for clarifying your question further. I understand that you are trying to trigger two AO tasks using a single digital input on the PFI line. 

What was the exact error message you were getting when trying to do this? With two analog output channels the PCIe-6323 supports rates of upto 840 kS/s per channel. What frequency is the signal you are trying to output, and also what mode? For reference the supported waveform modes are:

Non-periodic waveform, periodic waveform regeneration mode from onboard FIFO, periodic waveform regeneration from host buffer including dynamic update

I'm glad to hear that you have found a workaround that works for your application, but I will take a further look into triggering two AO tasks and let you know if I can find anything. 

Kind regards, 

Matthew 

0 Kudos
Message 4 of 9
(4,772 Views)

Hi Matthew,

 

Thanks for your post, but please don't break your back over this if there is not an obvious answer!

 

I'm outputting on two channels at 44.1 KHz (for each AO task). I'm not too sure about the mode; presumably whatever is default for my card as I don't think I have specified this in the code (I can look into this if you think it is important).

 

The error message is:

 

Specified route cannot be satisfied, because it requires resources that are currenlty in use by another route.

 

Property: DAQmx_DigEdge_StartTrig_Src
Property: DAQmx_DigEdge_StartTrig_Edge
Source Device: Dev1
Source Terminal: PFI12

 

Required Resources in Use by
Task Name: IndexTapper
Source Device: Dev1
Source Terminal: PFI10
Destination Device: Dev1
Destimation Terminal: ao/StartTrigger

 

Task Name: MiddleTapper

 

status code: -89137

 

Key aspects fo the c++ code follow. These lines set up the names of the tasks:

 

CString AuditoryTaskChannel = "Dev";   
  _itoa_s(m_Timer.m_Card,String,10);
  AuditoryTaskChannel += String; 
  AuditoryTaskChannel += "/ao0:1"; //for solonoid!

 

  CString TriggerTerminal = "/Dev";
  TriggerTerminal += String;  
  TriggerTerminal += "/PFI0";

 

  CString AuditoryTaskChannel2 = "Dev"; 
  AuditoryTaskChannel2 += String;  
  AuditoryTaskChannel2 += "/ao2:3"; //for solonoid!

 

  CString TriggerTerminal2 = "/Dev";
  TriggerTerminal2 += String;  
  TriggerTerminal2 += "/PFI12";

 

And these set up the output tasks based on those names (the actual waveform has been previously stored in the variable TwoChannelLongOutputBuffer):

 

 

//prepare stimulus presentation
  AuditoryTaskHandle=0;
     
  ReturnValue = DAQmxCreateTask("IndexTapper",&AuditoryTaskHandle); //create a DAQ task
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info
  
  ReturnValue = DAQmxCreateAOVoltageChan(AuditoryTaskHandle,AuditoryTaskChannel,"",-10.0,10.0,DAQmx_Val_Volts,NULL);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info
    
  ReturnValue = DAQmxCfgSampClkTiming(AuditoryTaskHandle,"OnboardClock",OutputRate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,SamplesToWrite);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info

 

  ReturnValue = DAQmxCfgDigEdgeStartTrig (AuditoryTaskHandle,TriggerTerminal, DAQmx_Val_Falling);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info
  
  ReturnValue = DAQmxWriteAnalogF64(AuditoryTaskHandle,SamplesToWrite,0,10.0,DAQmx_Val_GroupByChannel,TwoChannelLongOutputBuffer,&Written,NULL);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info

  if (Written != SamplesToWrite)//OutputLengthLong) //not all samples were written
  {   
   TestString = "Samples written: ";
   _itoa_s(Written,String,10);
   TestString += String;
   AfxMessageBox(TestString,MB_OK);
  }

  ////prepare stimulus presentation
  TaskHandle AuditoryTask2Handle=2;
     
  ReturnValue = DAQmxCreateTask("MiddleTapper",&AuditoryTask2Handle); //create a DAQ task
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info
  
  ReturnValue = DAQmxCreateAOVoltageChan(AuditoryTask2Handle,AuditoryTaskChannel2,"",-10.0,10.0,DAQmx_Val_Volts,NULL);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info
    
  ReturnValue = DAQmxCfgSampClkTiming(AuditoryTask2Handle,"OnboardClock",OutputRate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,SamplesToWrite);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info

 

  ReturnValue = DAQmxCfgDigEdgeStartTrig (AuditoryTask2Handle,TriggerTerminal2, DAQmx_Val_Falling);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info
  
  ReturnValue = DAQmxWriteAnalogF64(AuditoryTask2Handle,SamplesToWrite,0,10.0,DAQmx_Val_GroupByChannel,TwoChannelLongOutputBuffer2,&Written,NULL);
  if (ReturnValue != 0)
   DAQError(); //this is a function I wrote to return error info

  if (Written != SamplesToWrite)//OutputLengthLong) //not all samples were written
  {   
   TestString = "Samples written: ";
   _itoa_s(Written,String,10);
   TestString += String;
   AfxMessageBox(TestString,MB_OK);
  }

 

Best,

 

Kielan.

0 Kudos
Message 5 of 9
(4,762 Views)

Hi Kielan, 

I've been having a look at the code that you attached and I believe that it is not possible to trigger two AO tasks in this way. As the error status (and we have discussed previously) it looks like the terminal is still in use by the first task when the second one goes to access it. To clarify my understandinf on what the intention of this code is I have some questions:

  • From what I can see, you are defining two separate tasks (AuditoryTaskchannel and AuditoryTaskchannel2) and each of these is tied to a separate trigger (PFI0 and PFI12 respectively). My initial understanding of this question was that you are trying to trigger two AO tasks using the same PFI line. Is this code not defining each task to a separate trigger line? Is this code to prove that even when using a separete trigger there is still a problem? The error regarding the resource being in use even though you have defined a different PFI line is strange indeed. 

  • Since it appears that the second task is unable to run because the required resources from the first task are still in use, have you considered using DAQmxClearTask to release the resources? 

    http://zone.ni.com/reference/en-XX/help/370471W-01/daqmxcfunc/daqmxcleartask/

  • This is possibly a stupid question, but would it be possible in incorpirate the outputs you need into a single task?

  • Finally, because you are looking at starting two tasks at the same time I had a look at some information related to parallelism. How this would be done in LabVIEW and C (multithreading) is detailed below:

    http://www.ni.com/white-paper/14556/en/
    https://msdn.microsoft.com/en-us/library/esszf9hw.aspx

Let me know your thoughts on this. 

Kind regards, 
Matt

 

0 Kudos
Message 6 of 9
(4,683 Views)

Hi Matt,

 

Setting up two different tasks was an attempt at a workaround. First I tried simply specifying two different PFI lines as triggers on a single task, but that throws a similar error stating that you can't specify more than a single trigger line. Hence it didn't appear possible to set this up as a single task, and I moved to plan B.

 

The plan B solution needs both tasks active (as either one must be triggered by an input) so I don't think clearing the first task is feasible. To be honest, I've pretty much come to the conclusion that this is just not possible, at least with my card. I suspect that this needs an NI engineer to get a definitive answer, but many thanks for your various suggestions.

 

Thanks also for the suggestions on parallel threads, I'll give those a read.

 

Best,

 

Kielan.

0 Kudos
Message 7 of 9
(4,680 Views)

Do not see the way how it is possible using daqmx, there is no OR function =(

Is it possible to combine 2 input trigger signals into one with hardware OR? It seems using 2 diodes will work:

2 diode OR.png

 

0 Kudos
Message 8 of 9
(4,657 Views)

Hi Alexander,

 

In fact, that is what I have ended up doing (or rather it is what my departmental technician has ended up doing for me, as I'm pretty clueless about electronics!) He bought a Quad 2-Input AND Gate for about £1 and wired the digital buttons I need though that. Bit of a faff, but works fine.

 

Best,

 

Kielan.

0 Kudos
Message 9 of 9
(4,641 Views)