Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Change the sampling rate for digital signal generation

Solved!
Go to solution

I have a question about changing the sampling clock rate when using the digital output
lines to generate signals. 

I'm using DAQmxCfgSampClkTiming (TaskHandle taskHandle, const char source[],
float64 rate, int32 activeEdge, int32 sampleMode, uInt64
sampsPerChanToAcquire); to set the sampling clock source for digital signal
generation.

But I found out the parameter float64 rate doesn't really change the sampling
frequency. For example, if I use "100kHzTimebase" for the const char
source[] clock source parameter, no matter what number I specify for  float64
rate, the sampling rate is always 100kHz.

I don't understand where I did wrong, and I was wondering what's the easiest
way to change the sampling frequency to an arbitrary number I want.

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

Hi Simingma,

 

Instead of using the 100kHz Timebase as your clock source, use the the OnBoardClock. The sample clock rate must match the freq of the internal timebase defined as the sample clock source, which is the 100kHz Timebase. To get around that, use "OnBoardClock."

 

Can you also let us know what hardware you are using? To clarify you are using a digital task, not a counter task, correct? It is also worthwhile checking out the DAQmx examples on digital output.

Ren H.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 8
(5,838 Views)

Thank you, Ren! I'm using NI6115, digital output port.

 

I tried to use "OnboardClock" or "OnBoardClock", but I got error -89120 "Source terminal to be routed could not be found on the device. Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names."

 

I also attach a snippet of my code here:

 

char outchannel_str[] = "Dev1/port0/line0:7";

DAQmxErrChk (DAQmxCreateTask("OutputTask",&taskHandleScanin));
DAQmxErrChk(DAQmxCreateDOChan(taskHandleScanin,outchannel_str,"outchannel",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgOutputBuffer(taskHandleScanin, 14));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandleScanin, "OnboardClock", 1000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 14));
for (linecount = 0; linecount < 14; linecount++){
DAQmxErrChk(DAQmxWriteDigitalLines(taskHandleScanin, 1, 0, 10.0, DAQmx_Val_GroupByChannel, scaninData[linecount], NULL, NULL));
}
DAQmxErrChk(DAQmxStartTask(taskHandleScanin));

 

Thanks!

 

 

 

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

Hi Simingma,

 

Ah, "OnBoardClock" is not a valid input for the 6115. How are you checking what sampling rate? I'm assuming you are calling the DAQmxGetSampleClkRate function after you set the sampling rate using the DAQmxCfgSampClkTiming function?

 

I tried setting the sampling rate on my side with a simulated 6115 and was able to change the rate when the sample clock was set to the 100kHz clock. I am checking this using the DAQmxGetSampleClkRate function. Try running an DO example. You can find it at C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Generate Values. I think the Cont Write Dig Port-Ext Clk is a good starting point. You can point the clock source to 100k or mastertime base. 

Ren H.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 8
(5,812 Views)

Hi Ren,

I connect the digital output lines to an oscilloscope, and set the oscilloscope to one-time trigger mode to capture the digital output signals, and then measured the pulse width. If I use 100kHzTimebase, changing the sampling rate had no influence, because I measured the output pulse width to be always 10us (correponding to 100kHz).

 

I tried NULL or "", but got error -200303:

"External sample clock source must be specified for this application. 
Task Name: OutputTask
Status Code: -200303"
 

I also tried other clock source terminal names, like "MasteTimebase",  but got error -89120:

"Source terminal to be routed could not be found on the device. Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names."
 
I'm confused why I couldn't use default sampling clock or predefined terminal names I found in this link http://zone.ni.com/reference/en-XX/help/370466AC-01/mxcncpts/termnames/.
 
Thanks!
0 Kudos
Message 5 of 8
(5,797 Views)

Hello Simingma!

Can you use the function Ren mentioned, the DAQmxGetSampleClkRate function, after configuring the 100kHz clock and setting the sample rate? What does this function return?

Also, it may be worth pointing out that you misspelled "MasterTimebase" in your post, so I'm wondering if its a syntax error in your code? Please check that and get back to us. 

Tanim I.
Application Engineer

0 Kudos
Message 6 of 8
(5,755 Views)
Solution
Accepted by topic author simingma

Sample clock sources that have a rate as part of their name (such as "100kHzTimebase" or "20MHzTimebase") are a fixed rate (100kHz or 20MHz, respectively) and can't be changed with the DAQmxCfgSampClkTiming 'rate' parameter.

 

The digital subsystem on the 6115 is not able to generate its own sample clock (as it can on the 63xx series), but it is capable of performing correlated digital I/O by using an alternative sample clock source (such as by sharing the sample clock from an AI/AO task or by using a counter).

 

One possible option is to use a counter output task to generate sample clock pulses, then use "Ctr0InternalOutput" or "Ctr1InternalOutput" as the sample clock source for your Digital Output task. Specify your sampling rate as both the output frequency for the counter task and as the sample clock rate on your digital task.

 

The Digital/Generate Values/WriteDigChan-ExtClk.c example demonstrates use of an external sample clock (in the example's case, "/Dev1/PFI0"). The Counter/Generate Pulse/Dig Pulse Train-Cont/DigPulseTrain-Cont.c example demonstrates pulse generation using a counter. Both examples are installed with the NI-DAQmx distribution.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
0 Kudos
Message 7 of 8
(5,747 Views)

Thank you all, Brandon, Ren and Tanim!

I was able to use the counter to generate a continuous digital pulse train, and use that as the external sampling clock of the digital output channel.

I'm so excited it's working now! 

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