学习FPGA的心得
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
学习FPGA的心得
一:设计规范:1,文件名必须体现模块的功能
2,时钟信号clk和低电平有效的信号(低电平有效*_n) 3,parameter和`define 进行宏定义和定义参数是,
名字要大写
4,信号,端口,模块,例话(代码最好小写)
5,一般字符的命名长度不应超过32个
6模块调用实体名的设定 mux4 u_mux4_1(....)
7,位宽【x:0】
8,begin和end,case和endcase。。。的对齐问题
9,原理图输入时,当有文本输入和原理图输入时,原
理图作为顶层文件,最好采用页面水平分层结构
10,阻塞(=)和非阻塞(>=)的问题
阻塞计算完立刻赋值,而非阻塞计算后不立刻赋值,
而是一起赋值,组合逻辑(阻塞赋值),时序逻辑(非
阻塞),既有时序又有组合是使用(非阻塞)
11,敏感信号列表(影响模块的输出和状态)
12,复位和初始化
13,输出设为reg
14.verilog中reg与integer的区别首先,integer和 reg与w i r e最大的差別是,integer本身是个32位元的有
号数,含正负。其次,integer消耗的资源也比多。
二:分频器(]frequency divider)
Module div_10(clk_50,f_10,rst_n);
Input clk_50;
Input rst_n;
Output f_10;
Reg [2:0] cnt;
Reg f_10;
Always @(posedge clk or negedge rst_n) If(!rstn)
Cnt<=3’b0;
F_10<=0;
Else
Begin
If(cnt==3’b100)
begin
Cnt<=0;
F_10<=~f_10;
end
Else
Begin
Cnt<=cnt+3’b1;
end
End
Endmodule
三:计数器(counter)
Module counter(clk,rst_n,s,q,en,d,co); Input clk;
Input rst_n;
Input en;
Input [3:0] d;
Output [3:0] q;
Output co;
Reg co;
Reg [3:0] q;
Always @(posedge clk or negedge rstn) If(!rst_n)
begin
q =0;
end
Else
Begin
If(s)
Begin
q=d;
End
Else
If(en)
Begin
q=q+4’b1;
If(q==4’b1111) Begin
Co=1;
End
Else
Begin
Co=0;
end
end
else
Begin
Q=q;
End
End
Endmodule
四:D触发器(D_Trigger)
Module D_Trigger(clk,rst_n,q,qn,s,d); Input clk,rst_n,s,d;
Output q,qn;
Reg q,qn;
Always @(posedge clk)_
If({rst_n,s}==2’b01)
begin
Q=1’b0;
Qn=1’b1;
end
Else
If({rst_n,s}==2’b10)
begin
Q=1’b1;
Qn=1’b0;
end
Else
If({rst_n,s}==2’b11)
begin
Q=d;
Qn=~d;
End
Endmodule
五:三态门( triple gate)
Module tri(din,dout,en);
Input din,en;
Output dout;
Assign dout=en?din:’bz; Endmodule
六:编码器(encoder)
Module 8_3encoder(din,dout);
Input [7:0] din;
Output [2:0] dout;
Reg [2:0] dout;
Always @(din)
Begin
Case(din)
8’b0000 0001: dout=3’b000; 8’b0000 0010: dout=3’b001;
8’b0000 0100: dout=3’b010; 8’b0000 1000: dout=3’b011; 8’b0001 0000: dout=3’b100;
8’b0010 0000: dout=3’b101;
8’b0100 0000: dout=3’b110;
8’b1000 0001: dout=3’b111;
Defult: dout=3’dzzz;
Endcase
end
Endmodule
优先编码器(priority encoder)
Module coder_42(in,out);
Input [3:0] in;
Output [1;0] out;
Always @(in)
Begin
Case(in)
4’b1000:out=2’b00;
4’bx100:out=2’b01;
4’bxx10:out=2’b10;
4’bxxx1:out=2’b11;