MAIN CODE
close allclear allclcstartV=5.4;dither=0.05;wait=100;target=6e-3;targetThresh=0.9;TARG=target*targetThresh*1000ticmy_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);tocwrite=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); endend
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