使用 Verilog 进行上采样
我需要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对您的代码的一些评论,假设这是用于综合。
根据您的描述,我不确定您要在这里执行什么操作。您说的是上采样,但这不是线性或三次插值方法等典型方法。
A few comments on your code, assuming this is for synthesis.
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.
问题解决了。我从测试平台更改了过滤器输入周期,如下所示:
我得到了输出: 1 0 2 0 3 0 4 0 5 0 0 0...
Problem solved. I changed filterin input period from my testbench like this:
And I got my output: 1 0 2 0 3 0 4 0 5 0 0 0...