用for语句描述的7人投票表决器,若超过4人(含4人)投票赞成,则表决通过
RTL代码
module vote7(pass,vote);
output pass;
input vote;
wire[6:0] vote;
reg pass;
integer i;
reg[2:0] sum;
always@(vote) begin
sum=0;
for (i=0;i<=6;i=i+1)
begin
if (vote[i])
begin
sum=sum+1;
end
if (sum[2])
begin
pass=1;
end
else
begin
pass=0;
end
end
end
endmodule
TB代码
module vote7_tb();
wire pass;
reg[6:0] vote;
initial begin
repeat(5) begin
vote={$random}%128;
$display("vote=%b",vote);
#5
if (pass)
begin
$display("++++pass++++");
end
else
begin
$diplay("+++++nopass++++++");
end
end
end
vote7 v7(.pass(pass),.vote(vote));
endmodule
文章描述了一个用Verilog实现的7人投票表决器,当超过4人(含4人)投票赞成时,表决通过。RTL代码部分使用了for循环来计票,并在达到一定条件时设置表决结果。TB测试模块则用于验证表决器的功能,通过随机生成投票输入并显示输出结果。
1万+

被折叠的 条评论
为什么被折叠?



