Verilog HDL经典电路设计
1.1 全加器的设计
description:example of a one-bit full add
module FULLADDR(Cout,Sun,Ain,Bin,Cin);
input Ain,Bin,Cin;
output Sun,Cout;wire Sum;
wire Count;
assign Sum=Ain^Bin^Cin;
assign Cout=(Ain&Bin)|(Bin&Cin)|(Ain&Cin);
endmodule
1.2 数据通路
1.2.1 四选一的多路选择器
description::example of a mux4-1
module MUX(C,D,E,F,S,Mux_out);
input C,D,E,F,; //input
input [1:0] s; //select control
output Mux_out; //resultreg Mux_out; //mux
always@(C or D or E or F or S)
begincase(S)2`b00:Mux_out=C;2`b01:Mux_out=D;2`b10:Mux_out=f;default:Mux_out=S;endcase
end
endmodule
1.2.2 译码器
description:example of 3-8decoder
module DECODE(Ain,En,Yout);
input En; //input
input [2:0] Ain; //input code
output [7:0] Yout; reg [7:0] Yout;
always@(En or Ain)beginif(!En)Yout=8`0;elsecase(Ain)3`b000:Yout=8`b0000_0001;3`b001:Yout=8`b0000_0010;3`b010:Yout=8`b0000_0100;3`b011:Yout=8`b0000_1000;3`b100:Yout=8`b0001_0000;3`b101:Yout=8`b0010_0000;3`b110:Yout=8`b0100_0000;3`b111:Yout=8`b1000_0000;default:Yout=8`b0000_0000;endcaseend
endmodule
1.2.3 优先编码器
description:example of Priority encoder
module PRIO_ENCODE(Cin,Din,Ein,Fin,Sin,Pout);
input Cin,Din,Ein,Fin; //input signals
input [1:0] Sin; //input select contorloutput Pout; //output select resultreg Pout; //Pout assignment
always@(Sin or Cin or Din or Ein or Fin)
beginif(Sin==2`b00)Pout=Cin;else if(Sin==2`b01)Pout=Din;else if(Sin==2`b10)Pout=Ein;elsePout=Fin;
end
endmodule //module prio_encode
1.3 计数器
description:example of a counter with enable
module COUNT_EN(En,Clock,Reset,Out);
parameter Width =8;
parameter U_DLY=1;
input Clock,Reset,En;
output [Width-1:0] Out;reg [Width-1:0] Out;
always@(posedge Clock or negedge Reset)if(!Reset)Out<=8`b0;else if(En)Out<=#U_DLY Out+1;
endmodule
1.4 算术操作
description:example of a arithmetic include +-*/
module ARITHMETIC(A,B,Q1,Q2,Q3,Q4);
input [3:0] A,B; //input opeartor
output [4:0] Q1; //output sum,with carry bit
output [3:0] Q2; //output sutract result
output [3:0] Q3; //output quotion
output [7:0] Q4; //productreg [4:0] Q1;
reg [3:0] Q2,Q3;
reg [7:0] Q4; //arithmetic operatealways@(A or B)beginQ1=A+B;Q2=A-B;Q3=A/2;Q4=A*B;end
endmodule
1.5 逻辑操作
description:example of a relational operate
module RELATIONAL(A,B,Q1,Q2,Q3,Q4);
input [3:0] A,b; //operator
output Q1,Q2,Q3,Q4; //resultreg Q1,Q2,Q3,Q4; //comparealways@(A or B)beginQ1=A>B;Q2=A<B;Q3=A>=B;if(A<=B)Q4=1;elseQ4=0;end
endmodule
1.6 移位操作
description:example of a shifter
module SHIFT(Data,Q1,Q2);
input [3:0] Data;
output [3:0] Q1,Q2;parameter B=2;
reg [3:0] Q1,Q2;always@(Data)baginQ1=Data<<B;Q2=Data>>B;end
endmodule
1.7 时序器件
一个时序器件(指触发器或锁存器)就是一个一位存储器。锁存器是电平敏感存储器件,触发器是沿触发存储器件。
触发器也称寄存器,在程序中体现为对上升沿或下降沿的探测,Verilog中如下方式表示
(posedge Clk)——————上升沿
(negedge Clk)——————下降沿
下面给出不同类型触发器的描述
1.7.1 上升沿触发的触发器
description:example of a rising flip-flop
module DFF(Data, Clk,Q);
input Data,Clk;
output Q;reg Q;always@(posedge Clk)Q <= Data;
endmodule
1.7.2 带异步复位,上升沿触发的触发器
description:example of a rising edge flip-flop with asynchronous reset
module DFF_ASYNC_RST(Data,Clk,Rest,Q);
input Data,Clk,Reset;
output Q;parameter U_DLY=1;reg Q;always@(posedge Clk or negedge Reset)if(~Reset)Q <= #U_DLY 1`b0;elseQ <= #U_DLY Data;
endmodule
1.7.3 带异步置位,上升沿触发的触发器
description:example of a rising edge flip-flop with asynchronous preset
module DFF_ASYNC_PRE(Data,Clk,Preset,Q);
input Data,Clk,Preset;
output Q;
parameter U_DLY=1;
reg Q;
always@(posedge Clk or negedge Preset)if(~Prest)Q <= #U-DLY 1`b1;elseQ <= #U_CLY Data;
endmodule
1.7.4 带异步复位和置位,上升沿触发的触发器
description:example of a rising edge flip-flop with asynchronous reset and preset
module DFF_ASYNC(Data,Clk,Reset,Prest,Q);
input Data,Clk,Reset,Preset;
output Q;
parameter U_DLY=1;reg Q;always@(posedge Clk or negedge Reset or posedge Preset)if(~Reset)Q <= 1`b0;else if(Preset)Q <= 1`b1;elseQ <= #U_DLY Data;
endmodule
1.7.5 带同步复位,上升沿触发的触发器
description:example of a rising edge flip-flop with synchronous reset
module DFF_SYNC_RST(Data,Clk,Reset,Q);
input Data,ClK,Reset;
output Q;
parameter U_DLY=1;
reg Q;
always@(posedge Clk)if(~Reset)Q <= #U_DLY 1`b0;elseQ <= #U_DLY Data;
endmodule
1.7.6 带同步置位,上升沿触发的触发器
description:example of a rising edge Flip-Flop with synchronous preset
module DFF_SYNC_PRE(Data,Clk,Preset,Q);
input Data,Clk,Preset;
output Q;
parameter U_DLY=1;
reg Q;
always@(posedge Clk)if(~Preset)Q <= #U_DLY 1`b1;elseQ <= #U_DLY Data
endmodule
1.7.7 带异步复位和时钟使能,上升沿触发的触发器
description:example of a Rising Edge Flip-Flop with Asynchronous Reset
module DFF_CK_EN(Data,Clk,Reset,En,Q);
input Data,Clk,Reset,En;
output Q;
parameter U_DLY=1;
reg Q;always@(posedge Clk or negedge Reset)if(~Reset)Q <= 1`b0;else if(En)Q <= #U_DLY Data;
endmodule
1.8 ALU
description:example of a 4-bit Carry Look Ahead ALU
module ALU(A,B,Cin,Sum,Cout,Operate,Mode); //input signals
input [3:0] A,b; //two operands of ALU
input Cin; //carry in at the LSB
input [3:0] Operate; //determine f(.) of sum=f(a,b)
input Mode; //arithmetic(Mode=1`b1) or logic operation(Mode=1`b0)
output [3:0] Sum; //result of ALU
output Cout; //carry produced by ALU operation//carry generation bits and propogation bits.
wire [3:0] G,P;//carry bits ;
reg [2:0] C;//funtion for carry generation:
function geninput A,B;input [1:0] Oper;begincase(Oper)2`b00:gen=A;2`b01:gen=A&B;2`b10:gen=A&(~B);2`b11:gen=1`b0;endcaseend
endfunction//function for carry propergation:
function propinput A,B;input [1:0] Oper;begincase(Oper)2`b00:prop=1;2`b01:prop=A|(~B);2`b10:prop=A|B;2`b11:prop=A;endcaseend
endfunction//producing carry generation bits;
assign G[0]=gen(A[0],B[0],Oper[1:0]);
assign G[1]=gen(A[1],B[1],Oper[1:0]);
assign G[2]=gen(A[2],B[2],Oper[1:0]);
assign G[3]=gen(A[3],B[2],Oper[1:0]);//producing carry propogation bits
assign P[0]=pro(A[0],B[0],Oper[3:2]);
assign P[1]=Pro(A[1],B[1],Oper[3:2]);
assign P[2]=Pro(A[2],B[2],Oper[3:2]);
assign P[3]=Pro(A[3],B[3],Oper[3:2]);//producing carry bits with carry-look -ahead;
always@(G or P or Cin,Mode)beginif(Mode)beginC[0]=G[0]|P[0] & Cin;C[1]=G[1]|P[1] & G[0]|P[1] & P[0] & Cin;C[2]=G[2]|P[2] & G[1]|P[2] & P[1] & G[0]|P[2] & P[1] & P[0] & Cin;Cout=G[3]|P[3] & G[2]|P[3] & P[2] & G[1]|P[3] & P[2] & P[1] & G[0]|P[3] & P[2] & P[1] & P[0] & Cin;endelsebeginC[0]=1`b0;C[1]=1`b0;C[2]=1`b0;Cout=1`b0;endend//calculate the operation results;
assign Sum[0]=(~G[0]&P[0])^Cin;
assign Sum[1]=(~G[1]&P[1])^C[0];
assign Sum[2]=(~G[2]&P[2])^C[1];
assign Sum[3]=(~G[3]&P[3])^C[2];
endmodule
Verilog HDL经典电路设计相关推荐
- verilog hdl数字集成电路设计原理与应用_数字IC设计经典书籍推荐
数字IC设计流程很复杂,从前端到后端,也有很多职位.在这里整理了个数字IC各个环节的经典必读书籍.市面上的书籍种类纷繁复杂,这里每种只推荐两本左右,如果需要,建议知识类的书籍还是购买正版,尊重作者,也 ...
- (45)Verilog HDL 秒灯电路设计
(45)Verilog HDL 秒灯电路设计 1.1 目录 1)目录 2)FPGA简介 3)Verilog HDL简介 4)Verilog HDL 秒灯电路设计 5)结语 1.2 FPGA简介 FPG ...
- 数字集成电路设计(二、Verilog HDL基础知识)
文章目录 1. 语言要素 1.1 空白符 1.2 注释符 1.3 标识符 1.3.1 转义标识符 1.4 关键字 1.5 数值 1.5.1 整数及其表示方式 1.5.2 实数及其表示方式 1.5.3 ...
- 基于 Verilog 的经典数字电路设计(12)串并转换器
基于 Verilog 的经典数字电路设计(12)串并转换器 版权所有,新芯设计,转载文章,请注来源 引言
- 基于 Verilog 的经典数字电路设计(13)并串转换器
基于 Verilog 的经典数字电路设计(13)并串转换器 版权所有,新芯设计,转载文章,请注来源 引言
- 【FPGA】分频电路设计(Verilog HDL设计)(良心博文)
目录 前言 分频器分类 偶分频 奇分频 占空比为50%的奇分频 占空比不限定的奇数分频器 前言 虽然在实际工程中要产生分频时钟一般采用FPGA的时钟管理器来进行分频.倍频,通过设置一下IP核中的参数即 ...
- 数字集成电路设计(三、Verilog HDL程序设计语句和描述方式)(一)
文章目录 1. 数据流建模 1.1 连续赋值语句 2. 行为级建模 2.1 过程语句 2.2 语句块 2.3 过程赋值语句 **!!!小结** 2.4 过程连续赋值语句 2.5 条件分支语句 2.5. ...
- 数字集成电路设计(四、Verilog HDL数字逻辑设计方法)(一)
文章目录 1.Verilog语言的设计思想和可综合特性 2. 组合电路的设计 2.1 数字加法器 2.2 数据比较器 2.3 数据选择器 2.4 数字编码器 2.4.1 3位二进制8线-3线编码器 2 ...
- 数字集成电路设计(一、Verilog HDL数字集成电路设计方法概述)
文章目录 集成电路发展 HDL产生 HDL分类 Verilog HDL的发展 Verilog HDL与VHDL Verilog HDL在数字集成电路设计中的优点 组合逻辑电路原理图设计和Verilog ...
最新文章
- 我把 Spring Boot 的 banner 换成了美女,老板说工作不饱和,建议安排加班
- 宁波海关连续查获走私白糖1700余吨
- JAVA中的list去重复
- 在x86上成功使用gentoo系统上安装的grub2启动 Mac OS X Leopard 10.5.7
- 【C++】19. 深入 char * ,char ** ,char a[ ] ,char *a[] 内核
- python socket发送组播数据_Python socket 如何实现广播单播切换
- 【附10】kibana创建新的index patterns
- poj 2914(stoer_wanger算法求全局最小割)
- java监控数据库性能_Java:GraalVM数据库流性能
- netflix的准实验面临的主要挑战
- ros机器人写字,svg图片绘制,二三阶贝塞尔计算公式转代码
- 1-2+3-4+......+99 除去88的和
- 【3月22日】2022年百度机器学习春实习笔试题解
- idea开发springboot的一些小干货
- Boxy vehicle detection 数据集
- 数据中心的“风火水电”
- 云服务器中的mac地址是什么?
- 线性代数A矩阵乘以A的转置的含义或者几何意义
- 给武则天找凤凰的java游戏_武则天称帝时,改国号为
- android输入过滤回车换行,Android实现输入框回车输入