[求助]各位大哥,双端口的testbench怎么写呢?
- UID
- 127648
- 性别
- 男
|
[求助]各位大哥,双端口的testbench怎么写呢?
我想实现两个双向的输入输出,但是双端口在仿真的时候为什么老是高阻呢?下面是我写的小程序,请教各位相应的testbench测试程序应该怎么写呢?谢谢各位大哥了!
module Dual_IO ( WR, RD, DATA_R, DATA_L ); // Wire Declaration input WR; input RD; inout [7:0] DATA_R; inout [7:0] DATA_L; reg [7:0] DATA_R_REG; reg [7:0] DATA_L_REG; wire [7:0] DATA_R_WIRE; wire [7:0] DATA_L_WIRE;
assign DATA_L_WIRE = (!WR&RD) ? DATA_L : DATA_L_WIRE; assign DATA_L = (WR&!RD)? DATA_L_REG :8'hzz; assign DATA_R_WIRE = (WR&!RD) ? DATA_R : DATA_R_WIRE; assign DATA_R = (!WR&RD)? DATA_R_REG :8'hzz; // Always Construct always @(WR or DATA_L_WIRE) if(!WR) DATA_R_REG <= DATA_L_WIRE; else DATA_R_REG <= 8'hzz; always @(RD or DATA_R_WIRE) if(!RD) DATA_L_REG <= DATA_R_WIRE; else DATA_L_REG <= 8'hzz;
endmodule |
|
|
|
|
|
- UID
- 132437
- 性别
- 女
|
“assign DATA_R_WIRE = (WR&!RD) ? DATA_R : DATA_R_WIRE;
assign DATA_R = (!WR&RD)? DATA_R_REG :8'hzz;”
不太懂verilog如果这两句是并行的那么就有问题。如果双向接口,就不可能同时读写。必须在一个状态里把入、出、高阻明确定义,也就是每个clk周期端口只能起到输入作用,或者输出作用,或者赋值高阻。
我用vhdl写过,是可以的 |
|
|
|
|
|
- UID
- 132434
- 性别
- 男
|
补充点东西,可能有用:大部分仿真软件在仿真的时候需要信号初值,否则后面一直是不定态,最好用reset给你的信号赋初值,这个初值在实际硬件里是可以没有的。 |
|
|
|
|
|
- UID
- 127648
- 性别
- 男
|
谢谢大家,如果你们要实现一个这样的两个双端口会怎样实现呢?最关键的是仿真应该怎样? |
|
|
|
|
|
- UID
- 132437
- 性别
- 女
|
就是在每个clk周期定义好三种状态的一种,仿真是可以实现的, |
|
|
|
|
|
- UID
- 127648
- 性别
- 男
|
`timescale 1ns/1ns
module Dual_IO_TB();
reg WR,RD;
wire [7:0] DATA_L;
wire [7:0] DATA_R;
reg [7:0] DATA_L_REG;
reg [7:0] DATA_R_REG;
parameter delay=100;
Dual_IO myTest(WR,RD,DATA_R,DATA_L);
always #100 WR = ~WR;
assign DATA_L = DATA_L_REG;
initial
begin
WR = 1;
RD = 0;
DATA_L_REG = 8'h52;
#(delay*2) DATA_L_REG= 8'h25;
#(delay*5) DATA_L_REG= 8'h44;
#4000 $stop;
end
initial $monitor($time,,,,"WR=%d,RD=%d,DATA_L=%d,DATA_R=%d",WR,RD,DATA_L,DATA_R);
endmodule
我是这样写的testbench,仿真不行,DATA_R为高阻 |
|
|
|
|
|