verilog HDL抢答器.docx

上传人:b****3 文档编号:4741700 上传时间:2022-12-08 格式:DOCX 页数:14 大小:41.17KB
下载 相关 举报
verilog HDL抢答器.docx_第1页
第1页 / 共14页
verilog HDL抢答器.docx_第2页
第2页 / 共14页
verilog HDL抢答器.docx_第3页
第3页 / 共14页
verilog HDL抢答器.docx_第4页
第4页 / 共14页
verilog HDL抢答器.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

verilog HDL抢答器.docx

《verilog HDL抢答器.docx》由会员分享,可在线阅读,更多相关《verilog HDL抢答器.docx(14页珍藏版)》请在冰豆网上搜索。

verilog HDL抢答器.docx

verilogHDL抢答器

一、设计任务

智力竞赛抢答器VerilogHDL要求有6位参赛者进行抢答,有六个抢答信号进行抢答。

当有抢答选手按下抢答键后系统能够快速准确的判断是那一组选手按下了抢答信号,由于系统比较小,速度比较快一般不会有同时按下的可能,所以只有六种状态,然后系统能够根据这六种状态进行适时的显示和提示。

当有选手按下以后就对抢答信号进行锁存,其他选手的输入无效。

然后就是对抢答进行时间限制了,根据设定的时间进行倒计时,当倒计时完成还没有人抢答的时候系统发出警报声音提示时间已经到了。

当有选手在主持人未按下抢答键抢答时视为超前抢答,系统显示该选手号,同时蜂鸣器响,该抢答无效。

还有清除复位键,抢答完成以后按复位键即可清除已有的状态。

通过VerilogHDL程序代码实现系统的各个功能。

二、设计目的与要求

目的:

理论联系实际,巩固和运用所学课程,提高分析、解决计算机技术实际问题的独立工作能力,培养学生正确的设计思想,严肃认真、实事求是的科学态度和勇于探索的创新精神。

通过对一个智力抢答器的设计,进一步加深对计算机原理以及数字电路应用技术方面的了解与认识,进一步熟悉数字电路系统设计、制作与调试的方法和步骤,通过Verilog程序的编写,进一步熟悉VerilogHDL的语法知识;规范化训练学生撰写技术研究报告,提高书面表达能力。

要求:

掌握FPGA设计系统的一般方法。

熟练掌握使用modelsim软件设计较复杂的数字逻辑电路。

培养学生独立分析问题和解决实际问题的能力。

三、课程设计的内容

设计一抢答器,要求如下:

(1)抢答台数为6;

(2)具有抢答开始后20s倒计时,20秒倒计时后6人抢答显示超时,并报警;

(3)能显示超前抢答台号并显示犯规报警;

(4)系统复位后进入抢答状态,当有一路抢答按键按下,该路抢答信号将其余各路抢答信号封锁,同时铃声响起,直至该路按键松开,显示牌显示该路抢答台号。

四、系统设计方案

根据系统设计要求可知,系统的输入信号有:

主持人按钮inputEn,各选手的抢答按钮分别是inputL1、inputL2、inputL3、inputL4,inputL5,inputL6,主持人和选手抢答按钮都是低电平有效,系统复位信号clr(高电平有效),系统时钟信号clk,系统的输出信号有:

六个人抢答成功与否的指示灯控制信号输出口Led2,犯规抢答时报警器Buzzer(低电平有效)。

本系统应具有的功能有:

能够准确的判断出是哪位抢答者,当主持人没按抢答时,有人抢答了则蜂鸣器报警,并显示该选手号,当主持人按了抢答键时有人抢答了,同时封锁抢答信号,其他选手抢答无效,不显示该选手号。

五、仿真过程与仿真结果

仿真过程:

使用ModelSim进行功能测试,首先在里面进行相应的设置,在工程文件夹下面会新建一个modelsim的文件夹,然后编写实现功能的程序和测试文件,最后保存编译执行就可以进行功能仿真了。

仿真结果:

结果分析与讨论:

可以看到0时刻系统复位状态,2s时2号超前抢答(inputEn为高电平,inputL2为低电平),系统显示2蜂鸣器并犯规报警(Buzzer为低电平),8s时系统复位状态,12s时4号选手先抢答成功(inputL4为低电平)显示4,14s时3号选手后抢答,不显示3,20s时系统复位。

六、总结

通过本次合成设计,我又一遍熟悉了VerilogHDL语言进行建模,并且通过实际操作学会了怎么使用Modelsim这个软件来完成一个完整的课程设计。

以及对基于FPGA的系统开发流程有了一个整体认识,我越来越认识到一点,编程对项目实现有着至关重要的,我们在硬件开发的过程中更应该重视编程,将编程看作是完善开发的不可缺少的一部分。

虽然题目简单,但这也磨练了我的意志。

第一次做的太复杂了,然后一次次修改,做成最简单功能的。

在一次次的反复设计、论证和测试中,提高了逻辑分析能力、全面分析问题的能力以及发现问题、解决问题的能力。

通过对各方面资料的收集,我的知识面也进一步拓宽了。

同时,我也发现了自己的不足,像语言表达还比较差,不能更清楚地表达自己的意思,逻辑分析能力和编程能力有待提高,有些预先的想法都未能实现。

在系统的结构设计上也还有很长的路需要走,这是需要时间去积累的。

在今后的学习中我还得加以改进。

七、程序

系统主要VerilogHDL源程序:

moduleQiangDaQi

(clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led2,Buzzer);//一开始声明有哪些端口

inputclk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6;

output[0:

7]Led2;//Led2显示选手号

outputBuzzer;//低电平时蜂鸣器发出声音

regEnFlat=1'b0;//EnFlat为高电平时开始抢答

reg[0:

2]Led2=3'd0;

regBuzzer=1'b1;

always@(posedgeclk)//时钟上升沿

begin

if(inputEn==1)//如果主持人没按按钮就有人抢答

begin

if(inputL1==0)

beginLed2=3'd1;Buzzer=1'b0;end

if(inputL2==0)

beginLed2=3'd2;Buzzer=1'b0;end

if(inputL3==0)

beginLed2=3'd3;Buzzer=1'b0;end

if(inputL4==0)

beginLed2=3'd4;Buzzer=1'b0;end

if(inputL5==0)

beginLed2=3'd5;Buzzer=1'b0;end

if(inputL6==0)

beginLed2=3'd6;Buzzer=1'b0;end

end

if(inputEn==1'b0)//为低电平时表示主持人按下抢答按钮开始抢答

begin

EnFlat=1'b1;

if(EnFlat==1'b1)

begin

if(inputL1==1'b0)//一号选手抢答

begin

Led2=3'd1;

EnFlat=1'b0;//为低电平禁止其他选手抢答

Buzzer=1'b1;

end

else//一开始没加else发现仿真结果随着输入数据变化而变化

if(inputL2==1'b0)//二号选手抢答

begin

Led2=3'd2;

EnFlat=1'b0;

Buzzer=1'b0;

end

else

if(inputL3==1'b0)//三号选手抢答

begin

Led2=3'd3;

EnFlat=1'b0;//为低电平禁止其他选手抢答

Buzzer=1'b1;

end

else

if(inputL4==1'b0)//四号选手抢答

begin

Led2=3'd4;

EnFlat=1'b0;//为低电平禁止其他选手抢答

Buzzer=1'b1;

end

else

if(inputL5==1'b0)//五号选手抢答

begin

Led2=3'd5;

EnFlat=1'b0;//为低电平禁止其他选手抢答

Buzzer=1'b1;

end

else

if(inputL6==1'b0)//六号选手抢答

begin

Led2=3'd6;

EnFlat=1'b0;//为低电平禁止其他选手抢答

Buzzer=1'b1;

end

end

end

if(clr)//按下clr键以后各组参数重置,整个比赛重新开始

begin

EnFlat=1'b0;

Led2=3'd0;//为低电平时,选手前的灯点亮

Buzzer=1'b1;//为高电平不响

end

end

endmodule

测试程序

`timescale1s/1s

moduleqiangdaqi_test();

regclk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6;//输入口

wire[0:

7]Led2;//Led2显示选手号

wireBuzzer;//低电平时蜂鸣器发出声音

QiangDaQiu1(clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led2,Buzzer);

initial

begin

#0clk=1;clr=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2inputL2=0;//二号选手超前抢答

#4clr=1;inputL2=1;//复位

#2clr=0;

#4inputEn=0;inputL4=0;//四号选手先抢答显示4

#2inputL3=0;//三号选手后抢答不显示3

#4clr=1;inputEn=1;inputL3=1;inputL4=1;

#2clr=0;

end

always#1clk=~clk;

endmodule

程序二

moduleQiangDaQi

(clk,clr,add,stu,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led1,Led2,Led3,Buzzer);

//一开始声明有哪些端口

inputclk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,add,stu;//输入口

output[0:

5]Led1;//对应参赛选手前的灯

output[0:

7]Led2,Led3;//Led2显示选手号Led3显示选手分数

outputBuzzer;//低电平时蜂鸣器发出声音

regEnFlat=1'b1;//EnFlat为高电平时开始抢答

regBuClk=1'b0;//为高电平时进入蜂鸣器处理程序

//regadd,stu;//add答题正确加一分stu答题错误减一分

//regclr=0;//重置键

reg[0:

5]Led1=6'b111111;

reg[0:

2]answer=3'd0;

reg[0:

3]score=4'd0,score1=4'd0,score2=4'd0;

reg[0:

3]score3=4'd0,score4=4'd0,score5=4'd0,score6=4'd0;//各选手分数计算

regBuzzer=1;

reg[0:

4]daojishi=5'd20;//用于产生20s倒计时

reg[0:

7]Led2=8'b,Led3=8'b;

always@(posedgeclk)//时钟上升沿

begin

if(inputEn==1)//如果主持人没按按钮就有人抢答

begin

if(inputL1==0)

beginLed1=6'b111110;answer=3'd1;BuClk=1'b1;end

if(inputL2==0)

beginLed2=6'b111101;answer=3'd2;BuClk=1'b1;end

if(inputL3==0)

beginLed2=6'b111011;answer=3'd3;BuClk=1'b1;end

if(inputL4==0)

beginLed2=6'b110111;answer=3'd4;BuClk=1'b1;end

if(inputL5==0)

beginLed2=6'b101111;answer=3'd5;BuClk=1'b1;end

if(inputL6==0)

beginLed2=6'b011111;answer=3'd6;BuClk=1'b1;end

end

if(inputEn==1'b0)//为低电平时表示主持人按下抢答按钮开始抢答

begin

Led1=6'b111111;//为低电平时,选手前的灯点亮

BuClk=1'b0;

Buzzer=1'b1;//为高电平不响

end

if(EnFlat==1'b1)

begin

begin

if(inputL1==1'b0)//一号选手抢答

begin

EnFlat=1'b0;//为低电平禁止其他选手抢答

answer=3'd1;//为高电平时转到对应选手加减分程序中去

BuClk=1'b1;//转到蜂鸣器程序

end

if(inputL2==1'b0)//二号选手抢答

begin

EnFlat=1'b0;

answer=3'd2;

BuClk=1'b1;

end

if(inputL3==1'b0)//三号选手抢答

begin

EnFlat=1'b0;

answer=3'd3;

BuClk=1'b1;

end

if(inputL4==1'b0)//四号选手抢答

begin

EnFlat=1'b0;

answer=3'd4;

BuClk=1'b1;

end

if(inputL5==1'b0)//五号选手抢答

begin

EnFlat=1'b0;

answer=3'd5;

BuClk=1'b1;

end

if(inputL6==1'b0)//六号选手抢答

begin

EnFlat=1'b0;

answer=3'd6;

BuClk=1'b1;

end

end

begin

if(daojishi!

=5'd0)//用于1Hz信号

daojishi=daojishi-1;

else//倒计时结束抢答器还没按下则抢答停止且蜂鸣器响

begin

daojishi=5'd20;

EnFlat=1'b0;

BuClk=1'b1;

end

end

begin

if(BuClk==1'b1)//当蜂鸣器标志为1时

Buzzer=1'b0;//蜂鸣器发声

end

begin

if(answer==3'd1)//第一组加减分

begin

Led1=6'b111110;//点亮该选手前的LED灯

Led2=8'hf9;//选手号数码管显示1

if(add)

score1=score1+1;//当主持人判定选手的回答正确时,按下add键进行加分操作

else

if((stu||inputEn)&&(score1!

=0))

score1=score1-1;//当主持人判定选手的回答错误时,按下stu键进行加分操作

elsescore1=0;

score=score1;//把第一组的分数赋值给分数寄存器

end

if(answer==3'd2)//第二组加减分

begin

Led1=6'b111101;Led2=8'ha4;

if(add)

score2=score2+1;//当主持人判定选手的回答正确时,按下add键进行加分操作

else

if((stu||inputEn)&&(score2!

=0))

score2=score2-1;//当主持人判定选手的回答错误时,按下stu键进行加分操作

elsescore2=0;

score=score2;//把第一组的分数赋值给分数寄存器

end

if(answer==3'd3)//第三组加减分

begin

Led1=6'b111011;Led2=8'hb0;

if(add)

score3=score3+1;//当主持人判定选手的回答正确时,按下add键进行加分操作

else

if((stu||inputEn)&&(score3!

=0))

score3=score3-1;//当主持人判定选手的回答错误时,按下stu键进行加分操作

elsescore3=0;

score=score3;//把第一组的分数赋值给分数寄存器

end

if(answer==3'd4)//第四组加减分

begin

Led1=6'b110111;Led2=8'h99;

if(add)

score4=score4+1;//当主持人判定选手的回答正确时,按下add键进行加分操作

else

if((stu||inputEn)&&(score4!

=0))

score4=score4-1;//当主持人判定选手的回答错误时,按下stu键进行加分操作

elsescore4=0;

score=score4;//把第一组的分数赋值给分数寄存器

end

if(answer==3'd5)//第五组加减分

begin

Led1=6'b101111;Led2=8'h92;

if(add)

score5=score5+1;//当主持人判定选手的回答正确时,按下add键进行加分操作

else

if((stu||inputEn)&&(score5!

=0))

score5=score5-1;//当主持人判定选手的回答错误时,按下stu键进行加分操作

elsescore5=0;

score=score5;//把第一组的分数赋值给分数寄存器

end

if(answer==3'd6)//第六组加减分

begin

Led1=6'b011111;Led2=8'h82;

if(add)

score6=score6+1;//当主持人判定选手的回答正确时,按下add键进行加分操作

else

if((stu||inputEn)&&(score6!

=0))

score6=score6-1;//当主持人判定选手的回答错误时,按下stu键进行加分操作

elsescore6=0;

score=score6;//把第一组的分数赋值给分数寄存器

end

begin

case(score)//

4'd0:

Led3=8'hc0;4'd1:

Led3=8'hf9;4'd2:

Led3=8'ha4;

4'd3:

Led3=8'hb0;4'd4:

Led3=8'h99;4'd5:

Led3=8'h92;

4'd6:

Led3=8'h82;4'd7:

Led3=8'hf8;4'd8:

Led3=8'h80;

4'd9:

Led3=8'h90;default:

Led3=8'hff;

endcase

end

end

end

if(clr)//按下clr键以后各组参数重置,整个比赛重新开始

begin

EnFlat=1'b1;

daojishi=5'd20;

Led1=6'b111111;//重置时六个Led全灭

Led2=8'b;//熄灭选手号静态数码管

Led3=8'b;//熄灭分数显示数码管

BuClk=1'b0;//蜂鸣器标志位重置

Buzzer=1'b1;//蜂鸣器控制管脚重置

score=0;

//score1=4'd0;score2=4'd0;score3=4'd0;

//score4=4'd0;score5=4'd0;score6=4'd0;

answer=3'd0;

end

end

endmodule

测试程序

`timescale1s/1s

moduleqiangdaqi_test();

regclk,clr,add,stu,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6;

//regclr;//重置键

//regadd,stu;//add答题正确加一分stu答题错误减一分

wire[0:

5]Led1;//对应参赛选手前的灯

wire[0:

7]Led2,Led3;//Led2显示选手号Led3显示选手分数

wireBuzzer;//低电平时蜂鸣器发出声音

QiangDaQiu1(clk,clr,add,stu,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led1,Led2,Led3,Buzzer);

initial

begin

#0clk=1;add=0;stu=0;clr=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2inputEn=0;inputL1=1;inputL2=0;inputL3=1;inputL4=1;inputL5=1;inputL6=1;add=1;

#2clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2clr=0;

#2inputEn=0;inputL1=1;inputL2=0;inputL3=1;inputL4=1;inputL5=1;inputL6=1;add=1;

#1inputL3=0;add=1;

#2clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2clr=0;

#2inputEn=1;inputL1=1;inputL2=0;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2clr=0;

#2inputEn=0;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#40inputEn=0;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;

#2clr=0;

#2inputEn=0;inputL1=0;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;add=1;

#2clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1