Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI 9171 and NI 9421: change the sampling rate in Matlab

Hey, I have a question about changing the sampling clock to acquire digital data in Matlab.

 

I need a counter input channel and a digital input channel for my application, which should be both run in the background. I have no external clock and so I have to use the 100kHz, 20Mhz or 80Mhz time base. The problem is that the maximum sampling rate for the digital input channel can be only 10kHz. I read in the forum some things about using the frequency generator. But the commands to divide the external time bases are not described for Matlab applications. My question:

1.)Is it in general possible to reduce the sampling rate without any external clock or use a clock with a frequency less than 10kHz?

2.) If yes, is it also possible for Matlab applications?

 

My code:

daq.getDevices;                           
                                                 
ni9421_1 = daq.createSession ('ni');  
ni9421_2 = daq.createSession ('ni');  
              
% Add Counter Channel and Clock Connection
ni9421_1.Rate = 100000;
ni9421_2.Rate = 10000;

addCounterInputChannel(ni9421_1,'cDAQ1Mod1','ctr0','EdgeCount');
addClockConnection(ni9421_1,'external','cDAQ1/100kHzTimebase','ScanClock');

addDigitalChannel(ni9421_2,'cDAQ1Mod1','Port0/Line2','InputOnly');
addClockConnection(ni9421_2,'external','cDAQ1/100kHzTimebase','ScanClock');

ni9421_1.IsContinuous = true;
ni9421_2.DurationInSeconds=10;
lh1 = addlistener(ni9421_2,'DataAvailable',@(src, event)savDat1(src, event, fid2));
ni9421_2.startBackground;

 

 

Error code:

NI Error -201002:
Sample Clock Rate must match the frequency of the internal timebase specified as the Sample Clock Source.

To use the specified Sample Clock Rate, set the Sample Clock Source to OnboardClock. To use the specified timebase as the Sample Clock, set the Sample Clock
Rate to the frequency of that timebase.
Sample Rate:  10.0e3
Source Terminal: /cDAQ1/100kHzTimebase

Task Name: _unnamedTask<1F>

Status Code: -201002

 

 

I would be very happy if someone can help me with my problem.

Thank you in advance!

 

0 Kudos
Message 1 of 2
(3,137 Views)

@Svenpablo wrote:

 

I need a counter input channel and a digital input channel for my application, which should be both run in the background. I have no external clock and so I have to use the 100kHz, 20Mhz or 80Mhz time base. The problem is that the maximum sampling rate for the digital input channel can be only 10kHz. I read in the forum some things about using the frequency generator. But the commands to divide the external time bases are not described for Matlab applications. My question:

1.)Is it in general possible to reduce the sampling rate without any external clock or use a clock with a frequency less than 10kHz?

2.) If yes, is it also possible for Matlab applications?

 


  1. Yes
  2. Pretty sure yes.

There's a link here to a Mathworks tutorial to set a clocked digital input. It looks fairly similar to your code. The key point (as far as I remember from hitting the same issue in LabVIEW) is that you can't explicitly set a timebase as the sample clock source unless you have the same rate. However, the timebase can be (and obviously is) used and internally divided down to provide lower frequency sample clocks for input and output tasks.

 

For clocked digital input, the example I linked above shows generating a clock output signal at a specific rate (they use 100 Hz), and then using that clock signal as an "external" clock, despite it really being internal. The cDAQ chassis you have seems to have 4 counters, so you should be OK using a second counter alongside the existing counter task.

 


GCentral
0 Kudos
Message 2 of 2
(3,035 Views)