请教双向口的testbench 我用verilog写了个双向口,程序如下:
// test.v module test(xck, d_port, inp, outp, dir); input xck; inout [7:0] d_port; input [7:0] inp; output[7:0] outp; input dir;
reg [7:0] outpTemp; reg [7:0] d_portTemp;
assign outp=outpTemp; assign d_port=dir?d_portTemp:8'bzzzzzzzz;
[email=always@(posedge]always@(posedge[/email] xck) begin if(dir) // dir=1 做输出 d_portTemp <=inp; else // dir=0 输入 outpTemp<=d_portTemp; end endmodule
双向口的方向由dir控制. testbench程序如下: /*********************************** ** 模块名称:testbench ** 模块功能:产生测试激励向量 ************************************/
`timescale 1 ns / 1 ns module testbench(); //模块名命名为Libero默认的testbench reg clk; reg dir; reg [7:0] tempp; reg [7:0] in_temp; wire [7:0] out_temp; parameter period = 20 ; //测试时钟频率周期20ns always #(period/2) clk = ~clk; //产生测试时钟 initial begin clk = 0; dir = 1; #20000 dir = 0; in_temp=8'haa; #4000 in_temp=8'hbb; #8000 in_temp=8'hcc; #12000 in_temp=8'hdd; #16000 in_temp=8'hee; #20000 in_temp=8'h55;
tempp=8'h00; #20000 tempp=8'haa; #24000 tempp=8'hbb; #28000 tempp=8'hcc; #32000 tempp=8'hdd; #34000 tempp=8'hee; #40000 tempp=8'h55; end
test test_0(.xck(clk),.d_port(tempp),.inp(in_temp),.outp(out_temp),.dir(dir));
endmodule
我想在前20000ns时, dir为1, 双向口做位输出口, 后20000ns双向口做输入.
modelsim编译时提示tempp 口有问题, 但我不知道原因
请大家指点,谢谢! |