撒萌萌

 

用MATLAB生成QUARTUS II的*.mif (转)

用MATLAB生成QUARTUS II的*.mif
 

做设计时经常要调用芯片内存。特别对于ROM,内存的初始化就显得比较重要。当然你完全可以手工在QUARTUS II打开mif文件的表格里或是在EXCEL中逐个输入,几十项(字)或是近百项(字)你还可以接受,如果上千项或是更多呢?估计会累死人!

一般内存的初始化数据都是有规律的,符合一定的函数,我们完全可以用MATLAB来完成(如果没规律只能逐项手工输入了)

首先,我们应该知道*.mif文件的格式,它其实是文本格式文档,用写字板打开一个mif文件,你会发现它具有如下的格式:

 

-- Copyright (C) 1991-2008 Altera Corporation

-- Your use of Altera Corporation's design tools, logic functions

-- and other software and tools, and its AMPP partner logic

-- functions, and any output files from any of the foregoing

-- (including device programming or simulation files), and any

-- associated documentation or information are expressly subject

-- to the terms and conditions of the Altera Program License

-- Subscription Agreement, Altera MegaCore Function License

-- Agreement, or other applicable License agreement, including,

-- without limitation, that your use is for the sole purpose of

-- programming logic devices manufactured by Altera and sold by

-- Altera or its authorized distributors. Please refer to the

-- applicable agreement for further details.

 

-- Quartus II generated Memory Initialization File (.mif)

 

WIDTH=8;

DEPTH=256;

 

ADDRESS_RADIX=UNS;

DATA_RADIX=UNS;

 

CONTENT BEGIN

0:127;

1:126;

2:126;

……

……

253:126;

254:126;

255:127;

END;

如果从m到n 单元格内的数据是相同的55,会是这样的格式出现:[m..n] :55;

 

 

格式很简单吧。首先根据需要设置每个字的位宽WIDTH和总字数(或总单元格数)DEPTH,然后设置地址和数据的进制基数ADDRESS_RADIXDATA_RADIX,建议大家不要修改,就使用无符号数(UNS)。然后用MATLAB生成需要的数据(按上边的格式,注意中间“:”,最后“;”),往CONTENT BEGINEND中间一贴就行了。

 

下边举例说明MATLAB生成需要数据的程序的写法,希望对大家有用:

 

%the walue of cosine

function data=makedata

index = linspace(0,2*pi,2^8);

cos_value = cos(index);

cos_value = cos_value * (2^7 -1 );

cos_value = fix(cos_value);

cos_value =abs(cos_value);

for i=65:192

cos_value(i)=cos_value(i)+128;

end

%///////////////////////////////////////上边的用来生成数据,下边的用于控制格式输出

number=[0:255];

for i=1:256

comer(i)=':';

end

for i=1:256

semi(i)=';';

end

data=[number; comer; cos_value; semi];

fid=fopen('d:\data.txt','w');   %在D盘下生成文件data.txt

fprintf(fid, '%d%c%d%c\n', data);

fclose(fid);

 

D盘下找到data.txt文件,用写字板打开mif文件,将data.txt中的内容贴到CONTENT BEGINEND中间,然后保存就可以了,这样就用MATLAB工具输入行数不多的程序生成有规律数据,然后复制到用写字板打开的mif文件的CONTENT BEGINEND之间,成功录入ROM的初始化数据了。

注:MATLAB的这两段程序未经本人验证过!!

posted on 2011-10-20 10:49  撒萌萌  阅读(1680)  评论(0编辑  收藏  举报

导航