竞赛抢答器设计报告.docx
《竞赛抢答器设计报告.docx》由会员分享,可在线阅读,更多相关《竞赛抢答器设计报告.docx(22页珍藏版)》请在冰豆网上搜索。
竞赛抢答器设计报告
电子技术课程设计报告
课题:
竞赛抢答器(verilog)
学号:
U200813539
院系:
控制科学与工程系
专业班级:
自动化0806班
姓名:
许伟波
目录
一、概述3
二、课题要求3
三、验收要求4
四、测试工具平台4
五、课题分析与理解4
六、设计思路5
1.模块划分5
2.系统ASM图6
七、模块代码及仿真8
1.代码编写思路8
2.变量说明8
3.各模块程序与仿真9
1)抢答模块9
2)计时模块11
3)计分模块13
4)显示模块18
5)报警模块20
八、实验感想21
一、概述
在竞赛、文体娱乐活动(抢答活动)中,能准确、公正、直观地判断出抢答者的机器。
通过抢答者的指示灯显示、数码显示和警示显示等手段指示出第一抢答者。
一般抢答器由单片机以及外围电路组成,分为八路十路等不同,八路和十路的差别是,抢答器背面的接口有几组,和外形没有关系。
二、课题要求
1.设计一个可容纳6组参赛的数字式抢答器,每组设一个按钮,供抢答使用。
2.主持人按复位键后开始抢答。
3.第一个抢答信号可以使其它信号无效。
4.指示灯显示抢答组别。
5.对提前1秒或超时3秒答题的组别鸣笛示警,由组别显示器显示犯规组别。
6.设置一个记分模块,每组开始预设10分,答对加1分,答错减一分。
三、验收要求
1.用Verilog语言对设计进行描述,设计一个测试方案,通过Muxplus对设计进行仿真验证。
并能够下载到实验板上调试成功。
2.写出设计性实验报告,并打印各层次的源文件和仿真波形,然后作简要说明。
并谈谈此次实验的收获、感想及建议。
四、测试工具平台
编写语言:
Verilog
编译调试工具:
maxplus2
五、课题分析与理解
根据题目要求可知,首先需要一个按钮begin让主持人来控制抢答的开始与结束。
然后,在选手答完题后需要判断选手回答正确与否,用sub和add来控制加减分。
但是由于资源有限,只有八个按键,所以用剩下的五个键k1,k2,k3,k4,k5来控制选手的抢答。
所以在这次课设中我只设置了五位抢答选手。
再对课题进行进一步分析,用自顶向下的设计方法,由于所需要实现的内容不止一个,所以我们采用分模块的设计理念,先设计独立功能的子程序,再把各个子程序综合起来构成一个整体的系统。
这样设计的好处有以下几点:
(1)各子程序之间是相对独立的。
某个子程序并不需要知道所调用它的程序是如何实现的,而仅仅需要知道知道该调用程序的接口所提供的服务。
由于每一个子程序只实现一种相对独立的功能,因而可将一个难以处理的复杂问题分解为若干个较容易处理的更小的问题。
这样,整个问题的复杂程度就降低了。
(2)灵活性好。
当某个子程序发生变化时(例如技术的变化),只要保证各接口关系不变,则其他程序不受影响。
(3)易于实现和维护。
这种结构使得实现和调试一个庞大而复杂的系统变得易于处理,因为整个的系统已被分解为若干个相对独立的子系统。
电路原理如下图所示:
六、设计思路
1.模块划分
在对问题进行分析之后将该程序分成一下模块,如图所示:
模块名
作用和意义
Qiangda
当主持人没有按下抢答按钮时,按下抢答按钮选手为犯规选手;当主持人按下抢答按钮时,按下抢答按钮选手为抢到的选手,并用pressed信号锁存。
Time_count
设置初始时间为五秒,当选手抢到题目时开始计时,当超时3秒时,time_out信号置1,蜂鸣器发出报警声。
Score_count
设置各位选手的初始分数,主持人通过两个按键对抢答者回答对错进行判断,同时改变其分数。
Display
将需要数码管输出显示的信号输入,显示犯规组别或者抢答组别,另外四个数码管显示分数和剩余时间。
2.过程分析
通过主持人按键判断强大是否开始,抢答开始前,选手按下抢答按钮,被算为提前抢答,蜂鸣器发出报警声,数码管显示犯规组别。
抢答开始后,选手通过抢答按钮进行抢答,当某组抢答成功时显示抢答组别:
若该组超时3秒抢答,蜂鸣器报警,抢答无效;若该组在抢答时间内完成作答,主持人可通过加分减分按钮对该组得分进行修改。
在某组抢答成功时,其他组抢答按钮被屏蔽,按钮无效,只有当主持人按下第二次抢答信号时可以再次抢答。
七、模块代码及仿真
1.代码编写思路
在分完模块后,根据ASM图进行各个模块的编程,再将各个模块通过顶层模块连接起来,合成一个完整的系统。
2.各模块程序与仿真
1)抢答模块
a)代码
moduleqiangda(k1,k2,k3,k4,k5,cp1024hz,reset,tqqd,pressed,zbxs);
inputk1,k2,k3,k4,k5,cp1024hz,reset;
outputtqqd,pressed;
output[3:
0]zbxs;
regtqqd,pressed;
reg[3:
0]zbxs;
always@(posedgecp1024hz)
begin
if(!
reset)//没开始抢答
begin
pressed<=0;
zbxs<=0;
if(k1==1)
begin
zbxs<=1;
tqqd<=1;
end
elseif(k2==1)
begin
zbxs<=2;
tqqd<=1;
end
elseif(k3==1)
begin
zbxs<=3;
tqqd<=1;
end
elseif(k4==1)
begin
zbxs<=4;
tqqd<=1;
end
elseif(k5==1)
begin
zbxs<=5;
tqqd<=1;
end
end
else//reset==1,主持人按下开始键
begin
tqqd<=0;
if(k1==1&&pressed==0)
begin
pressed<=1;
zbxs<=1;
end
elseif(k2==1&&pressed==0)
begin
pressed<=1;
zbxs<=2;
end
elseif(k3==1&&pressed==0)
begin
pressed<=1;
zbxs<=3;
end
elseif(k4==1&&pressed==0)
begin
pressed<=1;
zbxs<=4;
end
elseif(k5==1&&pressed==0)
begin
pressed<=1;
zbxs<=5;
end
end
end
endmodule
b)仿真
2)计时模块
a)代码
moduletime_count(cp1024hz,reset,pressed,time_left,time_out);
inputcp1024hz,reset,pressed;
output[3:
0]time_left;
outputtime_out;
reg[3:
0]time_left;
regtime_out;
reg[9:
0]temp_count;//中间变量,1023时计一秒
reg[3:
0]temp_time;//实现延时3秒
always@(posedgecp1024hz)//计时模块
begin
if(!
reset)
begin
time_left<=5;
time_out<=0;
temp_count<=0;
temp_time<=8;
end
else
begin
if(temp_time==0)
begin
time_out<=1;
end
if(pressed)//有人抢答开始计时
begin
if(temp_count==1023)
begin
temp_count<=0;
if(temp_time>1&&time_left>0)
begin
time_left<=time_left-1;
temp_time<=temp_time-1;
end
elseif(temp_time>1&&time_left==0)
begin
temp_time<=temp_time-1;
time_left<=0;
end
else//超时三秒
begin
temp_time<=0;
time_out<=1;
end
end
else
begin
temp_count<=temp_count+1;
end
end
end
end
endmodule
b)仿真
3)计分模块
a)代码
modulescore_count(cp1024hz,add,sub,zbxs,reset,score11,score12,score21,score22,score31,score32,score41,score42,score51,score52);
inputadd,sub,cp1024hz,reset;
input[3:
0]zbxs;
output[3:
0]score11,score12,score21,score22,score31,score32,score41,score42,score51,score52;
reg[3:
0]score11,score12,score21,score22,score31,score32,score41,score42,score51,score52;
realinit_score;//计分模块
realinit_pf;
always@(posedgecp1024hz)
if(!
init_score)//初始化分数
begin
score11<=0;
score12<=1;
score21<=0;
score22<=1;
score31<=0;
score32<=1;
score41<=0;
score42<=1;
score51<=0;
score52<=1;
init_score<=1;
end
elseif(init_score&&!
reset)//锁存评分信号
begin
init_pf<=0;
end
elseif(init_score&&reset&&init_pf==0)
begin
if(zbxs==1&&add==1)
begin
if(score11==9)
begin
score11<=0;
score12<=score12+1;
init_pf<=1;
end
else
begin
score11<=score11+1;
init_pf<=1;
end
end
elseif(zbxs==1&&sub==1)
begin
if(score11==0)
begin
score11<=9;
score12<=score12-1;
init_pf<=1;
end
else
begin
score11<=score11-1;
init_pf<=1;
end
end
elseif(zbxs==2&&add==1)
begin
if(score21==9)
begin
score21<=0;
score22<=score22+1;
init_pf<=1;
end
else
begin
score21<=score21+1;
init_pf<=1;
end
end
elseif(zbxs==2&&sub==1)
begin
if(score21==0)
begin
score21<=9;
score22<=score22-1;
init_pf<=1;
end
else
begin
score21<=score21-1;
init_pf<=1;
end
end
elseif(zbxs==3&&add==1)
begin
if(score31==9)
begin
score31<=0;
score32<=score32+1;
init_pf<=1;
end
else
begin
score31<=score31+1;
init_pf<=1;
end
end
elseif(zbxs==3&&sub==1)
begin
if(score31==0)
begin
score31<=9;
score32<=score32-1;
init_pf<=1;
end
else
begin
score31<=score31-1;
init_pf<=1;
end
end
elseif(zbxs==4&&add==1)
begin
if(score41==9)
begin
score41<=0;
score42<=score42+1;
init_pf<=1;
end
else
begin
score41<=score41+1;
init_pf<=1;
end
end
elseif(zbxs==4&&sub==1)
begin
if(score41==0)
begin
score41<=9;
score42<=score42-1;
init_pf<=1;
end
else
begin
score41<=score41-1;
init_pf<=1;
end
end
elseif(zbxs==5&&add==1)
begin
if(score51==9)
begin
score51<=0;
score52<=score52+1;
init_pf<=1;
end
else
begin
score51<=score51+1;
init_pf<=1;
end
end
elseif(zbxs==5&&sub==1)
begin
if(score51==0)
begin
score51<=9;
score52<=score52-1;
init_pf<=1;
end
else
begin
score51<=score51-1;
init_pf<=1;
end
end
end
end
endmodule
b)仿真
4)显示模块
a)代码
moduledisplay(cp1024hz,reset,score11,score12,score21,score22,score31,score32,score41,score42,score51,score52,zbxs,scorea,scoreb);
inputcp1024hz,reset;
input[3:
0]score11,score12,score21,score22,score31,score32,score41,score42,score51,score52,zbxs;
output[3:
0]scorea,scoreb;
reg[3:
0]scorea,scoreb;
always@(posedgecp1024hz)
begin
if(!
reset)
begin
scorea<=0;
scoreb<=0;
end
else
begin
if(zbxs==1)
begin
scorea<=score11;
scoreb<=score12;
end
elseif(zbxs==2)
begin
scorea<=score21;
scoreb<=score22;
end
elseif(zbxs==3)
begin
scorea<=score31;
scoreb<=score32;
end
elseif(zbxs==4)
begin
scorea<=score41;
scoreb<=score42;
end
elseif(zbxs==5)
begin
scorea<=score51;
scoreb<=score52;
end
end
end
endmodule
b)仿真
5)报警模块
a)代码
modulesound_alarm(reset,cp1024hz,tqqd,time_out,alarm);
inputreset,cp1024hz;
inputtqqd,time_out;
outputalarm;
regalarm;
reg[9:
0]temp_count;
regtemp;
always@(posedgecp1024hz)
begin
if(!
reset)
begin
alarm<=temp;
temp_count<=0;
if(tqqd==1)
begin
if(temp_count==10)
begin
temp<=1;
end
elsetemp_count<=temp_count+1;
end
end
else
begin
alarm<=temp;
temp_count<=0;
if(time_out==1)
begin
if(temp_count==10)
begin
temp<=1;
end
elsetemp_count<=temp_count+1;
end
end
end
endmodule
b)仿真
八、实验感想
这次电子技术课程设计,让我对以前不够明白真正理解的知识,有了更加深一步的学习和了解。
通过五个星期的学习和探索,我利用自己的课外时间看了很多verilog的教程,并且通过查看资料自己设计完成了一个竞赛抢答器。
同时我进一步学习了maxplus2软件的使用和连接到试验箱进行调试,对整个系统的测试起到了很大的作用。
在仿真和调试的过程中,我再次复习了软件的的使用方法,复习了以前学过的怎么样编译程序、怎么样生成波形文件,怎样下载到实验板上验证设计是否符合要求。
在这次的设计中我遇到了3个问题。
第一个就是,由于系统时钟是1024hz的,在进行加减分时是在每一个上升沿触发的,一次按键就会触发多次加减分操作,刚开始不知道怎么去实现在一次抢答过程中只进行一次加减分,和同学讨论后,设置了一个中间变量init_pf,此信号在reset信号为0时进行清零,在一次加减分后,赋值为1避免二次赋值。
第二个问题是,因为各位选手的初始分数是10分,如何在整个过程中只进行一次赋值,其实这个问题和第一个问题差不多,只要不进行清零就行。
我遇到的最后一个问题是在报警模块中出现了问题,刚开始以为只要给个高电平蜂鸣器就会发出报警声,下载到实验板上后一直没有声音,后来知道是给一个时钟信号,不过修改也很简单,由于我用的系统时钟是1024hz的,将高电平与系统时钟相与就得以实现了。
当然遇到困难在所难免,最主要的是我学到了很多。
通过这次课程设计,加强了我们动手、思考和解决问题的能力。
在设计过程中,经常会遇到这样那样的情况,自己编程时候的思路和下载到实验板上是有区别的,实际情况更为复杂,因此耗费在这上面的时间用去很多。
通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正为社会服务,从而提高自己的实际动手能力和独立思考的能力。
最后衷心感谢老师的悉心授课和同学门的热心帮助!