11-01-2016 09:50 AM
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.
Solved! Go to Solution.
11-02-2016 09:32 AM
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.
11-02-2016 10:26 AM
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";
Thanks!
11-03-2016 10:36 AM
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.
11-04-2016 02:11 PM
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:
I also tried other clock source terminal names, like "MasteTimebase", but got error -89120:
11-08-2016 02:42 PM
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
11-08-2016 05:10 PM
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.
11-11-2016 04:52 PM
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!