DDS module and test bench finished
This commit is contained in:
+37
-17
@@ -5,11 +5,11 @@
|
||||
% Module name - DDS (direct digital synthesis)
|
||||
%
|
||||
% Detailed module description:
|
||||
% This file generates lock up table with SIN values
|
||||
% This file generates lock up table with SIN and COS values
|
||||
%
|
||||
% Revision:
|
||||
% A - initial design
|
||||
% B -
|
||||
% B - add COS output
|
||||
% C -
|
||||
%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@@ -18,30 +18,50 @@ word_lenght = 8;
|
||||
table_size = 4; % 2^n
|
||||
x = linspace(0, (2*pi - 2*pi/2^table_size) , 2^table_size);
|
||||
sin_x = sin(x);
|
||||
sin_x = round(sin_x * 2^word_lenght) / 2^word_lenght;
|
||||
sin_x = round(sin_x * 2^word_lenght) / 2^word_lenght; % round values
|
||||
|
||||
%% Print values in hex
|
||||
hex = [];
|
||||
cos_x = cos(x);
|
||||
cos_x = round(cos_x * 2^word_lenght) / 2^word_lenght; % round values
|
||||
|
||||
%% Print values in HEX
|
||||
hex_sin = [];
|
||||
hex_cos = [];
|
||||
for i=1:2^table_size
|
||||
a = sfi(sin_x(i),word_lenght,word_lenght-2);
|
||||
hex = [hex; a.bin];
|
||||
a = sfi(sin_x(i),word_lenght,word_lenght-2);
|
||||
b = sfi(cos_x(i),word_lenght,word_lenght-2);
|
||||
hex_sin = [hex_sin; a.bin];
|
||||
hex_cos = [hex_cos; b.bin];
|
||||
end
|
||||
hex,
|
||||
%hex_sin,
|
||||
%hex_cos,
|
||||
|
||||
fid = fopen('lookuptable.v', 'wt');
|
||||
fprintf(fid, 'module lookuptable(\n');
|
||||
fprintf(fid, '\tinput [%d :0] in,\n',word_lenght-1);
|
||||
fprintf(fid, '\toutput reg [%d :0] out);\n',word_lenght-1);
|
||||
fprintf(fid, 'module lookuptable #( parameter phase_width = %d, data_width = %d)(\n', table_size, word_lenght);
|
||||
fprintf(fid, '\tinput [phase_width - 1 :0] phase,\n');
|
||||
fprintf(fid, '\toutput reg [data_width - 1 :0] sin,\n');
|
||||
fprintf(fid, '\toutput reg [data_width - 1 :0] cos);\n');
|
||||
|
||||
fprintf(fid, 'reg [%d :0] out = %d''h0; \n', word_lenght-1,word_lenght);
|
||||
% fprintf(fid, 'reg [%d :0] sin = %d''h0; \n', word_lenght-1,word_lenght);
|
||||
fprintf(fid, 'always@* begin\n');
|
||||
fprintf(fid, 'case (in)\n');
|
||||
fprintf(fid, 'case (phase[phase_width - 1 : 0])\n');
|
||||
|
||||
for i=1:length(hex)
|
||||
temp = hex(i,1:word_lenght);
|
||||
fprintf(fid, '\t%d''d%d : out <= %d''b%s;\n',word_lenght, i-1 ,word_lenght, hex(i,1:word_lenght) );
|
||||
for i=1:length(hex_sin)
|
||||
temp = hex_sin(i,1:word_lenght);
|
||||
fprintf(fid, '\t%d''d%d : sin[data_width - 1 : 0] <= %d''b%s;\n',table_size, i-1 ,word_lenght, hex_sin(i,1:word_lenght) );
|
||||
end
|
||||
fprintf(fid, '\tdefault : out <= %d''b%s;\n ',word_lenght, hex(1,1:word_lenght) );
|
||||
fprintf(fid, '\tdefault : sin[data_width - 1 : 0] <= %d''b%s;\n ',word_lenght, hex_sin(1,1:word_lenght) );
|
||||
fprintf(fid, 'endcase\n');
|
||||
fprintf(fid, 'end\n');
|
||||
fprintf(fid, ' \n');
|
||||
|
||||
fprintf(fid, 'always@* begin\n');
|
||||
fprintf(fid, 'case (phase[phase_width - 1 : 0])\n');
|
||||
|
||||
for i=1:length(hex_cos)
|
||||
temp = hex_cos(i,1:word_lenght);
|
||||
fprintf(fid, '\t%d''d%d : cos[data_width - 1 : 0] <= %d''b%s;\n',table_size, i-1 , word_lenght, hex_cos(i,1:word_lenght) );
|
||||
end
|
||||
fprintf(fid, '\tdefault : cos[data_width - 1 : 0] <= %d''b%s;\n ',word_lenght, hex_cos(1,1:word_lenght) );
|
||||
fprintf(fid, 'endcase\n');
|
||||
fprintf(fid, 'end\n');
|
||||
fprintf(fid, 'endmodule');
|
||||
|
||||
Reference in New Issue
Block a user