3、设计一个带有异步复位控制端和时钟使能控制端的10进制计数器。 端口设定如下: 输入端口:CLK:时钟,RST:复位端,EN:时钟使能端,LOAD:置位控制端, DIN:置位数据端; 输出端口:COUT:进位输出端,DOUT:计数输出端。 module CNT10 (CLK,RST,EN,LOAD,COUT,DOUT,DATA); input CLK ; input EN ; input RST ; input LOAD ; input [3:0] DATA ; output [3:0] DOUT ; output COUT ; reg [3:0] Q1 ; reg COUT ; assign DOUT = Q1;
always @(posedge CLK or negedge RST) begin if (!RST) Q1 <= 0; else if (EN) begin
if (!LOAD) Q1 <= DATA; else if (Q1<9) Q1 <= Q1+1; else Q1 <= 4'b0000; end end
always @(Q1)
if (Q1==4'h9) COUT = 1'b1; else COUT = 1'b0; endmodule
4、下面是通过case语句实现四选一电路部分程序,将横线上的语句补上,使程序形成完整功能。
case({s1,s0}) 2’b00:out=i0; 2’b01:out=i1; 2’b10:out=i2;
2’b11:out=i3;
3、标注各语句功能,指出整个程序完成的电路功能。 // 带同步清0/同步置1(低电平有效)的D触发器.
module dff_syn(q,qn,d,clk,set,reset); //定义模块为diff_syn, 端口为q,qn,d,clk,set,reset input d,clk,set,reset; output reg q,qn; //定义端口d,clk,set,reset为输入端口,reg,q,qn为输出端口
always @(posedge clk) //对clk信号上升沿有效 begin
if(~reset) begin q<=1'b0;qn<=1'b1;end //同步清零,低电平有效
else if(~set) begin q<=1'b1;qn<=1'b0;end //同步置位, 低电平有效 else begin q<=d; qn<=~d; end //q输出为d, qn输出为非d; end
endmodule //模块结束
4、根据图3给定的两个2位全加器信号关系及实现的4位全加器功能部分程序,在下列部分程序中的横线上填入必要语句,实现4位全加器的完整功能。 sum4(3..2) a(3..2) ai sum )) b(3..2) bi 2位加法器 cout4 cout c0 ci a(1..0) ai sum4(1..0) sum b(1..0) bi 2位加法器 cout c ci 图3 //底层4位全加器程序 //顶层8位全加器程序 module add2(ai,bi,ci,sum,cout); module fadd4(a,b,c,sum4,cout4); input [1:0]ai,bi;input ci; input [3:0]a,b;input c; output [1:0]sum;__________; output [3:0] sum4output cout4; output cout;_________; wire c0; always @(___________) add4 U1( ); {cout,sum}=ai+bi+ci; add4 U2( ); endmodule endmodule
5、根据下列给定的仿真输入输出波形图2,说明完成此功能的电路是什么功能电路?并写出对应的Verilog HDL描述程序(图中clk,clr为输入,q,c为输出)。 4进制加法计数器
module counter(clk,clr,q,c) input clk,clr; output ret[1:0] q; output c;
always@(posedge clk or negedge clr) begin
if(~clr) q<=2’h0; else begin
if(2’h3==q) q<=2’h0; else q<=q+2’h1; end end
assign c=(2’h3==q) endmodule
6、采用结构描述方法设计一个二进制数字半加器,输入数据ai与bi,并将和输出到so,进位输出到co,给出详细设计过程。 输入 ai 0 0 1 1 bi 0 1 0 1 so 0 1 1 0 输出 co 0 0 0 1
so?aibi?aibi?ai?bi,co?aibi
由输入输出逻辑表达式,采用与门and和异或门xor进行结构描述的程序如下:(6分) module hadd (ai,bi,so,co); input ai,bi; output so,co; xor(so,si,ci); and(co,ai,bi); endmodule
6、采用结构描述方法设计一个二进制数字比较器,比较输入数据a与b的大小,并分别输
出到x,y和z,给出详细设计过程。
x?ab?ab,y?ab,z?ab
not(not_a,a); not(not_b,b); and(ab,a,b);
and(not_ab,not_a,not_b); or(x,ab,not_ab); and(y,not_a,b); and(z,a,not_b);
7、采用结构描述方法设计一个3人竞选数字电路,输入数据[2:0]x,要求2人以上为1表示通过,且输出为y为1,否则输出相反,给出详细设计过程。