Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

6255 gated external sample clock for use with an ai task

I have an application written in ansi C that will create an NI task that will run a continueous collection of several AI lines at a set collection rate (see CollectionRate below).  This is a simplified version of the setup of the ai task:
 
      ni_rc = DAQmxCreateTask (
                  "",                     // name assigned to the task
                  &ai_task);   // reference to the task created in this function
      for (i = 0; i < ai_channels; i++)
      {
            /* Create an NI AI voltage channel.
             */
         if (ai_ptrs[i].chan_num >= 0)
         {
            char  chan_name[MAX_STRLEN];  // NI channel name, e.g. "Dev1/ai2"
            //
            long     chan_num = ai_ptrs[i].chan_num;
            sprintf (chan_name, INPUT_CHANNEL_FORMAT, deviceName, chan_num);
            ni_rc = DAQmxCreateAIVoltageChan (
                        ai_task,                // task to which to add the channel
                        chan_name,              // names of the physical channels to use
                        "",                     // name(s) to assign to the created virtual channel(s)
                        terminal_config,        // differential vs. single-ended
                        (double) devsupp_ai_channels[chan_num].volts_min,   // minimum voltage expected
                        (double) devsupp_ai_channels[chan_num].volts_max,
                        (long) DAQmx_Val_Volts, // units in which to generate voltage (unscaled)
                        "");                    // name of a custom scale
         }
      }
      ni_rc = DAQmxCfgSampClkTiming (
                  ai_task,           // task reference
                  "",                           // clock source terminal (internal clock)
                  (double)CollectionRate,       // sampling rate in hz
                  (long) DAQmx_Val_Rising,      // rising edge of clock signal is active
                  (long) DAQmx_Val_ContSamps,   // continuous sampling
                  1ULL);                        // samples per channel to acquire
      ni_rc = DAQmxStartTask (ai_task);
 
 
Now I need to use an external sample clock.  That part will be easy just change the DAQmxCfgSampClkTiming statement to:
 
            ni_rc = DAQmxCfgSampClkTiming (
                        ai_task,           // task reference
                        CLOCK_SOURCE,                       // clock source terminal e.g. PFI7 or RTSI2...
                        MAX_COLECTION_RATE,            // maximum sampling rate in hz
                        (long) DAQmx_Val_Rising,            // rising edge of clock signal is active
                        (long) DAQmx_Val_ContSamps,   // continuous sampling
                        1ULL);                        // samples per channel to acquire
 
However I also need to have the external clock GATED by a second external signal.  I am sure given the capabilities of the card and the DAQmx software In can be done but how?  Do I need to set up a second task with a counter (as a divide by 1).  The clock input and gate to the counter will be from a hardware terminal and use the counter output as the CLOCK_SOURCE?
0 Kudos
Message 1 of 3
(2,841 Views)

Hi anderssd,

If you would like to set up a gated external clock, you can look into the some of our DAQmx shipping examples which shows you exactly how to set that up. The DAQmx ANSI C examples are installed with your DAQmx drivers and should be under C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse. The example we are particularly interested in is Dig Pulse Train Cont-Pause Trig. This example allows you to generate a continuous pulse train using a counter and have a pause trigger. This can effectively be used to gate your clock, however, you would need to make an external connection from your external signal to one of the PFI lines.

I hope this helps,

S_Hong
National Instruments
Applications Engineer
0 Kudos
Message 2 of 3
(2,814 Views)

Thanks:

In point of fact for my application the DAQmxSetDigLvlPauseTrig* (DAQmxSetDigLvlPauseTrigSrc & DAQmxSetDigPatternPauseTrigWhen) are a better fit.  For my case I will use a line (PFI9) as the source of the pause trigger and use the PFI7 as the source clock.

 

 

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