Altera_Forum
Honored Contributor
8 years agoProblem 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?