Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
825 Views

Received waveform frequency is way too low than it was sent

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, data is sent from fpga vhdl block to NIos II system, 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). So I do some buffering and send the data for plotting afterwards. 

I am buffering data received from fpga vhdl say 1000 sample points and save it in sdram... after saving these 1000 sample points, the C code will send data to uart so that Matlab can access these serial port data and plot the graph real time. 

 

Please refer to this image: 

 

http://www.alteraforum.com/forum/attachment.php?attachmentid=11015&stc=1  

 

My problem is, a complete cycle of sinewave obtained from fpga is with a frequency of 50Hz, so it should be having a period of 0.02 seconds instead of 0.16 minutes as I got now, I don't know what could be the problem? Forgive me, I am newbie to signal processing.. Thank you. 

 

 

int max_sample =1000;//number of sample points wanted if(a_out_data==1)//check if it is the beginning of a sinusoidal waveform? { for(i=0;i<max_sample;i++)//start the process of buffering data { vref_data = IORD_ALTERA_AVALON_PIO_DATA(vref_base);//read a single value of reference voltage from fpga *(pSDRAM+i)=vref_data;//save this single value in a location of SDRAM specified in SDRAM_U1_BASE } } for(i2=0;i2<i;i2++)//start the process of sending data to uart for all data saved previously { data16=*(pSDRAM+i2);//access each value from SDRAM //send data to uart before increment i++ }
0 Kudos
5 Replies
Altera_Forum
Honored Contributor I
22 Views

You have many variables in your setup: 

 

1) nios runs at known speed but your tone frequency depends on instructions (nios is no good as NCO) so your frequency at generation is unknown 

2) buffering adds further time uncertainty 

3) plotter needs to be scaled correctly but I don't think you can 

 

so with your given info it is not doable.
Altera_Forum
Honored Contributor I
22 Views

 

--- Quote Start ---  

You have many variables in your setup: 

 

1) nios runs at known speed but your tone frequency depends on instructions (nios is no good as NCO) so your frequency at generation is unknown 

2) buffering adds further time uncertainty 

3) plotter needs to be scaled correctly but I don't think you can 

 

so with your given info it is not doable. 

--- Quote End ---  

 

 

 

Thank you kaz for your reply. 

 

Regarding point 1 and point 2, instead of getting Vref from fpga block, now I have the Vref data in C code (as below, just for testing), so I am no longer doing any buffering, still I obtain the same result where the period of a complete cycle of sinewave is 0.16 minutes. So, if I understand correctly, now the data is available in C code straightforward, so shouldn't I expect the data can be plotted faster?  

 

Regarding point 3, I don't understand how to scale the plotter. 

 

 

float Vref = {0.00,0.06,0.13,0.19,0.25,0.31,0.37,0.43,0.48,0.54,0.59,0.64,0.68,0.73,0.77,0.81,0.84,0.88,0.90,0.93,0.95,0.97,0.98,0.99,1.00,1.00,1.00,0.99,0.98,0.97,0.95,0.93,0.90,0.88,0.84,0.81,0.77,0.73,0.68,0.64,0.59,0.54,0.48,0.43,0.37,0.31,0.25,0.19,0.13,0.06,0.00,-0.06,-0.13,-0.19,-0.25, -0.31, -0.37, -0.43, -0.48, -0.54, -0.59, -0.64, -0.68, -0.73, -0.77, -0.81, -0.84, -0.88, -0.90, -0.93, -0.95, -0.97, -0.98, -0.99, -1.00, -1.00, -1.00, -0.99, -0.98, -0.97, -0.95, -0.93, -0.90, -0.88, -0.84, -0.81, -0.77, -0.73, -0.68, -0.64, -0.59, -0.54, -0.48, -0.43, -0.37, -0.31, -0.25, -0.19, -0.13, -0.06}; 

 

Please let me know if I could provide more information, I actually want to know which aspect could be the root of the problem could it be with C code or Matlab code or the uart programming... 

 

I also posted the Matlab code here: 

 

 

 

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', ); % 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... %get data line by line line = fscanf(s); = 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); = disect_line(line); if c == i vref(i,j) = vo; else fprintf('\nError\n'); end end dlmwrite(logfile,,'delimiter',',','-append'); %save data from all 12 sets to csv file plot(ax1, start:j, vref(1,start:j).'); for k = 1:1 text(j, vref(k, j), num2str(k), 'Parent', ax1); end xlim(ax1, ); ylabel(ax1, 'Vref'); title(ax1, ); end end function = 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
Altera_Forum
Honored Contributor I
22 Views

your sine cycle is 100 data so if your sampling frequency(Fs) is regular and known then sine frequency = Fs/100 

Nios/UART/Matlab will process data based on instruction time so time dimension is vague here (Fs in somewhat unknown unless samples are sent at regular intervals). 

If you are sending all samples (without loss or duplication) then scale the plotter according to Fs/100. It looks you have a plotter with fixed time scale. 

 

I think it is better you focus on samples being sent correctly than actually measuring frequency of sine.
Altera_Forum
Honored Contributor I
22 Views

 

--- Quote Start ---  

your sine cycle is 100 data so if your sampling frequency(Fs) is regular and known then sine frequency = Fs/100 

Nios/UART/Matlab will process data based on instruction time so time dimension is vague here (Fs in somewhat unknown unless samples are sent at regular intervals). 

If you are sending all samples (without loss or duplication) then scale the plotter according to Fs/100. It looks you have a plotter with fixed time scale. 

 

I think it is better you focus on samples being sent correctly than actually measuring frequency of sine. 

--- Quote End ---  

 

 

Thanks for your reply, i can get the amplitude of the samples sent correctly, the issue now is the frequency. 

 

Sorry, I still dont understand. What actually determine the period of the plotted waveform?
Altera_Forum
Honored Contributor I
22 Views

Matlab plot is ok for signal values(y axis) but time axis is useless, unless you know the time per sample and then enter the x axis as time.

Reply