简体   繁体   English

我正在尝试实现卷积编码器。 我附上了我的代码。 我是 verilog 的初学者,我认为我的测试台工作不正常

[英]I'm trying to implement a convolution encoder. I have attached my code. I am a beginner in verilog and I don't think my testbench is working properly

`timescale 1 ns/1 ns

module VIT_ENC (Vx,Ux,tb_en,clock,reset);

`include "params_b213.v"

output [`n-1:0] Vx;
input  [`k-1:0] Ux;
input           tb_en;
input           clock;
input           reset;

reg [`m:0] encoder_reg;

always @(posedge clock or posedge reset)
   begin   
      if(reset)
         encoder_reg = 4'b0;
  
      if (tb_en==1'b0)
         encoder_reg = {Ux, encoder_reg[3:1]};
   end

assign Vx[1] = encoder_reg[3]^encoder_reg[1]^encoder_reg[0];
assign Vx[0] = encoder_reg[3]^encoder_reg[2]^encoder_reg[1]^encoder_reg[0];

endmodule

The always block does not work for some reason.由于某种原因,always 块不起作用。 The encoder_reg is not getting any values. encoder_reg 没有得到任何值。 How to assign values to a reg in an always block?如何为始终块中的 reg 赋值? EDIT: I am adding the test bench code also here.编辑:我也在此处添加测试台代码。 So we are giving some input to Ux, which has to get shifted and stored in encoder_reg.所以我们向 Ux 提供了一些输入,这些输入必须被移位并存储在 encoder_reg 中。 Modulo 2 addition(XOR) is performed between the bits of encoder_reg and stored in the output.在encoder_reg的位之间进行模2加法(XOR)并存储在output中。

`timescale 1 ns/1 ns

module tb_VIT_ENC();

`include "params_b213.v"

wire [`n-1:0] Vx;
reg [`k-1:0] Ux;
reg tb_en;
reg clock;
reg reset;

VIT_ENC 
dut(.Vx(Vx),.Ux(Ux),.tb_en(tb_en),.clock(clock),.reset(reset));

initial
begin
    Ux=1;tb_en=0;clock=1;reset=0;
    #100;
    Ux=0;tb_en=0;clock=1;reset=0;
    #100;
    Ux=1;tb_en=0;clock=1;reset=0;
    #100;
    Ux=0;tb_en=0;clock=1;reset=0;
end

endmodule

I can see that there is no clock signal generation in the test bench.我可以看到测试台中没有时钟信号生成。 Without a positive edge on the clock signal the registers are'nt going to work.如果时钟信号没有上升沿,寄存器就不会工作。 You could use the following initial block in your test bench, instead of driving clock = 1 every 100ns as written in your test bench.您可以在测试台中使用以下初始块,而不是在测试台中每 100ns 驱动clock = 1

initial
begin
  clock = 1'b1;
  forever #5 clock = ~clock; //Clock Generator
end

The initial block sets clock to 1 initially. initial块最初将clock设置为 1。 The next line toggles the clock after 5ns and sets clock to 0. The forever keyword ensures the clock toggles every 5 time units forever till the end of the simulation, thus generating a square wave of period 10 time units.下一行在 5ns 后切换时钟并将clock设置为forever关键字确保时钟永远每 5 个时间单位切换一次,直到模拟结束,从而生成周期为 10 个时间单位的方波。 (Given the timescale in your code 10 time units = 10 ns) (给定代码中的时间刻度 10 个时间单位 = 10 ns)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在用 Verilog 构建 ALU 并且我的自检测试台不断收到这个连续的蓝色错误? - I am building an ALU in Verilog and my self-checking testbench keeps receiving this continuous blue error? 如何在测试台上运行verilog代码? - How do I run the verilog code on a testbench? 我正在尝试在 verilog Quartus 中为 8 位 2x1 MUX 编写代码,但代码中有错误 - am trying to make code in verilog Quartus for 8-bit 2x1 MUX but i have errors in the code 我如何编写这个 verilog 测试平台? - How do I write this verilog testbench? 我的 verilog 代码出现此错误,“常量表达式的非法操作” - I'm getting this error for my verilog code, "Illegal operation for constant expression" 为什么会出现此错误:常量表达式的非法操作? - Why do I get this error: Illegal operation for constant expression? 如何更改代码。 Verilog测试平台代码 - How to change the code. verilog testbench code 当我尝试同时检查两个输入时总是阻塞我得到推断的锁存警告并且我的代码在 Verilog 中运行不一致 - When I try to check two inputs in one always block I am getting inferred latch warning and my code runs inconsistently in Verilog 尝试将我的 verilog 代码从 modelsim 传输到 quartus 时出现很多错误 - I got a lot of error when trying to tranfer my verilog code from modelsim to quartus 嗨,我正在尝试使用Verilog实现硬件的5级流水线16 * 16位矩阵乘法 - Hi, I am trying to implement a 5 stage pipelined 16*16 bit matrix multiplication using Verilog for a HW
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM