VHDL到Verilog
我有一些VHDL代码,我正试图转换为Verilog VHDL代码运行良好VHDL到Verilog,vhdl,verilog,system-verilog,hdl,Vhdl,Verilog,System Verilog,Hdl,我有一些VHDL代码,我正试图转换为Verilog VHDL代码运行良好 library ieee; use ieee.std_logic_1164.all; entity find_errors is port( a: bit_vector(0 to 3)
library ieee;
use ieee.std_logic_1164.all;
entity find_errors is port(
a: bit_vector(0 to 3);
b: out std_logic_vector(3 downto 0);
c: in bit_vector(5 downto 0));
end find_errors;
architecture not_good of find_errors is
begin
my_label: process (a,c)
begin
if c = "111111" then
b <= To_StdLogicVector(a);
else
b <= "0101";
end if;
end process;
end not_good;
ieee库;
使用ieee.std_logic_1164.all;
实体查找_错误为端口(
a:位_向量(0到3);
b:输出标准逻辑向量(3到0);
c:在位_向量中(5到0));
结束查找错误;
体系结构不利于发现错误
开始
my_标签:过程(a、c)
开始
如果c=“111111”,则
baw
和creg
是不必要的,bw
需要声明为reg
module find_errors(
input [3:0] a,
output [3:0] b,
input [5:0] c
);
reg [3:0] bw;
assign b = bw;
always @(a,c)
begin
if (c == 4'b1111)
bw <= a;
else
bw <= 4'b0101;
end
endmodule
它看起来非常接近,但有一些问题/错误需要修复,请参阅固定代码中的内联注释:
module find_errors(
input wire [3:0] a, // Better to be explicit about the types even if
// its not strictly necessary
output reg [3:0] b, // As mentioned in the comments, the error youre
// seeing is because b is a net type by default; when
// describing logic in any always block, you need to
// use variable types, like reg or logic (for
// SystemVerilog); see the comment for a thread
// describing the difference
input wire [5:0] c);
// You dont really need any local signals as the logic is pretty simple
always @(*) begin // Always use either always @(*), assign or
// always_comb (if using SystemVerilog) for combinational logic
if (c == 6'b111111)
b = a; // For combinational logic, use blocking assignment ("=")
// instead of non-blocking assignment ("<="), NBA is used for
// registers/sequential logic
else
b = 4'b0101;
end
endmodule
模块查找错误(
input wire[3:0]a,//最好明确说明类型,即使
//这不是绝对必要的
output reg[3:0]b,//如注释中所述,您遇到的错误
//看到是因为默认情况下b是网络类型;当
//在任何always块中描述逻辑,您需要
//使用变量类型,如reg或logic(用于
//SystemVerilog);请参阅线程的注释
//描述差异
输入线[5:0]c);
//你不需要任何本地信号,因为逻辑很简单
始终@(*)开始//始终使用始终@(*)、分配或
//对于组合逻辑,始终使用\u梳(如果使用SystemVerilog)
如果(c==6'b111111)
b=a;//对于组合逻辑,使用分块赋值(“=”)
//非阻塞分配(“为了允许分配给始终块中的bw
,它需要声明为reg
。另一方面,creg
必须声明为wire
,而不是reg
,以便允许在连续分配的左侧(外部总是)。还请注意c
是6位宽,您可以将其与4位值进行比较。虽然这是一个很好的经验法则,但值得注意的是,这不是组合逻辑,因为使用了分块赋值。在这种情况下,这没有什么区别。例如,本指南在中的第11节中进行了解释,以供参考
module find_errors(
input [3:0] a,
output [3:0] b,
input [5:0] c
);
assign b = (c == 4'b1111) ? a : 4'b0101;
endmodule
module find_errors(
input wire [3:0] a, // Better to be explicit about the types even if
// its not strictly necessary
output reg [3:0] b, // As mentioned in the comments, the error youre
// seeing is because b is a net type by default; when
// describing logic in any always block, you need to
// use variable types, like reg or logic (for
// SystemVerilog); see the comment for a thread
// describing the difference
input wire [5:0] c);
// You dont really need any local signals as the logic is pretty simple
always @(*) begin // Always use either always @(*), assign or
// always_comb (if using SystemVerilog) for combinational logic
if (c == 6'b111111)
b = a; // For combinational logic, use blocking assignment ("=")
// instead of non-blocking assignment ("<="), NBA is used for
// registers/sequential logic
else
b = 4'b0101;
end
endmodule