MATLAB: I’m using a NIDAQ USB6343 device to acquire an error signal which is just a continuous voltage. I’ve used Matlab help to develop the code as this is our first encounter with Matlab and NI DAQ integrated. Kindly see the code below.

acquiring continuous input voltages using ni usb 6343

MAIN CODE
close all
clear all
clc
startV=5.4;
dither=0.05;
wait=100;
target=6e-3;
targetThresh=0.9;
TARG=target*targetThresh*1000
tic
my_NIDAQ_USB_6343=daq.getDevices; %finds all DAQ devices connected to the PC and supported by matlab.
DAQ=daq.createSession('ni'); %opens the session between the PC,matlab,DAQ.
DAQ.Rate = 100000;
DAQ.DurationInSeconds =0.01;
addAnalogInputChannel(DAQ,'Dev1','ai1','Voltage'); %adds a single analog input channel
addAnalogOutputChannel(DAQ,'Dev1','ao1','Voltage'); %adds a single analog output channel
pause(wait/1000);
toc
write=startV/10; %%%%DIVIDE BY 10 BEFORE WRITING TO DC

outputSingleScan(DAQ,write); %WRITE

pause(wait/1000);
newDCv=startV;
while 2>1
% lockStepCounter=0
currentDCv=inputSingleScan(DAQ);
currentDCv=newInputFunct(DAQ) %READ

pause(wait/1000);
while currentDCv<target*targetThresh
% lockStepCounter=lockStepCounter+1
dUp=ditherUp(DAQ,newDCv,dither,wait);
dDown=ditherDown(DAQ,newDCv,dither,wait);
%%%Choose parameters to pass to calcStep
if dUp(1,1)==1
ud=1;
grad=dUp(1,2);
else
ud=-1;
grad=dDown(1,2);
end
%%%%%
%calStep(ud,grad,target)
stepVal=calStep(ud,grad,target);
newDCv=newDCv+stepVal;
write=newDCv/10; %%%%DIVIDE BY 10 BEFORE WRITING TO DC
outputSingleScan(DAQ,write); %WRITE
pause(wait/1000);
currentDCv=newInputFunct(DAQ); %READ
pause(wait/1000);
end
end
FUNCTION>newInputFunct
function [ output ] = newInputFunct(DAQ)
[data] = DAQ.startForeground();
output=mean(data);
end
We want to lock the phase of a signal traveling along an optical fibre to a precise and stable reference signal, so what we actually doing is developing a phase lock loop. We do this by using the DAQ to acquire a continuous error signal (voltage) then using Matlab to do a dither step while our acquired voltage is below a certain threshold until the error signal is maximized. When this happens the phase of the signal along the fiber and the reference signal will be in phase. The function holds the commands for acquiring the voltage. My code is not running as I'm getting the following error message "there must be data queued in the session before this function can be called." Can you please advise on how to overcome this error. Thanks

Best Answer

Your session has both an input channel and an output channel. You startForeground on it, which asks that both the input and output take place. But you have not queued any output samples. You need to have queued output samples to go out for as many time periods as you are doing input on when you run foreground operations on a session with both input and output channels.
I notice that you are trying to mix single scans and foreground operations. If I recall correctly, single scans bypass queues, and so are risky to mix with foreground operations.
Related Question