Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting analog output update events using counters in text-based NIDAQmx

I have a time analog output task, and I would like to be able to count the number of output updates so that I can send a particular digital signal high immediately after the last update.  In traditional NIDAQ, I have found that I need to use two counters to accomplish this task.

 

In traditional NIDAQ, I wired the ao UPDATE signal to CTR0 input, and the CTR0 output, which is set up to send a pulse on reaching TC, to the input of CTR1.  In my working traditional NIDAQ code, I routed the signals using SELECT_SIGNAL.  My translation of this code into NIDAQmx is given below, but I think the routing part is incorrect, i.e., I need to know how to wire the UPDATE output to the CTR0 input, and the CTR0 output to the CTR1 input.  I would also like to know if it is possible to reset the count of each counter to 0 without stopping and restarting the task.

 

Thanks in advance for your help!

 

(The traditional nidaq code are the statements that are commented out that begin with status=)

 

procedure Set_timers;
 var
     CTR0Channel,
     CTR1Channel : PChar;
     TriggerString,
     TerminalString :smileytongue:Char;

  begin
     //General purpose counter 0
     //This counter is used to count the number of update clicks from the dacs
     //First create a task handle
     status:=DAQmxCreateTask('', @CTR0TaskHandle);

    //Next create a CTR channel to count edges, setting the initial count to 0
    StrPCopy(CTR0Channel, BoardIdentifier+'/ctr0');
    status:=DAQmxCreateCICountEdgesChan(CTR0TaskHandle,
                                                                  CTR0Channel, //Counter number
                                                                  '', //default virtual name to assign
                                                                  DAQmx_Val_Falling, //count on falling edge
                                                                  0, //initial count
                                                                  DAQmx_Val_CountDirection1_CountUp); // count direction

 

   //Reset the counter
   //Not sure if the next line is already taken care of above
   // status:=GPCTR_Control(deviceNumber, ND_COUNTER_0, ND_RESET);

   //Application is simple event counting ************ ALREADY DONE ABOVE !!
   // status:=GPCTR_Set_Application(deviceNumber, ND_COUNTER_0, ND_SIMPLE_EVENT_CNT);

   //Set the initial count to 0 ************ ALREADY DONE ABOVE !!
   // status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_0, ND_INITIAL_COUNT, 0);


   //Use the UPDATE* signal from the dacs on the PFI_5 pin
   StrPCopy(TriggerString,'/'+BoardIdentifier+'/ao/SampleClock'); //may want to change this to PFI5 
   StrPCopy(TerminalString, '/'+BoardIdentifier+'Ctr0Source');
   status:=DAQmxConnectTerms(TriggerString, TerminalString, DAQmx_Val_DoNotInvertPolarity);

 

   //the lines abopve replaced the lines below
   //status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_0, ND_SOURCE,ND_PFI_5);

   //ALREADY TAKEN CARE OF ABOVE
   // status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_0, ND_SOURCE_POLARITY, ND_HIGH_TO_LOW);

 

  //Output pulses on reaching TC
  status:=DAQmxSetExportedCtrOutEventOutputBehavior(CTR0TaskHandle,DAQmx_Val_ExportActions2_Pulse);

 

   //line above replaced the line below
  // status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_0, ND_OUTPUT_MODE, ND_PULSE);

  //Arm the counter, ready to start when the waveform output starts
  //Will do this at the end for both counters
  // status:=GPCTR_Control(deviceNumber, ND_COUNTER_0, ND_PROGRAM);


  {counter number 1. This counter is hooked up to counter 0, and it counts
  how many times the other counter has turned over}

  //First create a task handle
  status:=DAQmxCreateTask('', @CTR1TaskHandle);

  StrPCopy(CTR1Channel, BoardIdentifier+'/ctr1');
  status:=DAQmxCreateCICountEdgesChan(CTR1TaskHandle,
                                                                CTR1Channel, //Counter number
                                                                 '', //default virtual name to assign
                                                                DAQmx_Val_Rising, //count on falling edge
                                                                0, //initial count
                                                                DAQmx_Val_CountDirection1_CountUp); // count direction

  //Reset the counter
  // status:=GPCTR_Control(deviceNumber, ND_COUNTER_1, ND_RESET);

  //Application is simple event counting
  // status:=GPCTR_Set_Application(deviceNumber, ND_COUNTER_1, ND_SIMPLE_EVENT_CNT);

  //Set the initial count to 0
  // status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_1, ND_INITIAL_COUNT, 0);


  //Use TC output of the first counter
  StrPCopy(TriggerString,'/'+BoardIdentifier+'Ctr0Out'); //may want to change this to PFI5
  StrPCopy(TerminalString, '/'+BoardIdentifier+'Ctr1Source');
  status:=DAQmxConnectTerms(TriggerString, TerminalString, DAQmx_Val_DoNotInvertPolarity);
  //The above lines replaced the line below
  // status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_1, ND_SOURCE, ND_OTHER_GPCTR_TC);

  //Line below is taken care of above by DAQmx_Val_Rising
  // status:=GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_1, ND_SOURCE_POLARITY, ND_LOW_TO_HIGH);

  //Arm the counter, ready to start when the waveform output starts
  // status:=GPCTR_Control(deviceNumber, ND_COUNTER_1, ND_PROGRAM);

  //Start both counter tasks
  status:=DAQmxStartTask(CTR0TaskHandle);
  status:=DAQmxStartTask(CTR1TaskHandle);
  end;

0 Kudos
Message 1 of 4
(3,332 Views)

Hi Shiva,

 

I'm looking into how to perform gain this functionality in DAQmx.  Can you tell me what the model number is for the  DAQ hardware you are using?  Thanks!

 

 

Josh B
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,313 Views)

I'm currently programming with a NI 6251, but I have successfully used this technique using traditional NIDAQ with a NI 6052E card (which are the commented out traditional NIDAQ commands).  I am pretty sure I can use the technique; the question really is how to connect the UPDATE signal from the concurrently running ao task to CTR0 SOURCE, and how to connect the TC output from CTR0 (CTR0InternalOutput ?) to the CTR1 SOURCE input.  This would create a cascaded edge counter.  I can send you my working traditional NIDAQ code if that would help.

 

Using MAX on the Windows machine with the 6251 card, it seems that CTR0Source is permanently connected to PFI8, and so is CTR1Source.  It seems strange to me that NIDAQmx would have less flexibility than traditional NIDAQ.

0 Kudos
Message 3 of 4
(3,306 Views)

Hi Shiva,

 

If I understand you correctly, I believe you are looking for the DAQmxConnectTerms function.  In addition, some terminology has changed between Traditional NI-DAQ and NI-DAQmx.  The Update Clock is now called the Sample Clock.  I've attached a link to a document that describes some of the terminology changes between the two as well as a link to a document that describes the process of transitioning from Traditional NI-DAQ to NI-DAQmx in general.  Hopefully some of this gets you going in the right direction!

 

What are the Terminology Changes in NI-DAQmx?

http://digital.ni.com/public.nsf/websearch/7759B0D2A8A392DF86256D21001B452E

 

Transitioning from Traditional NI-DAQ (Legacy) to NI-DAQmx Using ANSI C and NI LabWindows/CVI

http://www.ni.com/white-paper/5957/en

Josh B
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,296 Views)