集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2696|回复: 5

抢答器verilog代码-

[复制链接]
VVIC 发表于 2010-6-28 00:33:23 | 显示全部楼层 |阅读模式
//===================================================================
//  project name:        strive_answer
//  author:          heal119
//  date:           24.07.2006
//  code description:      host control the state .Initial ,the host give an
//               order then three persons start to strive answer,
//               after the first man successfully have this done,
//               the host give the second order ,then the man start
//               answer the question demanded while a counter start
//               to work, which count from 60s down to 0s,
//               when counter =0; the process is over .
// note:           I just write it for practice.I will be glad if it can give
//                you some help.      
//===================================================================
   
module strive_answer (clk,
        rst,
        man_a,
        man_b,
        man_c,
        host,
        led1,
        led2,
        led3);
input rst;        
input clk;
input man_a;
input man_b;
input man_c;
input host;
outputreg [3:0] led1;
outputreg [3:0] led2;
outputreg [3:0] led3;

reg [1:0] state;
reg [5:0] cnt;

reg en_cnt;
reg en_ans;
reg en_man_a;
reg en_man_b;
reg en_man_c;

parameter prepare=0;
parameter strive=1;
parameter answer=3;

always @(posedge clk or posedge rst)
begin
if (rst)
begin
en_ans<=0;
state<=prepare;
end
else
begin
case(state)        
prepare:
begin
en_ans<=0;
en_man_a<=0;
en_man_b<=0;
en_man_c<=0;
if(host)
begin
en_cnt<=0;
state<=strive;
end
else
en_cnt<=0;
end
strive:
begin
en_ans<=1;
en_man_a<=1;
en_man_b<=1;
en_man_c<=1;
if(host)
begin
en_cnt<=1;
state<=answer;
end
else
en_cnt<=0;
end
answer:
begin
en_ans<=0;
en_man_a<=0;
en_man_b<=0;
en_man_c<=0;
en_cnt<=0;
if (cnt==0)
state<=prepare;
end
endcase
end
end

always@(posedge clk or posedge rst)
if(rst)
cnt<=0;
else if (en_cnt)
cnt<=60;
else
cnt<=cnt-1;

always @(posedge clk or posedge rst)
if (rst)
begin
led1<=0;
en_man_a<=0;
en_man_b<=0;
en_man_c<=0;
end
else if (en_ans)
begin
if (man_a&&en_man_a)
begin
led1<=1;
en_man_b<=0;
en_man_c<=0;
end
else if (man_b&&en_man_b)
begin
led1<=2;
en_man_a<=0;
en_man_c<=0;
end
else if (man_c&&en_man_c)
begin
led1<=3;
en_man_a<=0;
en_man_b<=0;
end
end
endmodule
CHA 发表于 2010-6-28 02:07:37 | 显示全部楼层
看不懂。。。。。。
interige 发表于 2010-6-28 03:40:50 | 显示全部楼层
这是因为在VHDL<br>
和Verilog HDL中都不允许两个进程对同一信号进行赋<br>
值(即多重驱动)<br>
这样在编译时会产生竞争冒险的&nbsp;&nbsp;<br>
怎么办?
usd 发表于 2010-6-28 05:10:00 | 显示全部楼层
听说有单位招画版图的本科生,应该知道些什么<br>
有经验的指教一下,万分感谢
ANG 发表于 2010-6-28 05:44:25 | 显示全部楼层
学习了。呵呵。。。。
interi 发表于 2010-6-28 07:06:20 | 显示全部楼层
原帖由 duanqingqing 于 2006-9-18 20:11 发表<br>
这是因为在VHDL<br>
和Verilog HDL中都不允许两个进程对同一信号进行赋<br>
值(即多重驱动)<br>
这样在编译时会产生竞争冒险的&nbsp;&nbsp;<br>
怎么办? 写在一个always语句中,或者使用中间的wire或reg类型变量。<br>
多驱动综合时会抱错。
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-1 02:07 , Processed in 0.072587 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表