This example shows how to acquire clocked digital data using a counter output channel that generates pulses. The counter provides the clock in this acquisition.
In this example, we will generate a clock in one session using a counter output channel and export the clock to another session that acquires clocked digital data.
This example shows how to create a clock session with a counter output channel that will continuously generate frequency pulses in the background. Use this channel as an external clock in your clocked digital acquisition.
Create a clock frequency that you will use to synchronize the frequency and rate of your counter output as well as the rate of your digital acquisition in the next step.
clockFreq = 100;
Create a session and add a counter output channel with PulseGeneration measurement type.
sClk = daq.createSession('ni'); ch1 = addCounterOutputChannel(sClk,'Dev1',0,'PulseGeneration')
Save the counter output terminal to a variable. You will use this terminal in your digital session to specify the external clock that synchronizes your digital clocked operations.
clkTerminal = ch1.Terminal;
You will use this terminal in your digital session to specify the external clock that synchronizes your digital clocked operations.
Set the frequency of your counter session to the clock frequency.
ch1.Frequency = clockFreq
Set the session to continuous mode.
sClk.IsContinuous = true;
Start the counter output channel in the background.
This example shows how to create a digital input session and import an external clock from the clock session.
Create a session and add a line from port 0 line 2 on Dev1.
s = daq.createSession('ni'); addDigitalChannel(s,'Dev1','Port0/Line2','InputOnly')
Set the sessions scan rate to the same as the rate and the frequency of the counter output channel.
s.Rate = clockFreq;
Import the clock from your clock session to synchronize your acquisition.
Acquire and plot data.
dataIn = startForeground(s); plot(dataIn)
You can also perform clocked operations when you :