使用 Verilog 进行上采样

发布于 2024-11-07 10:00:07 字数 1311 浏览 0 评论 0原文

我需要使用 Verilog 对数据进行上采样(2 倍)。我认为使用三个端口作为输入,一个端口作为输出。输入端口有过滤、复位和时钟。输出端口被过滤。我还需要动态输入大小。我怎样才能用Verilog实现这一点。

编辑1: 我的输入和输出数据都是 16 位长。我只需要一个 Verilog 代码来执行此操作:

如果输入:1 2 3, 然后输出:1 0 2 0 3 0。

如果输入:1 2 3 4 5, 然后输出:1 0 2 0 3 0 4 0 5 0。

编辑2: 我创建了一个 verilog 文件来解决这个问题,但它没有解决我的问题。

US1.v 文件

`timescale 1ns / 1ps

module US1 (filterin,clk,filterinus);

    input [15:0] filterin;
    input clk;

    output reg [15:0] filterinus;

    integer i=0;

    always @ (posedge clk) begin
        if (i==0) begin
            filterinus <= filterin;
        end
        else begin
            filterinus <= 0;
        end
        i=~i;
    end


endmodule

我使用以下测试台测试了此代码:

Test.v 文件

`timescale 1ps/1ps
module Test;

    reg [15:0] filterin;
    reg clk;
    wire [15:0] filterinus;

    US1 uut (
        .filterin(filterin), 
        .clk(clk),
        .filterinus(filterinus)
    );

    initial begin
        clk = 1;

        filterin = 1;
        #2 filterin = 2;
        #2 filterin = 3;
        #2 filterin = 4;
        #2 filterin = 5;

        #30 $finish;
    end

    always #1 clk = ~clk;

endmodule

正如所见,我的输入是:1 2 3 4 5。 我的输出是: 1 0 3 0 5 0 5 0 5 0 ... 我需要看到:1 0 2 0 3 0 4 0 5 0 0 0 0 0...

I need to upsample(2x) my data using Verilog. I think to use three ports for input and one port for output. Input ports are filterin, reset and clock. Output port is filterout. Also I need dynamic input size. How can I realize this with Verilog.

Edit1:
My input and output datas are 16 bit long. I just need a Verilog code to do this:

If Input: 1 2 3,
Then Output: 1 0 2 0 3 0.

If Input: 1 2 3 4 5,
Then Output: 1 0 2 0 3 0 4 0 5 0.

Edit2:
I created a verilog file to solve this but it didn't solve my problem.

US1.v file

`timescale 1ns / 1ps

module US1 (filterin,clk,filterinus);

    input [15:0] filterin;
    input clk;

    output reg [15:0] filterinus;

    integer i=0;

    always @ (posedge clk) begin
        if (i==0) begin
            filterinus <= filterin;
        end
        else begin
            filterinus <= 0;
        end
        i=~i;
    end


endmodule

I tested this code with the following Test bench:

Test.v file

`timescale 1ps/1ps
module Test;

    reg [15:0] filterin;
    reg clk;
    wire [15:0] filterinus;

    US1 uut (
        .filterin(filterin), 
        .clk(clk),
        .filterinus(filterinus)
    );

    initial begin
        clk = 1;

        filterin = 1;
        #2 filterin = 2;
        #2 filterin = 3;
        #2 filterin = 4;
        #2 filterin = 5;

        #30 $finish;
    end

    always #1 clk = ~clk;

endmodule

As is seen, my input is: 1 2 3 4 5.
My output is: 1 0 3 0 5 0 5 0 5 0...
I need to see: 1 0 2 0 3 0 4 0 5 0 0 0 0 0...

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

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

发布评论

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

评论(2

月野兔 2024-11-14 10:00:07

对您的代码的一些评论,假设这是用于综合。

  • 不要在声明中初始化变量“i”。这并不总是可合成的。
  • 不要对单个切换位使用整数类型。这会使您的代码不太清晰,并使工具更加难以工作。
  • 切勿在同一个always块中混合阻塞和非阻塞赋值。

根据您的描述,我不确定您要在这里执行什么操作。您说的是上采样,但这不是线性或三次插值方法等典型方法。

A few comments on your code, assuming this is for synthesis.

  • Don't initialize the variable 'i' in a declaration. This is not always synthesizable.
  • Don't use an integer type for a single toggle bit. This makes your code less clear and makes the tools work harder.
  • Never mix blocking and non-blocking assignments in the same always block.

Given your description, I'm not sure what operation you're trying to implement here. You said upsampling but this isn't a typical approach such as linear or cubic interpolation methods.

橙味迷妹 2024-11-14 10:00:07

问题解决了。我从测试平台更改了过滤器输入周期,如下所示:

    filterin = 1;
    #4 filterin = 2;
    #4 filterin = 3;
    #4 filterin = 4;
    #4 filterin = 5;
    #4 filterin = 0;

我得到了输出: 1 0 2 0 3 0 4 0 5 0 0 0...

Problem solved. I changed filterin input period from my testbench like this:

    filterin = 1;
    #4 filterin = 2;
    #4 filterin = 3;
    #4 filterin = 4;
    #4 filterin = 5;
    #4 filterin = 0;

And I got my output: 1 0 2 0 3 0 4 0 5 0 0 0...

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