应用matlab&modelsim设计FPGA算法(1)

最近 的项目需要应用FPGA,以前做过matlab与FPGA的算法设计,拿出来分享一下。

传统的fpga算法设计需要进行c语言建模,并且用c语言建立激励,再通过modelsim单独进行算法设计,并且在modelsim中也要设计激励文件,再通过c语言与modelsim的比较进行验证,研发周期非常长。

我在工作中比较喜欢偷懒,觉得这个过程太繁琐了,并且因为自己是自动化电动机出身,对matlab的感情,就跟自己的亲人似的,以前用matlab做电动机的仿真,非常省时省力,而且基于matlab的设计似乎从来没有失败过。

1.工具介绍

1.1 matlab

matlab的出现把算法设计简化到了只用拖动一些模块,就可以完成,这一点极大的提高了效率,并且他的仿真功能也真的很牛,无论你是仿真1万伏的电动机,还是仿真最尖端的航天飞机,他都能把最合适的模型输入到你的电脑中。

本文应用的事matlab2013a

废话不说。

1.2 modelsim

modelsim时mentor graphics公司开发的EDA工具软件,主要针对IC设计的仿真阶段,即采用verilog HDL描述进行设计验证。属于IC设计的仿真验证阶段。

本文应用的是modelsim10.1a

2.步骤

2.1 新建一个文件夹,把设计好的verilog文件放进去。

2.2 运行matlab,进入到新建的文件夹中。

2.3 matlab中运行cosimWizard

2.4 配置联合仿真项目

(1) cosimulation type  选项卡

选择进行联合仿真的工具 分别位matlab和modelsim,选择 use HDL simulator excutables on system path。

(2) HDL files

选择添加进行仿真的HDL文件。

(3)HDL compilation commands

填写HDL的编译命令。

(4)HDL modules

选择需要进行编译的模块,进行完这一步,程序将lanch modelsim程序,并载入所确定的模块。

(5)input/output prot

这里确定输入输出接口,clk和reset分别对应Clock和Reset

(6)output port Detaile

这里确定输出信号的采样时间与数据类型。

(7)clock/reset detail

这里确定clocks信号的周期,以及reset信号的持续时间和初始值

(8)start time

这里确定matlab进行联合仿真的起始,通常会慢于modelsim仿真开始的时间。

(9)block gengeration

产生联合仿真模型。

2.5进行完之前的步骤后,就可以进行联合仿真了。

(1)首先贴出来我的verilog源代码

module butterfly
(
clk,rst_n,reset,ina,inb,inc,ind,ine,inf,out1,out2,out3,out4,outen
); 

input clk;
input rst_n;
input reset;
input   signed [23:0] ina,inb,inc,ind;
input signed [15:0] ine,inf;
output  signed [23:0] out1,out2,out3,out4;
output outen;
reg outen1;
reg signed [39:0] temp1a,temp2a,temp3a,temp4a;
wire signed [23:0] temp1,temp2,temp3,temp4;
assign outen = outen1;
always @(posedge clk or negedge rst_n)
if((!rst_n)||(reset))
begin
temp1a <= 0;
temp2a <= 0;
temp3a <= 0;
temp4a <= 0;
  <= 0;
end
else if(outen==0)
begin
temp1a = inc * ine;
temp2a = ind * inf;
temp3a = ind * ine;
temp4a = inc * inf;
outen1 = 1;
end
assign temp1 = temp1a[38:15];
assign temp2 = temp2a[38:15];
assign temp3 = temp3a[38:15];
assign temp4 = temp4a[38:15];

assign out1 = (outen)?(ina + temp1 - temp2):0;
assign out3 = (outen)?(ina - temp1 + temp2):0;
assign out4 = (outen)?(inb - temp3 - temp4):0;
assign out2 = (outen)?(inb + temp3 + temp4):0;

endmodule

这一段代码时计算FFT时,蝶形运算所应用的代码。

下图为联合仿真的simulink模块。

其中ina~inf分别对应x(1)+x(2)j,x(3)+x(4)j,以及FFT算子。

在simulink中对应分别对应constant模块,其中x(n)中的constant模块“output date type”设计为fixdt(1,24,15),而算子中的constant模块的“output date type”则设计fixdt(1,16,15)。

display模块设计为“HEX”,用于显示输出。

3。总结

通过对matlab的灵活应用,可以避免c语言实现算法的繁琐过程,并且输入输出都可以用模块拖动进行处理,极大的节省了效率,开发出来的fpga代码又快又好,值得推广。

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值