从 Verilog 到 VHDL 的 Delta-sigma DAC

发布于 2024-10-10 00:28:07 字数 2109 浏览 9 评论 0原文

下面的代码在 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;

The code below implements a Delta-sigma DAC in Verilog, from a Xilinx application note and I want to write equivalent VHDL code. I don't know anything about Verilog and I'm beginner in VHDL so I had to make a lot of guesses and probably beginner errors (code below). I'm not sure the translation is correct can someone help please?

Original 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

My try in 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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-10-17 00:28:07

看起来您正在使用 ieee.std_logic_unsigned (或 _arith)或两者。

请不要这样做。请改用 ieee.numeric_std.all 。

我的 Verilog 相当不存在,所以我忘记了 Verilog 默认是有符号还是无符号算术...但无论是哪种,都将所有数字信号转换为有符号或无符号的信号要匹配的类型。

您的重置子句可能想要读取类似以下内容:

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+2 更改为 width+1 以符合您对 width 通用的意图)

It looks like you're using ieee.std_logic_unsigned (or _arith) or both.

Please don't do that. Use ieee.numeric_std.all instead.

My Verilog is fairly non-existent, so I forget if Verilog defaults to signed or unsigned arithmetic... But whichever it is, make all your numerical signals into signed or unsigned types to match.

Your reset clause probably wants to read something like:

sigmalatch <= (width+1 => '1', others => '0');

and the deltafeedback update is something like:

deltafeedback(width+2 downto width+1) <= sigmalatch(width+2) & sigmalatch(width+2);
deltafeedback(width downto 0) <= (others => '0');

Finally, to match the Verilog, I think your width generic should be called MSBI and set to 7, (or change all your width+2s to width+1s to match your intention for the width generic)

燃情 2024-10-17 00:28:07

如果您只是对 VHDL 中的 Delta-sigma DAC 感兴趣,您可以查看我发布到 alt.sources(请选择“原始消息”,保存到文件并对其运行“unshar”以获取源)。

沃伊泰克

If you are simply interested in Delta-sigma DAC in VHDL, you may take a look at my implementation posted to alt.sources (please select the "original message", save to a file and run "unshar" on it to get sources).

Wojtek

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文