下面的代码在Verilog中实现了一个Delta-sigma DAC,它来自一个Xilinx应用程序说明,我想编写等效的VHDL代码。我对Verilog一无所知,我是VHDL的初学者,所以我不得不做很多猜测,可能是初学者的错误(下面的代码)。我不确定翻译是否正确,有人能帮忙吗?
原版Verilog
`timescale 100 ps / 10 ps
`define MSBI 7
module dac(DACout, DACin, Clk, Reset);
output DACout;
reg DACout;
input [`MSBI:0] DACin;
input Clk;
input Reset;
reg [`MSBI+2:0] DeltaAdder;
reg [`MSBI+2:0] SigmaAdder;
reg [`MSBI+2:0] SigmaLatch;
reg [`MSBI+2:0] DeltaB;
always @(SigmaLatch) DeltaB = {SigmaLatch[`MSBI+2], SigmaLatch[`MSBI+2]} << (`MSBI+1);
always @(DACin or DeltaB) DeltaAdder = DACin + DeltaB;
always @(DeltaAdder or SigmaLatch) SigmaAdder = DeltaAdder + SigmaLatch;
always @(posedge Clk or posedge Reset)
begin
if(Reset)
begin
SigmaLatch <= #1 1'bl << (`MSBI+1);
DACout <= #1 1'b0;
end
else
begin
SigmaLatch <== #1 SigmaAdder;
DACout <= #1 SigmaLatch[`MSBI+2];
end
end
endmodule我在VHDL中的尝试:
entity audio is
generic(
width : integer := 8
);
port(
reset : in std_logic;
clock : in std_logic;
dacin : in std_logic_vector(width-1 downto 0);
dacout : out std_logic
);
end entity;
architecture behavioral of audio is
signal deltaadder : std_logic_vector(width+2 downto 0);
signal sigmaadder : std_logic_vector(width+2 downto 0);
signal sigmalatch : std_logic_vector(width+2 downto 0);
signal deltafeedback : std_logic_vector(width+2 downto 0);
begin
deltafeedback <= (sigmalatch(width+2), sigmalatch(width+2), others => '0');
deltaadder <= dacin + deltafeedback;
sigmaadder <= deltaadder + sigmalatch;
process(clock, reset)
begin
if (reset = '1') then
sigmalatch <= ('1', others => '0');
dacout <= '0';
elsif rising_edge(clock) then
sigmalatch <= sigmaadder;
dacout <= sigmalatch(width+2);
end if;
end process;
end architecture;发布于 2011-01-04 15:09:00
看起来您正在使用ieee.std_logic_unsigned (或_arith)或两者兼用。
请不要那样做。使用ieee.numeric_std.all代替。
我的Verilog是相当不存在的,所以我忘记了Verilog是否默认为有符号的或无符号的算术.但无论是哪种类型,都要将所有数字信号转换为signed或unsigned类型来匹配。
您的reset子句可能希望读到这样的内容:
sigmalatch <= (width+1 => '1', others => '0');而deltafeedback更新类似于:
deltafeedback(width+2 downto width+1) <= sigmalatch(width+2) & sigmalatch(width+2);
deltafeedback(width downto 0) <= (others => '0');最后,为了匹配Verilog,我认为您的width泛型应该被称为MSBI并设置为7 (或者将您的所有width+2s更改为width+1s以匹配您对于width泛型的意图)。
发布于 2011-06-10 08:39:06
如果您只是对VHDL中的Delta-sigma感兴趣,您可以查看我发布到alt.sources的实现(请选择“原始消息”,保存到一个文件中,并在其上运行"unshar“以获取源代码)。
沃伊特克
https://stackoverflow.com/questions/4569252
复制相似问题