集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2803|回复: 3

如何初始化LPM_ROM

[复制链接]
usd 发表于 2010-6-26 02:50:06 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-7-11 11:55 编辑

怎么初始化LPM_ROM,数据位为8位.深度为256,怎么用C语言或是MATLAB编写MIF文件
ICE 发表于 2010-6-26 04:14:15 | 显示全部楼层
#include "stdio.h"<br>
#include "math.h"<br>
#define N 256&nbsp; &nbsp;&nbsp;&nbsp;/* N is the DEPTH of the table(数据个数也就是一个周期采样点数)*/<br>
#define P 8&nbsp; &nbsp;&nbsp; &nbsp;/* P is the Precision of data in the table(数据精度也就是一个数据的位数)*/<br>
void main()<br>
{<br>
FILE *fp;<br>
double y,bias,amp;<br>
int n,i;<br>
if((fp=fopen("sindata.mif","w"))==NULL)<br>
&nbsp; &nbsp;{printf("cannot open this file\n");<br>
&nbsp; &nbsp; exit(0);<br>
&nbsp; &nbsp;}<br>
fprintf(fp,"WIDTH=P;\n");<br>
fprintf(fp,"DEPTH=N;\n");<br>
fprintf(fp,"ADDRESS_RADIX=DEC;\n");<br>
fprintf(fp,"DATA_RADIX=DEC;\n");<br>
fprintf(fp,"CONTENT BEGIN\n");<br>
bias = amp = pow(2,P-1);&nbsp; &nbsp; /* pow(x,y)表示x的y次方*/<br>
i=1;<br>
for(n=0;n&lt;=N-1;n++,i++)<br>
&nbsp; &nbsp; {y=bias+amp*sin(n*3.1415936535/(N/2));<br>
&nbsp; &nbsp;&nbsp;&nbsp;if(fmod(n,N)==0)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;/* fmod(n,N)表示计算n/N的余数 */<br>
&nbsp; &nbsp;&nbsp; &nbsp; {fprintf(fp,"\n");}<br>
&nbsp; &nbsp;&nbsp;&nbsp;if(fmod(i,16)==1) {fprintf(fp,"\n%04x %04x: ",i,n);}<br>
&nbsp; &nbsp;&nbsp;&nbsp;fprintf(fp,"%04x",y);<br>
&nbsp; &nbsp; }<br>
&nbsp; &nbsp; fprintf(fp,"\nEND;");<br>
&nbsp; &nbsp; fclose(fp);<br>
}
usb 发表于 2010-6-26 06:08:53 | 显示全部楼层
同问同问啊
Sunlife 发表于 2015-6-17 10:56:35 | 显示全部楼层
fprintf(fp,"WIDTH=P;\n");<br>
fprintf(fp,"DEPTH=N;\n");<br>
fprintf(fp,"ADDRESS_RADIX=DEC;\n");<br>
fprintf(fp,"DATA_RADIX=DEC;\n");<br>
fprintf(fp,"CONTENT BEGIN\n");<br>
bias = amp = pow(2,P-1);&nbsp; &nbsp; /* pow(x,y)表示x的y次方*/<br>
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 03:31 , Processed in 0.061513 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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