将 VHDL 转换为 Verilog
Converting VHDL to Verilog
我正在尝试将下面的 vhdl 代码转换为 verilog,但它无法正常工作。我已经完成了大部分,但我认为我可能错误地转换了 VHDL 关键字 others
。有人可以帮忙吗?
VHDL代码
entity debounce is
Port ( clk : in STD_LOGIC;
i : in STD_LOGIC;
o : out STD_LOGIC);
end debounce;
architecture Behavioral of debounce is
signal c : unsigned(23 downto 0);
begin
process(clk)
begin
if rising_edge(clk) then
if i = '1' then
if c = x"FFFFFF" then
o <= '1';
else
o <= '0';
end if;
c <= c+1;
else
c <= (others => '0'); --LINE IN QUESTION
o <= '0';
end if;
end if;
end process;
end Behavioral;
根据 Toolic 的建议更新了 Verilog 代码
module debounce(input clk, input i, output o);
reg unsigned [23:0] c;
reg out_temp;
always @(posedge clk)begin
if(i == 1)begin
if(c==24'hFFFFFF)begin
out_temp <= 1'b1;
end
else begin
out_temp <= 1'b0;
end
c <= c+1'b1;
end
else begin
c <= {24{1'b0}};
out_temp <= 1'b0;
end
end
assign o = out_temp;
endmodule
当你说"see if it works"的时候,你是在模拟吗?如果没有,最好这样做。这是一个比较两个版本的简单测试平台:
module debounceTest;
reg clk=1'b0;
reg i=1'b1;
reg error=1'b0;
wire oVerilog, oVHDL;
integer k;
debounceVerilog UUTverilog (clk, i, oVerilog);
debounceVHD UUTvhdl (clk, i, oVHDL);
always
#5 clk = ~clk;
initial begin
for (k=0; k<2**26; k=k+1) begin
if ((k%(2**25))==0)
i = ~i;
#10;
end
$stop;
end
always @* begin
#1;
if (oVHDL!==oVerilog)
error = 1'b1;
end
endmodule
(实际上,我减少了模型中计数器的大小并模拟了更短的时间——这花了相当长的时间来模拟)。
为什么不对要从一种语言翻译成另一种语言的所有这些块执行此操作?
我正在尝试将下面的 vhdl 代码转换为 verilog,但它无法正常工作。我已经完成了大部分,但我认为我可能错误地转换了 VHDL 关键字 others
。有人可以帮忙吗?
VHDL代码
entity debounce is
Port ( clk : in STD_LOGIC;
i : in STD_LOGIC;
o : out STD_LOGIC);
end debounce;
architecture Behavioral of debounce is
signal c : unsigned(23 downto 0);
begin
process(clk)
begin
if rising_edge(clk) then
if i = '1' then
if c = x"FFFFFF" then
o <= '1';
else
o <= '0';
end if;
c <= c+1;
else
c <= (others => '0'); --LINE IN QUESTION
o <= '0';
end if;
end if;
end process;
end Behavioral;
根据 Toolic 的建议更新了 Verilog 代码
module debounce(input clk, input i, output o);
reg unsigned [23:0] c;
reg out_temp;
always @(posedge clk)begin
if(i == 1)begin
if(c==24'hFFFFFF)begin
out_temp <= 1'b1;
end
else begin
out_temp <= 1'b0;
end
c <= c+1'b1;
end
else begin
c <= {24{1'b0}};
out_temp <= 1'b0;
end
end
assign o = out_temp;
endmodule
当你说"see if it works"的时候,你是在模拟吗?如果没有,最好这样做。这是一个比较两个版本的简单测试平台:
module debounceTest;
reg clk=1'b0;
reg i=1'b1;
reg error=1'b0;
wire oVerilog, oVHDL;
integer k;
debounceVerilog UUTverilog (clk, i, oVerilog);
debounceVHD UUTvhdl (clk, i, oVHDL);
always
#5 clk = ~clk;
initial begin
for (k=0; k<2**26; k=k+1) begin
if ((k%(2**25))==0)
i = ~i;
#10;
end
$stop;
end
always @* begin
#1;
if (oVHDL!==oVerilog)
error = 1'b1;
end
endmodule
(实际上,我减少了模型中计数器的大小并模拟了更短的时间——这花了相当长的时间来模拟)。
为什么不对要从一种语言翻译成另一种语言的所有这些块执行此操作?