Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
740 Views

Problem reading RAM.

I have a state machine 

when ST_MCP25625_TO_RAM_2 => if (idx1 < MAILBOX_COUNT-1) then temp_mailbox_addr := (MAILBOX_SIZE * idx1) + MAILBOX_OFFSET; ram_addr_a <= std_logic_vector(to_unsigned(temp_mailbox_addr, 10)); --load start address idx2 := 0; RamState <= ST_MCP25625_TO_RAM_3; else --mailbox not found RamState <= ST_RAM_IDLE; end if; when ST_MCP25625_TO_RAM_3 => if (idx2 < 4) then tmp_mailbox(idx2) <= slave_data_out1; if (to_integer(unsigned(ram_addr_a)) < RAM_SIZE) then ram_addr_a <= ram_addr_a + 1; end if; idx2 := idx2 + 1; else mailbox_id := tmp_mailbox(3) & tmp_mailbox(2) & tmp_mailbox(1) & tmp_mailbox(0); RamState <= ST_MCP25625_TO_RAM_4; end if;  

Initially temp_mailbox_addr = 2 

And RAM initialized  

address - data 

2 - 5 

3 - 6 

4 - 7 

5 - 8 

But after ST_MCP25625_TO_RAM_3 I read 

tmp_mailbox(0) = 0 

tmp_mailbox(1) = 5 

tmp_mailbox(2) = 6 

tmp_mailbox(3) = 7 

 

So it seems like a tact is missing to update ram_addr_a. 

 

So I did it this way 

when ST_MCP25625_TO_RAM_3 => if (idx2 < 4) then tmp_mailbox(idx2) <= slave_data_out1; idx2 := idx2 + 1; RamState <= ST_UPDATE_RAM_ADDR; else mailbox_id := tmp_mailbox(3) & tmp_mailbox(2) & tmp_mailbox(1) & tmp_mailbox(0); RamState <= ST_MCP25625_TO_RAM_4; end if; when ST_UPDATE_RAM_ADDR => if (to_integer(unsigned(ram_addr_a)) < RAM_SIZE) then ram_addr_a <= ram_addr_a + 1; end if; --this way the same problem --ram_addr_a <= std_logic_vector(to_unsigned(temp_mailbox_addr+idx2, 10)); RamState <= ST_MCP25625_TO_RAM_3;  

And now I read 

tmp_mailbox(0) = 5 

tmp_mailbox(1) = 5 

tmp_mailbox(2) = 6 

tmp_mailbox(3) = 7 

 

Where is my problem?
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
55 Views

Have you got a testbench?

Altera_Forum
Honored Contributor I
55 Views

 

--- Quote Start ---  

Have you got a testbench? 

--- Quote End ---  

 

 

It's hard to simulate but I'll try.
Altera_Forum
Honored Contributor I
55 Views

Using a testbench is by far the easiest way to debug these things. With just a couple of code snippets, the is no way we can really see what's going on.

Reply