Using Timer to read Data. How the BusyMode can help?

10 次查看(过去 30 天)
Hi!
I am reading Data via the use of a NI-DAQ Card. I want to run my code for a long time continuously, but I have to sample my Data with 20kHz. I use FFT on my signals to save memory, and I write the needed values to the harddisk. Every 100s, I do the FFT on the data stored in this file to avoid massive use of memory, and so far, the file is deleted, and the DAQ writes a new one for the next 100s.
Up to now, I used a while loop with a break condition that is fulfilled by counting how many times the buffer of the NI card is read out to check if the data file is complete (I do not like to use here a timer because it never takes exactly 100s to write the 100s signal). It works quite well up to a point where I use it for a long duration. Somehow I have a memory leak in my code and always get the "Out of Memory"-Error at one time (as a standalone, the memory usage is growing continuously up to many GB). I'm quite sure it does not belong to a growing array or similar because I store all data that comes out of the FFT in files on the harddisk and clear the variables or allocate them again. I found by using "profile -memory on" that during the pause() function inside the while loop (to reduce execution times), the code leaks memory (I posted this already in another Question here: Memory usage of functions like pause()).
Now, I try to find and workaround for it. I want to try a timer with TimerFcn. But I do not get it to work. While playing with a minimal example, I found some issues belonging to the BusyMode. It is a bit too simplified since in the real code, the DAQ is also running in "parallel," calling two callback functions for writing and reading the NI card...
Timer = timer(...
'BusyMode','drop',... % <- ?
'ExecutionMode','fixedRate',...
'Period',0.1,...
'TimerFcn',@plot1 );
tic
start(Timer)
pause(1)
toc
stop(Timer)
function plot1(~,~)
disp('Hello I am here, look at me!')
pause(0.2) % to long pause -> should drop/skip the next TimerFcn?
end
As you see, I have a simple TimerFcn that displays a line of nonsense followed by a pause. If the length of this is < Period, it works quite well. But in the case shown above, I expected that I get the message only five times instead of 10. I thought every second execution of the TimerFcn would be skipped. It seems that dopping still ques it.
Or are there other possibilities for that problem? I also had in mind not to use the pause but do a dummy calculation that takes the same amount of time. But what will be the best way?
Best Max

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by