MATLAB生成*.mif、*.hex2008-08-31 03:06做FPGA设计时经常要调用芯片内存。特别对于ROM,内存的初始化就显得比较重要。当然你完全可以手工在QUARTUS II打开mif文件的表格里或是在EXCEL中逐个输入,几十项(字)或是近百项(字)你还可以接受,如果上千项或是更多呢?估计能累的人吐血! ; a; J# p: d' d" p8 ]& x$ i* b5 L 2 H! D% I& K3 b" F9 M一般内存的初始化数据都是有规律的,符合一定的函数,我们完全可以用MATLAB来完成(如果没规律只能逐项手工输入了)。1 J% o. s, G5 l0 K) H2 p& I) K# Q* X
# @- P# I/ U" s首先,我们应该知道*.mif文件的格式。它是文本格式。随便打开一个mif文件,你会发现它具有如下的格式:& b; m4 {/ V% f7 m: {
7 L. t, I" l% r: k0 F6 V
2 v( j( ~, w" s+ y" s \' c) j
-- 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; 2 K: v" b9 I# j5 I
格式很简单吧。首先根据需要设置每个字的位宽WIDTH和总字数DEPTH。然后设置地址和数据的进制基数ADDRESS_RADIX、DATA_RADIX,建议大家不要修改,就使用无符号数(UNS)。然后用MATLAB生成需要的数据(按上边的格式,注意中间“:”,最后“;”),往CONTENT BEGIN和END中间一贴就行了。) i0 I: p |4 H: o- L
( b+ f% P: `6 R1 }7 ~0 i下边举例说明MATLAB程序的写法,希望对大家有用7 P. I5 u& I3 v9 e! R8 R