Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

External reference clock and edge counting

Hi,
     we would like to use the M series 6251 as below
 
1) Acquire analog signals using a digital signal as trigger
2) Using an external 10MHz clock from a GPS device as reference
     This is required since the 50 PPM accuracy of the internal 6251 is not
      enough for this measurement.
3) Count the edges of the 10MHz signal. Read the value of the counter
     for each sample and use this as a timestamp for the sample.
 
Some of the code is as below
 
  DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
  DAQmxErrChk (DAQmxCreateTask("",&CtrtaskHandle));
 
  DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_RSE,0,4,DAQmx_Val_Volts,NULL));
  DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai1","",DAQmx_Val_RSE,0,4,DAQmx_Val_Volts,NULL));

  DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChan));
  DAQmxErrChk (DAQmxCfgDigEdgeRefTrig(taskHandle,triggerSrc,DAQmx_Val_Rising,preTrigSamps));
  DAQmxErrChk (DAQmxGetTaskAttribute(taskHandle,DAQmx_Task_NumChans,&numChannels));

  DAQmxErrChk (DAQmxSetTimingAttribute(taskHandle,DAQmx_RefClk_Src,"/Dev1/PFI8"));
  DAQmxErrChk (DAQmxSetTimingAttribute(taskHandle,DAQmx_RefClk_Rate,10000000.00));
  DAQmxErrChk (DAQmxCreateCICountEdgesChan (CtrtaskHandle,"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));
  DAQmxErrChk (DAQmxStartTask(CtrtaskHandle));
 
  DAQmxErrChk (DAQmxStartTask(taskHandle));
  
  DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,sampsPerChan,10,DAQmx_Val_GroupByChannel,data,sampsPerChan*numChannels,&numRead,NULL));
  DAQmxErrChk (DAQmxReadCounterScalarU32(CtrtaskHandle,0.5,&counterData,NULL));
 
I get the NON FATAL error
 
"Specifed route cannot be satisfied because it requires resources that are currently in use by another route"
Also the error is in the attachment.
 
It appears to be a conflit between the external clock and the counter. The data acqusition works with either the external clock or the counter
but not with both. Kindly help me debug.
 
Thanks
 
-Charles
0 Kudos
Message 1 of 5
(5,182 Views)
 

Hello Charles,

Thanks for contacting National Instruments. 

If I understand correctly, you would like to use an external 10 MHz clock to time an analog input acquisition.  At the same time, you would also like to count the number of edges of the sample clock that have occurred.  I am also assuming you are using LabWindows CVI to write this code. 

The error you are getting is from the DAQmxSetTimingAttribute command.  This function is used to route the internal reference clock of the device to a PFI line.  This is used mainly when synchronizing multiple DAQ cards to the same sample rate. 

To specify an external clock for use in a finite acquisition, please refer to the shipping example Acq-ExtClk.  For CVI, you can click Help-> Find Examples to bring up the NI Example Finder.  This examples is located under Hardware Input and Output -> DAQmx -> Analog Measurements -> Voltage.  For any other language, please refer to the DAQmx readme file in the Program Files -> National Instruments -> NI-DAQ.  This will provide the directory path location for the DAQmx examples in other programming languages.  This example uses an external clock to perform a finite acquisition.  The line:

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,clockSource,rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChan));

Allows for you to specifically set which pin uses the sample clock as well as other timing parameters.  You can view the CVI help for more information regarding the inputs of this function. 

For more information regarding a reference trigger, please see the Getting Started with DAQmx Page.  Under the Basic Programming link, there is a link (Triggering Using DAQmx) that goes over the different trigger types.  A reference trigger is used to stop acquisition.  However, acquisition will stop after the number of samples specified in SampsPerChan has been met. 

A finite aquisition will stop after the number of samples specified in the timing configuration command have been read.  This reduces the necessity of a counter task.  If it is still necessary to count the number of edges during the acquisition process, the following information may help you get started.  A counter task can be run at the same time as an AI task.  The input channel of the counter can be specified as the same pin as the sample clock.  This will not guarantee that the counter task and the AI task start at the same time.  To do this, you can specify a start trigger for the counter task using the line:

DAQmxCfgDigEdgeStartTrig (CtrTaskHandle, "/Dev1/ai/StartTrigger", DAQmx_Val_Rising);

By starting the counter task before the AI task, you will guarantee that the counter will start at the same time as the AI. 

Please post back if you have any more questions.

 

Regards,
Browning G
FlexRIO R&D
Message 2 of 5
(5,168 Views)

Hi Browning, thanks for the information. I would like to clarify that we are using the internal sample clock of 100KHz. But we would like the

reference clock for the PLL of that sample clock to be the external 10MHz GPS clock.

Thanks

-Charles

0 Kudos
Message 3 of 5
(5,148 Views)
What external GPS product are you using? You could override PXI_CLK10 with that 10MHz reference. I think you could then have the M-series board lock to that 10MHz.

-Adam
0 Kudos
Message 4 of 5
(5,140 Views)
 

Hello Charles,

Depending on whether you are using the PCI or PXI version of the 6251, the options for which input on the card uses the external 10 MHz reference clock will change.  Looking at the M Series DAQ Manual on page 9-2 I found the lines used as the timing source for an External Reference Clock.  This lists the RTSI and PXI lines that can be used for this reference clock source.  You should also be able to use an unused PFI line on your device.  This can be set using the DAQmxSetTimingAttribute command in CVI with DAQmx_RefClk_Src set as the attribute to be set.  This will cause the VI to phase lock loop the external 10 MHz clock to the internal 10 MHz clock. 

At this point you should be able to specify the sample clock for your DAQmx task to use the internal sample clock by leaving the source in the DAQmxCfgSampClkTiming command to NULL or OnboardClock.  The sample clock speed can be set to 100 kHz.

Please post back with any questions. 

Regards,
Browning G
FlexRIO R&D
0 Kudos
Message 5 of 5
(5,115 Views)