搜索
bottom↓
回复: 37

MIF文件生成器(发现坛里没有就转过来)

[复制链接]

出0入0汤圆

发表于 2011-3-22 09:40:05 | 显示全部楼层 |阅读模式
MIF File Generator Utility
What is a .MIF File?
A .MIF (Memory Initialization File) file is used to preload the EAB's in Altera's FLEX devices, like the Altera FLEX 10K family. When you instantiate a ROM or RAM in a schematic or an AHDL file, you have the option to specify a .MIF file for preloading the EAB with some default data.

Look-Up Table
You may use the EAB's as look-up tables. For instance, you could use the EAB's for storing digital waveforms. A typical digital waveform is the digital representation of a sine or cosine waveform.

MIFGEN.EXE, The .MIF File Generator Utility
The MIFGEN utility will generate .MIF files for you with sine or cosine digital waveforms. You have the option to specify several parameters, like amplitude, offset, angle range and so on. The MIFGEN utility is a stand-alone 32-bit executable running under Windows NT or Windows 95.



.MIF sample file
Here is a sample output of the MIFGEN utility, using the above parameters:

-- Memory Initialization File
-- Generated by .MIF File Generator Utility v1.2
-- by Rune Baeverrud

-- Angle Range 0-360 degrees (quadrant 1-2-3-4)
-- Function type    : Cosine
-- Options          : Normal
-- Peak Amplitude   : 127,00
-- Offset           : 0
-- Number of Samples: 256
-- SNR:             : SNR: 49,87dB over i = 0 to 255

DEPTH = 256;
WIDTH = 8;

ADDRESS_RADIX = DEC;
DATA_RADIX = DEC;

CONTENT
  BEGIN
    0 : 127;
    1 : 127;
    2 : 127;
    3 : 127;
    4 : 126;
    5 : 126;
    ...
    ... (some lines removed here)
    ...  
    250 : 126;
    251 : 126;
    252 : 126;
    253 : 127;
    254 : 127;
    255 : 127;
  END;


Parameter Description and Explanation
Parameter Name Description/Explanation
Peak Amplitude A sine or cosine (with no weigth) has a value in the range [-1,1]. The sine or cosine generated will be multiplied by the Peak Amplitude to generate an intermediate floating point representation of the waveform in the range [-Peak Amplitude, Peak Amplitude]. This value can be viewed in the 3rd column of the table ("cos(i)" or "sin(i)"). The floating point value is then rounded or quantized to the nearest whole integer - this is in the 4th column of the table ("Rounded").
Offset The Offset value is then added to Rounded, and the result can be viewed in the 5th column of the table ("w/Offset").
Number of Samples The Number of Samples parameter gives the number of entries in the .MIF file. In the on-screen table, the number of samples is actually one more, so that a complete quadrant, half or circle can be more easily verified.
Number of Bits The Number of Bits parameter is used for two purposes. First, the WIDTH parameter has to be specified in the .MIF file. Second, if the "w/Offset" column contains negative values, the waveform is assumed to be bipolar and it will be represented in 2's complement. Since the .MIF file itself does not accept negative values, the number -3 is converted to 2^(Number of Bits) - 3. Assuming Number of Bits is 8, the new value will be 2^8 - 3 = 256 - 3 = 253. This is the value appearing in the last column, which is also the value written to the .MIF file.
Angle Range The Angle Range parameter specifies the angle range of which the Number of Samples will be applied. The angle range is evenly divided by Number of Samples from 0 degrees up to 90, 180 or 360 degrees.
Function Function specifies if you want to generate a sine or cosine within the angle range.
Options Options lets you specify one of the following options, which apply to the angle range:
Normal. The angle range starts at 0 degrees and ends at, but does not include, the end angle (90, 180 or 360 degrees). For example, the cosine is computed as cos ((Angle Range) * i / Number Of Samples).
Include End Angle. The angle range starts at 0 degrees and stops at, and also includes, the end angle (90, 180 or 360 degrees). For example, the cosine is computed as cos ((Angle Range) * i / (Number Of Samples-1) ). A drawback is that there are 255 samples only per quadrant instead of 256, making it less suitable for a phase modulator. (256 divides nicely into 128, 64, 32, 16 etc. for accurate phase offsets).
Symmetry. The angle range starts at 0 degrees and stops at 90, 180 or 360 degrees, but does not contain the start or the end angle. This method generates a symmetric look-up table. For example, the cosine is computed as cos ((Angle Range) * (i+0.5) / Number Of Samples). A drawback is that the angle has a small offset error - the advantage is that it is very easy to implement a sine/cosine oscillator.


When you have entered your parameters, press the Generate Data button and the on-screen table will be filled with the appropriate values for your inspection. There is also an SNR (Signal-to-Noise Ratio) readout, based on the Signal Power / Quantization Noise Power. If you are satisfied with the result, press the Generate .MIF File button to create the .MIF file itself. You will be asked to supply a name for the new file.

MIF File Generator Utility.zipourdev_624512P9DS3K.zip(文件大小:152K) (原文件名:MIF File Generator Utility.zip)

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2011-3-22 09:45:25 | 显示全部楼层
做 FPGA设计时经常要调用芯片内存。 特别对于 ROM, 内存的初始化就显得比较重要。
当然你完全可以手工在 QUARTUS II 打开 mif文件的表格里或是在 EXCEL 中逐个输入,几
十项(字)或是近百项(字)你还可以接受,如果上千项或是更多呢?估计能累的人吐血!  
一般内存的初始化数据都是有规律的,符合一定的函数,我们完全可以用 MATLAB 来
完成(如果没规律只能逐项手工输入了)。
首先,我们应该知道*.mif 文件的格式。它是文本格式。随便打开一个 mif 文件,你会
发现它具有如下的格式:

-- Copyright (C) 1991-2007 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;

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

下边举例说明 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');
fprintf(fid, '%d%c%d%c\n', data);
fclose(fid);

在 D盘下找到 data.txt 文件,用写字板打开 mif文件,将 data.txt 中的内容贴到
CONTENT BEGIN和 END中间,然后保存就可以了。

对于 hex 文件,更简单。大家生成mif文件后,用 QUARTUS II 打开,然后另存为 hex
文件就可以了。

用MATLAB 生成.mif、.hex(QUARTUS II)文件简介.pdfourdev_624514CO3BS5.pdf(文件大小:64K) (原文件名:用MATLAB 生成.mif、.hex(QUARTUS II)文件简介.pdf)

出0入0汤圆

 楼主| 发表于 2011-3-22 09:46:42 | 显示全部楼层
用 MATLAB 生成*.mif、*.hex(QUARTUS II)文件简介(v1.1)
以前写过一个“用 MATLAB 生成*.mif、*.hex(QUARTUS II)文件简介” ,由于时间和
水平原因很粗糙,并且有一些错误。现在修改一下,升级到 v1.1。以前的称为 v1.0 吧。

做 FPGA设计时经常要调用芯片内存。 特别对于 ROM, 内存的初始化就显得比较重要。
当然你完全可以手工在 QUARTUS II 打开 mif文件的表格里逐个输入, 几十项或许你还可以
接受,但上千项估计能累的人吐血!
一般内存的初始化数据都是有规律的,符合一定的函数,我们完全可以用 MATLAB 来
完成(如果没规律只能逐项手工输入了)。

1.  使用 MATLAB 直接生成*.mif文件
首先,我们应该知道*.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=DEC;

CONTENT BEGIN
[0..3]  :   127;
[4..6]  :   126;
[7..8]  :   125;
9    :   124;
10   :   123;
……
……
[253..255]  :   127;
END;

下边笔者来说明用 MATLAB 产生所需*.mif文件方法。
由于笔者的语文水平仅脱盲,如果空洞讲解很表述清楚并且会很枯燥。所以笔者仍使用一个
例子来说明。对[0,2*pi) (包括 0,不包括 2*pi)256 点采样,每点用 8 位有符号数表示。
生成*.mif文件的 MATLAB 代码如下:
clear all;
close all;
clc;
index=linspace(0,2*pi,2^8+1);  %由于linspace函数包括前后两个边界点,所以多加一点除去
%cos(2*pi)的值
cos_val=fix((2^7-1)*cos(index)+0.5);  %求COS值、倍扩成8位有符号数、fix是去尾求整数,
%加0.5变成四舍五入求整数
fid=fopen('E:\…\cosine.mif','w');  %将cosine.mif文件创建到您老的QUARTUS工程目录里。 当
%然你也可创建到指定的目录,然后拷贝到QUARTUS工程目录。
fprintf(fid,'WIDTH=8;\n');   %指定每个数值的字宽(本工程用8位)
fprintf(fid,'DEPTH=256;\n');   %指定数值的个数,即ROM的深度(本工程用256个)
fprintf(fid,'ADDRESS_RADIX=UNS;\n');   %指定地址的数制(UNS:无符号数。推荐UNS)  
fprintf(fid,'DATA_RADIX=DEC;\n'); %指定数据基数 (DEC: 十进制 (有符号数) , 推荐DEC)  
fprintf(fid,'CONTENT BEGIN\n');   %固定格式
for j=1:256            %数据段数据
    i=j-1;
    fprintf(fid,'%3d',i);
    fprintf(fid,' : ');
    fprintf(fid,'%3d',cos_val(j));
    fprintf(fid,';\n');
end
fprintf(fid,'END;\n');   %固定格式
fclose(fid);

运行此 MATLAB 程序,得到 cosine.mif 即可使用。

用MATLAB生成.mif、.hex(QUARTUS II)文件简介(v1.1).pdfourdev_624515VKREOH.pdf(文件大小:135K) (原文件名:用MATLAB生成.mif、.hex(QUARTUS II)文件简介(v1.1).pdf)

出0入0汤圆

 楼主| 发表于 2011-3-22 09:49:40 | 显示全部楼层
【基于MATLAB生成Intel HEX文件】http://www.matlabsky.com/thread-675-1-1.html

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

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

首先,我们应该知道*.mif文件的格式。它是文本格式。随便打开一个mif文件,你会发现它具有如下的格式:


-- Copyright (C) 1991-2007 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 ******
-- Subscription Agreement, Altera MegaCore Function ******
-- Agreement, or other applicable ****** 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;

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

下边举例说明MATLAB程序的写法,希望对大家有用

function data=makedata
%使用MATLAB生成MIF & HEX2文件
%see also http://www.matlabsky.com
%2009.1.10
%
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:\mif_data_matlabsky.txt','w');
fprintf(fid, '%d%c%d%c\n', data);
fclose(fid);

在d:\下找到mif_data_matlabsky.txt'文件,用写字板打开mif文件,将data.txt中的内容贴到CONTENT BEGIN和END中间,然后保存就可以了。或者将CONTENT BEGIN和END两边的内容分别贴于data.txt文件的前后,然后保存为.mif文件。

对于hex文件,更简单。大家生成mif文件后,用QUARTUS II打开,然后另存为hex

出0入0汤圆

 楼主| 发表于 2011-3-22 09:57:23 | 显示全部楼层
在Quartus II中快速更新FPGA片上存储器初始值的一种方法
http://www.61eda.com/Services/soft/softs/200801/310.html

最近在调试中遇到了这样一个问题:一组参数预先存储在FPGA的片上存储器内;在系统运行过程中部分参数会被读出,修改后写回;为了调试,需要经常变换参数的初始化值。
    实现存储器中数值的初始化比较容易,在生成RAM模块时指定一个初始化文件(.hex或.mif)即可。

    实现部分参数的动态修改也容易,设计一个状态机在需要的时候写入该RAM即可。

    为了调试,更新初始化数值就难了些,可供选择的方法有这样几种:

1. 采用In-system Memory Content Editor,通过Import File的方式把修改后的初始化文件更新到RAM中。

2. 采用Virtual JTAG定制一个RAM写入接口,连接到双端口RAM的一个空闲端口用于调试,双端口RAM的另一个端口用作正常使用。

3. 修改初始化文件,把初始化文件更新到编程文件中,通过重新下载更新到RAM中。

    第一种方法原理上没有任何问题,在MegaWizard Plug-in Manager中选择Allow In-system Memory Content Editor...即可。但是,在实际应用中,只有单端口ROM可以采用该方法;单端口RAM采用该方法可以生成代码,但是不能正确编译,总是报出一些奇怪的错误;此外。双端口的ROM和RAM都不支持In-system Memory Content Editor。

    第二种方法在本质上与第一种方法相同,在实际应用中也能正确编译,唯一的缺点是需要对Virtual JTAG有较深入的认识,需要手工编写一些代码,还要编写TCL脚本。

    第三种方法可以不修改代码,也不需要执行全编译,只要在Quartus II集成开发环境中执行两个简单的操作即可。下面就是具体的步骤:

1. Processing -〉Update Memory Initialization File

2. Processing -〉Start -〉Start Assembler

    上述操作执行完毕,把Assembler生成的编程文件下载到FPGA中,修改后的初始化文件就更新到片上存储器中了。

    该方法的原理是,在Update Memory Initialization File过程中,只更新db文件夹中与RAM初始化内容相关的文件,其余文件不更新,所以不需要执行全编译;更新后执行Assembler,把新的初始化内容更新到编程文件中去。该方法类似于软件编译过程中的部分编译和重新链接。

    该方法只适用于静态更新RAM内容,如果需要对RAM进行动态调试,还是用第二种方法才行。


(原文件名:20080128165456782.jpg)

出0入0汤圆

发表于 2011-3-22 10:06:04 | 显示全部楼层
matlab必须的,你这个生成器好像只能SIN COS??用matlab要什么信号都搞定,HEX什么的格式转换就OK,方便快捷,前提是你做过

出0入0汤圆

发表于 2011-3-22 10:17:33 | 显示全部楼层
我最近用vc做了一个

出0入0汤圆

发表于 2011-3-22 17:45:40 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-3-22 19:01:19 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-3-23 08:28:49 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-3-25 16:51:42 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-8-22 16:42:17 | 显示全部楼层
好东西留名

出0入0汤圆

发表于 2011-8-22 18:18:39 | 显示全部楼层
谢谢分享。

出0入0汤圆

发表于 2011-8-22 19:30:23 | 显示全部楼层
Best MIF tool!

出0入0汤圆

发表于 2011-8-23 12:07:30 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-8-23 21:51:15 | 显示全部楼层
Mark

出0入0汤圆

发表于 2011-10-10 22:46:46 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-10-10 23:03:49 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-10-12 01:30:46 | 显示全部楼层

出0入0汤圆

发表于 2011-12-21 10:45:28 | 显示全部楼层
这个只是生成什么波形,如果我是一幅图片呢?

出0入0汤圆

发表于 2011-12-21 11:54:25 | 显示全部楼层
先收藏吧!

出0入0汤圆

发表于 2011-12-21 11:56:47 | 显示全部楼层
我希望我尽快被批准啊
上次就被刷了.

出0入0汤圆

发表于 2011-12-22 11:08:51 | 显示全部楼层
MARK,感谢

出0入0汤圆

发表于 2011-12-30 16:06:30 | 显示全部楼层
mark

出0入9汤圆

发表于 2012-1-9 11:30:37 | 显示全部楼层
mark

出0入0汤圆

发表于 2012-2-2 15:13:26 | 显示全部楼层
顶一下哈

出0入0汤圆

发表于 2012-2-2 19:42:08 | 显示全部楼层
这个太详细了,支持支持!

出0入0汤圆

发表于 2012-2-2 23:21:41 | 显示全部楼层
mark!

出0入0汤圆

发表于 2012-2-16 16:37:25 | 显示全部楼层
多谢楼主分享!

出0入0汤圆

发表于 2012-3-6 22:03:01 | 显示全部楼层
mark

出0入0汤圆

发表于 2012-3-7 16:13:53 | 显示全部楼层
呵呵,这个有用

出0入0汤圆

发表于 2012-3-7 17:14:23 | 显示全部楼层
mark

出0入0汤圆

发表于 2012-4-8 22:33:14 | 显示全部楼层
太有用了,谢谢楼主

出0入0汤圆

发表于 2012-10-22 09:51:00 | 显示全部楼层
先mark,回头再看

出0入0汤圆

发表于 2012-12-6 13:40:20 | 显示全部楼层
这个必须得留名

出0入0汤圆

发表于 2013-2-28 16:06:09 | 显示全部楼层
mark....

出0入0汤圆

发表于 2013-3-1 09:57:20 | 显示全部楼层
一般都用matlab生成

出0入0汤圆

发表于 2013-3-1 13:30:17 | 显示全部楼层
貌似用excel也可以完成一些简单的。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 07:15

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表