Here is what I am trying to do (simplified and with extraneous fluff removed). Basically I have a multiplexed 8 bit address/data bus. I want to latch an address (0 or 1) and then write data to some output bits depending on the address (this seems to work just fine in the test bench when I simulate in Modelsim). Then I want to read the state of some input bits (this is the part that I can never see on the bidirectional bus in the simulator).
In the simulator my cpubus (in the testbench) always appears to be driven by the values in test bench, even if that is a Z value. How do I get it to show the value that is read back from the device?
my device toplevel:
module top (
inout wire [7:0] cpldbus,
input bit ale,
input bit rd,
input bit wr,
output reg [15:0] outbit,
input reg [15:0] inbit );
logic [7:0] addr;
logic [7:0] data;
always_ff @ (posedge ale, posedge wr)
begin
if (ale) addr = cpldbus; // when ale is true latch the address
if (wr)
begin
if (addr == 0) outbit[7:0] = cpldbus;
if (addr == 1) outbit[15:8] = cpldbus;
end
end
assign cpldbus = (rd) ? data : 8'bZ;
always_ff @ (posedge rd)
begin
if (addr == 2) data = inbit[7:0];
if (addr == 3) data = inbit[15:8];
end
endmodule
Here is the test bench:
module test ();
localparam time PERIOD = (1.0e9/14.7456e6)*1ns;
logic [7:0] cpubus;
bit ale;
bit rd;
bit wr;
reg [15:0] outbit;
reg [15:0] inbit;
logic [7:0] data;
// DUT
top u1(
.cpldbus(cpubus[7:0]),
.ale,
.rd,
.wr,
.outbit,
.inbit
);
initial
begin
// put some dummy data on inbit
inbit = 8'h33;
// Stimulus
$stop; // to allow signal setup on wave page
// Write A5 to addr 0
# PERIOD data = 0;
# PERIOD ale = 1;
# PERIOD ale = 0;
# PERIOD data = 8'hA5;
# PERIOD wr = 1;
# PERIOD wr = 0;
// Write 5A to addr 1
# PERIOD data = 1;
# PERIOD ale = 1;
# PERIOD ale = 0;
# PERIOD data = 8'h5A;
# PERIOD wr = 1;
# PERIOD wr = 0;
// Read addr 2
# PERIOD data = 2;
# PERIOD ale = 1;
# PERIOD ale = 0;
# PERIOD rd = 1;
# PERIOD rd = 0;
end
assign cpubus = (ale || wr) ? data : 8'bZ;
endmodule
Well, maybe this is working and I'm not supposed to see cpubus in the testbench take on the value of cpldbus in my device module. Am I correct in that? I do see the cpldbus of top driving out that h33 that I forced onto inbit. But at that time cpubus of the test module is showing tri-state.