硬件描述语言上机作业
更新时间:2024-06-02 23:50:01 阅读量: 综合文库 文档下载
第一题:
用Verilog语言的结构描述和行为描述分别设计下面的电路。
A[0]B[0]A[1]B[1]A[2]B[2]
结构描述: 设计代码: module equal(y,a,b); input[2:0] a,b; output y; wire w1,w2,w3; xor U1(w1,a0,b0), U2(w2,a1,b1), U3(w3,a2,b2); nor U4(y,w1,w2,w3); endmodule 仿真代码: `timescale 1ns/1ns module equal_clk; reg[5:0]c;
equal U1(.y(y),.a({c5,c4,c3}),.b({c2,c1,c0})); initial begin
c=6'b000_000; forever #2 c=c+1; end
initial #500 $finish; initial
$minitor($time,\1,c0},y);
endmodule 行为描述: 设计代码:
module compare1(equal,a,b); input[2:0] a,b;
output equal;
assign equal=(a==b)?1:0; endmodule 仿真代码: `timescale 1ns/1ns module compare1_clk; reg[5:0]c; Y compare1 U(.equal(equal),.a({c[5],c[4],c[3]}),.b({c[2],c[1],c[0]}
)); initial begin
c=6'b000_000; forever #2 c=c+1; end
initial #300 $finish; initial $monitor($time,\
{c[5],c[4],c[3]},{c[2],c[1],c[0]},equal);
endmodule
第二题:参数化电路设计
1. 用行为描述方式实现下图所示的具有
“one-hot”(独热)状态的环形计数器。要求使用参数化的模块。 parameter SIZE =3; input clock, reset; output [SIZE-1:0]counter;
说明:低电平同步复位,此时counter最低位为“1”,其余位均为“0”。 DQDQDQ001resclketcounter[2counter[1counter[0]]]
2. 编写测试程序来验证该模块的正确性,要求测
试对象是一个5位的独热状态环形计数器。
设计代码:
module one_hot(counter,clock,reset); parameter SIZE =3; input clock, reset; output [SIZE-1:0]counter; reg [SIZE-1:0]counter; always @(posedge clock) if(!reset)
counter<=8'b0000_0001; else
counter<={counter[0],counter[SIZE-1:1]}; endmodule 仿真代码: `timescale 1ns/1ns module one_hot_five; reg clk,rst; wire [4:0] cnt;
one_hot #(5) U1(.counter(cnt),.clock(clk),.reset(rst)); initial begin clk=0;rst=1; #2 rst=0;#5 rst=1; end
always #5 clk=~clk; initial #600 $finish; initial
$monitor($time,\nt,clk,rst); endmodule 第三题:
1·用DFF实现二分频
设计代码:
module div2(clk_in,rst,clk_out);
input clk_in,rst; output clk_out; reg clk_out;
always @(posedge clk_in or negedge rst) begin if(!rst) clk_out<=0; else
clk_out<=~clk_out; end endmodule 仿真代码: `timescale 1ns/1ns module div2_tb; reg clock_in,reset; div2
U1(.clk_out(clock_out),.clk_in(clock_in),.rst(reset)); initial begin clock_in=0; reset=1; #100 reset=0; #200 reset=1; #1000 reset=0; #500 reset=1; end
always #50 clock_in=~clock_in; initial
$monitor($time,\ck_in,reset,clock_out); endmodule
2·十进制计数器 设计代码:
module comp_10(count,clk,reset); output[3:0]count; input clk,reset; reg[3:0]count;
always@(posedge clk or negedge reset) if(reset) count<=4'b0000; else if(count==4'b1001) count<=4'b0000; else
count<=count+1; endmodule 仿真代码: `timescale 1ns/1ns module comp_10_tb; reg clk,reset; wire[3:0]count;
comp_10 U1(.count,.clk,.reset); always #10 clk=~clk; initial begin
clk=0;reset=0; #100 reset=1; #200 reset=0; #1000 reset=1; end initial
$minitor($time,\lk,reset); endmodule 第四题 1·五人投票
A,B,C,D,E进行投票,多数服从少数,输出是F(也就是如果A,B,C,D,E中1的个数比0多,那么F输出为1,否则F为0),用与非门实现,输入数目没有限制。 设计代码:
module vote(a,b,c,d,e,f); input a,b,c,d,e; output f;
wire w1,w2,w3,w4,w5,w6,w7,w8,w9,w10; nand U1(w1,a,b,c); nand U2(w2,b,c,d); nand U3(w3,c,d,e); nand U4(w4,d,e,a); nand U5(w5,e,a,b); nand U6(w6,a,b,d); nand U7(w7,b,c,e); nand U8(w8,a,c,d); nand U9(w9,a,c,e); nand U10(w10,b,d,e);
nand U11(f,w1,w2,w3,w4,w5,w6,w7,w8,w9,w10);
Endmodule 仿真代码: `timescale 1ns/1ns module vote_tb; reg [4:0] z; vote
U1(.f(F),.a(z[4]),.b(z[3]),.c(z[2]),.d(z[1]),.e(z[0])); initial begin z=5'b0000; forever #2 z=z+1; end
initial #1000 $finish; initial
$monitor($time,\b\endmodule 2·四数比较
设a,b,c,d四个数,按从小到大的顺序重新排列并输出到ra,rb,rc,rd中。需在Verilog HDL描述中使用任务(task)。
设计代码:
module rank(a,b,c,d,ra,rb,rc,rd); input [3:0] a,b,c,d; output [3:0] ra,rb,rc,rd; reg [3:0] ra,rb,rc,rd; reg [3:0] H1,H2,H3; reg [3:0] L1,L2,L3; always @(a or b or c or d) begin
rank(a,b,L1,H1); rank(c,d,L2,H2); rank(L1,L2,ra,H3); rank(H1,H2,L3,rd); rank(H3,L3,rb,rc); end task rank;
input [3:0] A,B; output [3:0] C,D; begin
C=(A
end endtask endmodule 仿真代码: module rank_tb; reg [3:0] a,b,c,d; wire [3:0] ra,rb,rc,rd; initial begin next=ST00; news<=3'b000; return<=3'b000; end 3'b001:begin next=ST01; news<=0; return<=3'b000; end a={$random}; b={$random}; c={$random}; d={$random}; repeat(8)#100
a={$random}; b={$random}; c={$random}; d={$random};
end
rank U1(.ra,.rb,.rc,.rd,.a,.b,.c,.d); initial
$monitor($time,\ %d,rc=%d,rd=%d\ endmodule 第五题 1·卖报机
设计一个接受1,2,5分钱的卖报机,每份报纸5 分钱,并考虑找零。 设计代码:
module auto_newsy(coin,return,news,clk,rst); input [2:0]coin; input clk,rst; output [2:0]return; output news;
reg [2:0]state,next,return; reg news; parameter
ST00=3'B000,ST01=3'B001,ST02=3'B010,ST03=3'B 011,ST04=3'B100;
always @(state or coin) case(state) ST00:case(coin) 3'b000:begin
3'b010:begin next=ST02; news<=0; return<=3'b000; end 3'b101:begin next=ST00; news<=1; return<=3'b000; end endcase ST01:case(coin) 3'b000:begin next=ST01; news<=0; return<=3'b000; end 3'b001:begin next=ST02; news<=0; return<=3'b000; end 3'b010:begin next=ST03; news<=0; return<=3'b000; end 3'b101:begin next=ST00; news<=1; return<=3'b001; end endcase ST02:case(coin) 3'b000:begin
next=ST02; news<=0; return<=3'b000; end 3'b001:begin next=ST03; news<=0; return<=3'b000; end 3'b010:begin next=ST04; news<=0; return<=3'b000; end 3'b101:begin next=ST00; news<=1; return<=3'b010; end endcase ST03:case(coin) 3'b000:begin next=ST03; news<=0; return<=3'b000; end 3'b001:begin next=ST04; news<=0; return<=3'b000; end 3'b010:begin next=ST00; news<=1; return<=3'b000; end 3'b101:begin next=ST00; news<=1; return<=3'b011; end endcase ST04:case(coin) 3'b000:begin
next=ST04; news<=0; return<=3'b000; end 3'b001:begin next=ST00; news<=1; return<=3'b000; end 3'b010:begin next=ST00; news<=1; return<=3'b001; end 3'b101:begin next=ST04; news<=1; return<=3'b100; end endcase endcase
always @(posedge clk or negedge clk) if(!rst) state<=ST00; else
state<=next; endmodule 仿真代码: `timescale 1ns/1ns module auto_newsy_tb; reg clk,rst; wire [2:0]return; wire news; reg [2:0]coin;
auto_newsy
U1(.coin(coin),.return(return),.news(news),.clk(clk),.rst(rst)); initial begin clk=0;rst=1; #2 rst=0;#5 rst=1; end
initial begin repeat(6) begin
#10 coin=3'b000; #10 coin=3'b001;
#10 coin=3'b010;#10
coin=3'b001;#10
coin=3'b001;#10 coin=3'b001;#10 coin=3'b001;#10
else
case (current) s0:if(a) current<=s1; else current<=s0; s1:if(a) current<=s1; else current<=s2; s2:if(a) current<=s1; else current<=s3; s3:if(a) current<=s4; coin=3'b010;#10 coin=3'b010;#10 coin=3'b010;#10
coin=3'b010;
#10 coin=3'b101;#10
coin=3'b101;#10 coin=3'b101;#10 coin=3'b101;#10
coin=3'b101; end end always #5 clk=~clk; initial #3000 $finish; initial
$monitor($time,\%b,rst=%b\endmodule
2·状态机
利用状态机设计一个“10011”序列检测器,该检测器具有如下行为:在每一个时钟下降沿检查输入数据,当输入数据序列为“10011”时,输出asm被置为1;其余情况asm为0。 要求:画出fsm(有限状态机) 设计代码:
module status_10011(a,clk,rst,asm); input a,clk,rst; output asm;
parameter [2:0] s0 =3'b000, s1 =3'b001, s2 =3'b010, s3 =3'b011, s4 =3'b100, s5 =3'b101; reg [2:0] current; always @ (negedge clk) begin if(rst) current=s0;
else current<=s0; s4:if(a) current<=s5; else current<=s2; s5:if(a) current<=s1; else current<=s2; endcase end
assign asm = (current == s5) ? 1 : 0; endmodule 仿真代码: `timescale 1ns/1ns module status_10011_tb; reg a,clk,rst; wire asm;
status_10011 U1(.a(a),.clk(clk),.rst(rst),.asm(asm)); initial begin
a=0;clk=1;rst=1; end always #5 clk=~clk; always #21 a=~a; initial begin #30 rst=0; #200 rst=1; end initial
$monitor($time,\endmodule
initial begin repeat(6) begin
#10 coin=3'b000; #10 coin=3'b001;
#10 coin=3'b010;#10
coin=3'b001;#10
coin=3'b001;#10 coin=3'b001;#10 coin=3'b001;#10
else
case (current) s0:if(a) current<=s1; else current<=s0; s1:if(a) current<=s1; else current<=s2; s2:if(a) current<=s1; else current<=s3; s3:if(a) current<=s4; coin=3'b010;#10 coin=3'b010;#10 coin=3'b010;#10
coin=3'b010;
#10 coin=3'b101;#10
coin=3'b101;#10 coin=3'b101;#10 coin=3'b101;#10
coin=3'b101; end end always #5 clk=~clk; initial #3000 $finish; initial
$monitor($time,\%b,rst=%b\endmodule
2·状态机
利用状态机设计一个“10011”序列检测器,该检测器具有如下行为:在每一个时钟下降沿检查输入数据,当输入数据序列为“10011”时,输出asm被置为1;其余情况asm为0。 要求:画出fsm(有限状态机) 设计代码:
module status_10011(a,clk,rst,asm); input a,clk,rst; output asm;
parameter [2:0] s0 =3'b000, s1 =3'b001, s2 =3'b010, s3 =3'b011, s4 =3'b100, s5 =3'b101; reg [2:0] current; always @ (negedge clk) begin if(rst) current=s0;
else current<=s0; s4:if(a) current<=s5; else current<=s2; s5:if(a) current<=s1; else current<=s2; endcase end
assign asm = (current == s5) ? 1 : 0; endmodule 仿真代码: `timescale 1ns/1ns module status_10011_tb; reg a,clk,rst; wire asm;
status_10011 U1(.a(a),.clk(clk),.rst(rst),.asm(asm)); initial begin
a=0;clk=1;rst=1; end always #5 clk=~clk; always #21 a=~a; initial begin #30 rst=0; #200 rst=1; end initial
$monitor($time,\endmodule
正在阅读:
硬件描述语言上机作业06-02
历年自考马克思主义基本原理概论试题及答案(2008--2014)03-29
经典新华信定量图表规范05-31
江苏省第五期“333工程”第三层次培养对象人选公示+05-17
广西农垦“民生建设年”成效显著11-05
资金时间价值练习104-16
学生暑假“企业挂职锻炼”09-27
- 小学生造句大全
- 增压泵投资项目可行性研究报告(模板)
- 高中语文人教版粤教版必修1-5全部文言文知识点归纳
- 两学一做专题民主生活会组织生活会批评与自我批评环节个人发言提
- 管理处环境保洁工作操作标准作业指导书
- 2012六一儿童节活动议程 - 图文
- 移树申请报告
- 《贵州省市政工程计价定额》2016定额说明及计算规则
- 计算机长期没有向WSUS报告状态
- 汉语拼音教学策略研究
- 发展西部领先的航空货运枢纽
- 司法所上半年工作总结4篇
- 如何提高银行服务水平
- 发电厂各级人员岗位职责
- 丰田汽车的外部环境分析
- 2017—2018年最新冀教版四年级数学下册《混合运算》教案精品优质
- 中建八局样板策划 - 图文
- 戚安邦《项目管理学》电子书
- 2015年高级项目经理笔记
- 弯桥的设计要点
- 上机
- 描述
- 作业
- 语言
- 硬件
- 译林版七年级英语上册单词表全(音标、翻译)
- 园林硬景施工管理规范
- 中职计算机等级考试题库及配标准答案
- 中考出错率最高的150个成语都在这里了
- 晶体解析步骤
- 《学前儿童数学教育》模拟试卷(A卷)
- 年产10万吨金红石型钛白粉工厂设计
- 传动装置的运动及动力参数的选择和计算
- 第一节 压强
- 锡林郭勒盟旅游业发展规划提纲
- 北大健康讲座 - 图文
- 晶体硅太阳能电池PECVD设备国产化现状及趋势
- 苏教版八下语文期中考试
- 2016届苏北三市高三年级第三次模拟考试英语
- 3种最简单神经网络的结构及学习算法
- 2018年中国再生医学行业分析及发展趋势预测(目录) - 图文
- Java4多选题
- 当前基层国税办税服务厅服务工作存在的问题及对策
- 汽车底盘系统检修工单
- 高中英语综合复习练习题