gpt4 book ai didi

verilog - 使用Verilog实现光控

转载 作者:行者123 更新时间:2023-12-04 07:28:08 26 4
gpt4 key购买 nike

这是我的主要代码。该功能是在我切换时打开或关闭灯。
也许 t 触发器可以提供帮助?

module demo(
input switch1,switch2,
output reg light=1'b0
);

always@(switch1 or switch2)
begin
light <= ~light;
end

endmodule
和测试台
`timescale 1ns/100ps

module demo_test;

reg switch1,switch2;
wire light;

demo d1(.switch1(switch1),
.switch2(switch2),
.light(light));

initial
begin: in_set_blk
#0 switch1 =1'b0;
switch2 =1'b0;
$display ($time, "light=%d \n",light);
#10 switch1 =1'b1;
switch2 =1'b0;
$display ($time, "light=%d \n",light);
#10 switch1 =1'b0;
switch2 =1'b0;
$display ($time, "light=%d \n",light);
#10 switch1 =1'b0;
switch2 =1'b1;
$display ($time, "light=%d \n",light);
#10 switch1 =1'b0;
switch2 =1'b0;
$display ($time, "light=%d \n",light);
#10 $stop;
#10 $finish;
end

endmodule
这是modelsim的波形图;我认为它运作良好:
and this is the modelsim waveform diagram, I think it work well
这是 RTL 查看器中的图表;这是奇怪的部分:
and this is the diagram in RTL viewer, that is the strange part
RTL 查看器中的图表很奇怪;输入甚至没有连接到逆变器。
我的主 Verilog 代码中有任何错误吗?

最佳答案

是的,问题是您的 demo模块 Verilog 代码不可合成。
并非所有合法的 Verilog 代码都是可合成的。综合工具可以识别特定的编码模式,但您的代码与这些模式中的任何一个都不匹配。您的 FPGA 工具集应该有说明综合支持的语法的文档。
这就是为什么您的 RTL 查看器工具会为您提供一个奇怪的图表。
以下是模拟的工作原理。在 time=0 时,您设置了 light和 2 个开关输入为 0。在 time=10 时,您更改 switch1为 1。这会触发 always block ,执行 light <= ~light;任务。这套light=1 .
每次任一输入更改时,always block 被触发,导致 light切换。
如果这是您希望设计工作的方式,则应考虑使用边缘检测器。但是,这需要触发器和时钟。

关于verilog - 使用Verilog实现光控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68111772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com