radar08
Newbie level 6
xilinx coe file
In fact, to generate Xilinx coe file is to transform decade to binary of hex data. Matlab is very helpful. When using Xilinx IP Core to generate RAM with initialization file or ROM with .coe file, the top two line is:
MEMORY_INITIALIZATION_RADIX=2;
MEMORY_INITIALIZATION_VECTOR=;
// The radix here can 16 or 10 but if 10 the data must be unsigned data.
If using FIR Compiler, we should generate FIR coefficients file. The format is:
radix=coefficient_radix;
coefdata=
a(0),
a(1),
a(2),
….
a(N-1);
//here the coefficient_radix is 2,10,16. if 10, the coefficient can be either signed or unsigned data.
这里给出一个有符号十进制转换为二进制的例子,生成.coe文件
The below is a matlab function to transform signed decade data to binary data.
%=================================================
function []=fddec2bin(data, width)
% Author: yuelengyueming.
% It aims to transfer decade data to binary data and stores in a file.
% data: decade data.
% width: binary bit width.
% Improvement: define the file name.
if length(dec2bin(max(abs(data))))>width
error('The second parameter is not bigger enough.');
end;
L=length(data);
fd=fopen('data.coe','w');
for k=1:L
if data(k)>=0
temp=dec2bin(data(k),width);
else
temp=dec2bin(2^width-abs(data(k)),width);
end;
fprintf(fd,'%s,\n',temp);
end;
fclose(fd);
%=================================================
In fact, to generate Xilinx coe file is to transform decade to binary of hex data. Matlab is very helpful. When using Xilinx IP Core to generate RAM with initialization file or ROM with .coe file, the top two line is:
MEMORY_INITIALIZATION_RADIX=2;
MEMORY_INITIALIZATION_VECTOR=;
// The radix here can 16 or 10 but if 10 the data must be unsigned data.
If using FIR Compiler, we should generate FIR coefficients file. The format is:
radix=coefficient_radix;
coefdata=
a(0),
a(1),
a(2),
….
a(N-1);
//here the coefficient_radix is 2,10,16. if 10, the coefficient can be either signed or unsigned data.
这里给出一个有符号十进制转换为二进制的例子,生成.coe文件
The below is a matlab function to transform signed decade data to binary data.
%=================================================
function []=fddec2bin(data, width)
% Author: yuelengyueming.
% It aims to transfer decade data to binary data and stores in a file.
% data: decade data.
% width: binary bit width.
% Improvement: define the file name.
if length(dec2bin(max(abs(data))))>width
error('The second parameter is not bigger enough.');
end;
L=length(data);
fd=fopen('data.coe','w');
for k=1:L
if data(k)>=0
temp=dec2bin(data(k),width);
else
temp=dec2bin(2^width-abs(data(k)),width);
end;
fprintf(fd,'%s,\n',temp);
end;
fclose(fd);
%=================================================