Info
此问题已关闭。 请重新打开它进行编辑或回答。
Plotted waveform frequency is way too low
2 次查看(过去 30 天)
显示 更早的评论
I am using Quartus 12.1 sp1, vhdl and Altera Nios II programmed in C code for DE0-Nano Development. Basically, what I have is, Nios II system sends the data to serial port, Matlab access the serial port to real time plot the graph.
In my system, the rate the graph is plotted is much slower (11Hz) than the rate the processor speed (50MHZ).
Please refer to this image:
My question is, what should I change in order to get the waveform plotted with a period of 0.02 seconds instead of 0.16 minutes as I got now? What determine the period of the plotted waveform?
I posted the Matlab code here: EDIT:
max_packets = 20000; %maximum number of packets to keep in memory (all are saved to log file)
update_plot = 1; %how often we should update the plot
plot_length = 12; %maximum length of plot
figure('Position', [10, 50, 900, 900]); % new figure
ax1 = subplot(3,1,1); % top subplot
ax2 = subplot(3,1,2); % bottom subplot
ax3 = subplot(3,1,3);
drawnow;
s = serial(port);
cleanupObj = onCleanup(@()cleanupFunc(s)); %clean-up function
set(s,'BaudRate',115200,'timeout',2); %timeout is in seconds
fopen(s);
vref= NaN(12,max_packets);
j = 0;
tic; %start timer
while 1; %do forever...
if j < max_packets
j = j+1;
else
fprintf('\n Buffer full, reset to 0\n');
j = 1; %reset counter to stop memory overflow
end
%get data line by line
line = fscanf(s);
[c,vo] = disect_line(line);
if c == 1 %start recording from set 1
vref(1,j) = vo;
for i = 2:12 %get set 2 to 12
line = fscanf(s);
[c,vo] = disect_line(line);
if c == i
vref(i,j) = vo;
else
fprintf('\nError\n');
end
end
dlmwrite(logfile,[toc vref(:,j).' ],'delimiter',',','-append'); %save data from all 12 sets to csv file
update plot1 every update_plot packets, and after we have at least 2 data points (otherwise we get errors)
if mod(j, update_plot)==0 && j>1
if j < plot_length
start = 1;
else
start = j-plot_length+1;
end
plot(ax1, start:j, vref(1,start:j).');
for k = 1:1
text(j, vref(k, j), num2str(k), 'Parent', ax1);
end
xlim(ax1, [start j]);
ylabel(ax1, 'Vref');
title(ax1, ['Time elapsed = ' num2str(toc) ' s']);
end
end
function [c, vo] = disect_line(line)
c = str2double(line(1:2)); %set number
vo = str2double(line(4:7));
end
function cleanupFunc(s)
fprintf('\nClosed serial port.\n')
fclose(s);
delete(s);
clear s;
end
0 个评论
回答(1 个)
Walter Roberson
2015-8-17
Your code does not define "start" or "j" and never changes them.
Remember too that start:j would increment by 1 and that if you want a different increment you need start:increment:j
6 个评论
Walter Roberson
2015-8-18
Let Fs = 1000 then 1/Fs = 0.001 and that is what you used as your increment. So in 0:001:1, your first sample is at time 0, your second sample is at 1/Fs = 0.001, your third is at 2/Fs = 0.002, your fourth is at 3/Fs = 0.003
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!