userx2
Full Member level 3
Hello
I am trying to get a bus interface working. I have a statement in the code below that is
level[address] = data;
I have address latched = 3'b001 and I can szee the correct value is there.
However, the above does not work when I simulate it. It always produces 0 in the level[1] (or any other).
It immediately works correctly if I code it like this
level[1] = data_in;
Can siomeone please let me know how to get it to work correctly? It may have something to do with how address or level is declared?
More complete sample code below:
-------------------------------------------------------------------
------------------------------
Best regards
X
I am trying to get a bus interface working. I have a statement in the code below that is
level[address] = data;
I have address latched = 3'b001 and I can szee the correct value is there.
However, the above does not work when I simulate it. It always produces 0 in the level[1] (or any other).
It immediately works correctly if I code it like this
level[1] = data_in;
Can siomeone please let me know how to get it to work correctly? It may have something to do with how address or level is declared?
More complete sample code below:
-------------------------------------------------------------------
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 module test(address_in, data_io, wr, rd, reset ); input [2:0] address_in; inout [2:0] data_io; input wr, rd, reset; reg [2:0] data_in; reg [2:0] data_out; reg [2:0] address; reg [2:0] level[2:0]; reg [3:0] state; reg [3:0] last_state; reg wr_flag; reg rd_flag; reg last_wr_state; reg last_rd_state; reg [2:0] rd_state; wire n_rd; assign data_io = (!rd && !reset) ? data_out : 3'bz; clock master_clock(m_clock); //instantiate clock //cl = output always @ (posedge m_clock) begin if (wr != last_wr_state) //some edge on write line begin last_wr_state = wr; //positive edge, latch address and data if (wr) begin data_in = data_io; address = address_in; wr_flag = 1; end end else begin if (wr_flag) begin wr_flag = 1'b0; *****THIS FAILS HERE level[address] = data_in; //data and address latched earlier **It works like this instead level[1] = data_in; end else if (!rd) begin if (rd_state <= 3'd3) begin rd_state = rd_state + 1; //wait some clock cycles for address to stabilize end else if (rd_state == 3'd3) //after n clocks since neg edge on bus, latch internal data to address begin rd_state = rd_state + 1; data_out= level[address_in]; end else begin data_out= data_out; end end else begin state <= state; end end end endmodule
------------------------------
Best regards
X
Last edited by a moderator: