FPGA 模块代码的 开发过程

27
FPGA 模模模模模 模模模模 以 FIR48 以以以以以以

description

FPGA 模块代码的 开发过程. 以 FIR48 阶滤波器为例. Outline. Model Design specification Data path and controller design Test bench Synthesis and timing simulation. model. FIR 滤波器结构说明图. FIR Coefficients ( IS-2000 规范). Matlab simulation. Fix-point Coefficients and simulation. Outline. Model - PowerPoint PPT Presentation

Transcript of FPGA 模块代码的 开发过程

Page 1: FPGA 模块代码的 开发过程

FPGA模块代码的开发过程以 FIR48 阶滤波器为例

Page 2: FPGA 模块代码的 开发过程

Outline Model Design specification Data path and controller design Test bench Synthesis and timing simulation

Page 3: FPGA 模块代码的 开发过程

model

1z

1z

)0(h

1z

1z

)1(h

1z

1z

)2(h )1( 2 Nh

1z

1z

)2( 2 Nh

)(nx

)(ny

FIR 滤波器结构说明图

Page 4: FPGA 模块代码的 开发过程

FIR Coefficients( IS-2000规范)

Page 5: FPGA 模块代码的 开发过程

Matlab simulation

0 5 10 15 20 25 30 35 40 45 50-1

0

1

h(n) n

0 1 2 3 4 5 6 70

5

frequency red

0 1 2 3 4 5 6 7-5

0

5

phase red

Page 6: FPGA 模块代码的 开发过程

Fix-point Coefficients and simulation

Page 7: FPGA 模块代码的 开发过程

0 5 10 15 20 25 30 35 40 45 50-1

0

1x 10

4

h(n) n

0 1 2 3 4 5 6 70

2

4x 10

4

frequency red

0 1 2 3 4 5 6 7-5

0

5

phase red

Page 8: FPGA 模块代码的 开发过程

Outline Model Design specification Data path and controller design Test bench Synthesis and timing simulation

Page 9: FPGA 模块代码的 开发过程

Design Specification 1, Function 48阶 fir 滤波器,可同时进行 I, Q 两路处理 2, Input clk ,系统时钟 reset ,系统复位 data_valid ,输入有效指示 din_i, I 路数据输入端 din_q, Q 路数据输入端

Page 10: FPGA 模块代码的 开发过程

3, Output fir_i, I 路数据输出端 fir_Q, Q 路数据输出端 out_valid ,输出有效指示 4, Timing 当 data_valid 有效时, I, Q 两路同时输入缓存,然后用内部信号 clk_en 来选择数据通道( datapath )处理哪一路。

Page 11: FPGA 模块代码的 开发过程

本程序中,对 data_valid 的时序有一定的要求:输入端 data_valid 占空比为 1/N( 其中 N 为大于一的整数,即 N= 2, 3,4……) ,频率为 fclk/N 。只要 data_valid符合上述要求,本程序都可以有效工作。

当 out_valid 有效时,输出端fir_i, fir_q 有效。

Page 12: FPGA 模块代码的 开发过程

时序图

Page 13: FPGA 模块代码的 开发过程

Outline Model Design specification Data path and controller design Test bench Synthesis and timing simulation

Page 14: FPGA 模块代码的 开发过程

Data path and controller design

Data_valid controller

Data_out

Out_valid

Data_indatapath

Page 15: FPGA 模块代码的 开发过程

Data path design 1. 查找表模块 本部分包括 6 个查找表,用来保存 24 个系数的部分和。查找表的输入数据为 din 的相应位的组合。输出为对应部分和。 2. 部分和模块 本部分对查找表的输出进行处理,主要是符号扩展和移位相加。以查找表的输出作为自己的输入,并输出 din 与对应系数的乘积。

Page 16: FPGA 模块代码的 开发过程

16X10LUT

16X10LUT

16X10LUT

16X10LUT

16X10LUT

16X10LUT

16X10LUT

16X10LUT

16X10LUT

16X10LUT

Sign expand

Pipeline_Register

Pipeline_Register

Pipeline_Register

Z(n)

Pipeline_Register

S(0)

S(1)

S(2)

S(3)

LSB

LSB

LSB

LSB

16Bit 16Bit 16Bit 16Bit 16Bit 16Bit 16Bit 16Bit 16Bit16Bit

26Bit 26Bit 26Bit 26Bit26Bit 26Bit26Bit 26Bit 26Bit 26Bit

26Bit

Right Shift1Bit

Right Shift1Bit

Right Shift1Bit

Right Shift1Bit

Right Shift1Bit

Right Shift2Bit

Right Shift2Bit

Right Shift4Bit

Right Shift8Bit

10Bit

10Bit

10Bit

10Bit

Page 17: FPGA 模块代码的 开发过程

3. 主模块

两个48位移位寄存器

data_valid

dini

dinq

dini48

dinq48

两个24位移位寄存器

din_i

din_q

48个系数偶对称,所以对48位数据进行折叠简化运算

依次将48个输入数据存入寄存器,准备和48个新数相乘

Page 18: FPGA 模块代码的 开发过程

两路选择If(clk_en)i路输入

else q路输入

clk_en

din_i

din_q

部分和模块

用3个时钟周期对6个部分结果进行相加并取其高15

用1个时钟对结果进行限幅使结果小于214大于-214-1

if(clk_en)i路输出else q路输出 fir_i

fir_q

Page 19: FPGA 模块代码的 开发过程

Controller design

clk_en=0

data_valid=1

启动clk_en,clk_en为2倍分频器

延时13个clk out_valid=data_valid

reset

if(!reset)

else @(posedge clk)

Page 20: FPGA 模块代码的 开发过程
Page 21: FPGA 模块代码的 开发过程

Outline Model Design specification Data path and controller design Test bench Synthesis and timing simulation

Page 22: FPGA 模块代码的 开发过程

Test bench

Test bench 的测试过程如下: 1 ,用 matlab 生成输入数据文件,并仿真生成参考输出数据文件。 Modelsim 内 2 ,读取输入数据文件,设置适当类型的变量存放这些数据。 3 ,设定模块输入信号的初值,比如: clk, reset 等。 4 ,指定输入信号的变化规律,比如: clk 的周期, reset 何时变化等。 5 ,调用待测试模块。 6 ,当输出信号有效时,采集输出信号,并存入输出数据文件。 7 ,用其他工具( matlab, ultraedit 等)将参考输出数据文件与输出数据文件进行比较。

Page 23: FPGA 模块代码的 开发过程

注意: 一,以上这些部分有些是顺序执行,有些则是并行执行,根据具体情况而定。 二,我们得到输出数据后,还需要将这些数据与 matlab 仿真结果进行逐比特对比,观察数据是否正确。 三,有些情况下逐比特比较结果不可行,那就要根据具体情况设计检验方法,在通信中常用的方法还有信噪比检验法。

Page 24: FPGA 模块代码的 开发过程

Outline Model Design specification Data path and controller design Test bench Synthesis and timing simulation

Page 25: FPGA 模块代码的 开发过程

Synthesis 我们使用相关工具进行综合(本设计使用 Quartus I

I ),我们主要关注面积和系统频率两方面。 面积:我们希望电路所占面积尽可能小,本设计综合后 Logic Cells 的数目为 4681

系统频率:系统工作速度要尽可能快,本系统要求工作频率 50MHz ,但实际工作频率可达到236.57MHz(period = 4.227 ns )

Page 26: FPGA 模块代码的 开发过程

Timing Simulation 这部分是时序仿真,即在前面功能仿真基础上,加上延时信息进行仿真。 综合后会有两个文件生成( .vo和 .sdo) , 我们用这两个文件以及功能仿真时所用的

Testbench ,进行时序仿真。 时序仿真和功能仿真的结果应该完全一致。

Page 27: FPGA 模块代码的 开发过程

Thank you!