Session based digital I/O using the DAQ toolbox fills memory

1 view (last 30 days)
Dear all
I'm trying to send a PWM signal to a motor using the DAQ toolbox in connection with a NI USB-6251 card and the sessin based interface. I add an event listener which does continuously output the signal in the background. For some reason, the memory of my PC is filled up withing roughly a minute (64-bit, Win7, Matlab R2013a). Interestingly, the memory is not freed when issuing clear all or clear functions. Leakage?
Can anyone give me a reason for this and a workaround? Is there a better/more elegant option to produce a PWM with the existing setup?
Here is the code I'm using
clear all; close all; clc
%%init
clockFreq = 10e6;
sClk = daq.createSession('ni');
sClk.addCounterOutputChannel('Dev1','ctr0','PulseGeneration');
sClk.Channels(1).Frequency=clockFreq;
clkTerminal = sClk.Channels(1).Terminal;
sClk.IsContinuous = true;
sClk.startBackground;
s = daq.createSession('ni');
s.addDigitalChannel('Dev1','Port0/Line2','OutputOnly');
s.Rate = clockFreq;
s.addClockConnection('External',['Dev1/' clkTerminal],'ScanClock');
%%Output PWM signal
freq=158000;
Ns=round(clockFreq/freq);
freq=10e6/Ns;
duty=0.5;
L1=floor(duty*Ns);
L2=ceil((1-duty)*Ns);
outputData(:,1)=[ones(L1,1);zeros(L2,1)];
outputData=repmat(outputData,round(2*freq),1);
s.IsContinuous=true;
s.queueOutputData(outputData);
lh=s.addlistener('DataRequired', @(src, event) s.queueOutputData(outputData));
s.startBackground();
pause
%%clean up
s.stop;
s.IsContinuous=false;
s.queueOutputData(0);
s.startForeground();
delete(lh)
Any help is appreciated.
Philipp

Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!