Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   VHDL (http://www.velocityreviews.com/forums/f18-vhdl.html)
-   -   Memory Mapped Register Help (http://www.velocityreviews.com/forums/t958631-memory-mapped-register-help.html)

KAY 03-13-2013 12:03 PM

Memory Mapped Register Help
 
Hi,

I need help setting up memory mapped registers. I would like to latch data to these registers when data has been written to the memory locations. How would I write VHDL for this?

Thanks,
K


KJ 03-13-2013 01:01 PM

Re: Memory Mapped Register Help
 
On Wednesday, March 13, 2013 8:03:57 AM UTC-4, KAY wrote:
> Hi, I need help setting up memory mapped registers. I would like to latch data to these registers when data has been written to the memory locations. How would I write VHDL for this? Thanks, K

entity foo is
Address: in natural range 0 to 255;
Write: in std_ulogic;
Write_data: in std_ulogic_vector(7 downto 0);
end foo;

architecture rtl of foo is
begin
process(clk)
begin
if rising_edge(clk) then
if (Write = '1') then
Mem(Address) <= Write_Data;
end if;
end if;
end process;
end rtl;

Kevin

KAY 03-13-2013 01:23 PM

Re: Memory Mapped Register Help
 
On Wednesday, March 13, 2013 6:01:36 AM UTC-7, KJ wrote:
> On Wednesday, March 13, 2013 8:03:57 AM UTC-4, KAY wrote:
>
> > Hi, I need help setting up memory mapped registers. I would like to latch data to these registers when data has been written to the memory locations. How would I write VHDL for this? Thanks, K

>
> entity foo is
>
> Address: in natural range 0 to 255;
>
> Write: in std_ulogic;
>
> Write_data: in std_ulogic_vector(7 downto 0);
>
> end foo;
>
>
>
> architecture rtl of foo is
>
> begin
>
> process(clk)
>
> begin
>
> if rising_edge(clk) then
>
> if (Write = '1') then
>
> Mem(Address) <= Write_Data;
>
> end if;
>
> end if;
>
> end process;
>
> end rtl;
>
>
>
> Kevin


Thanks so much for the reply,

Could you explain the line:
Mem(Address) <= Write_Data;

What is the Mem function? or am I just misunderstanding that line.

Thanks,
K

KJ 03-13-2013 03:32 PM

Re: Memory Mapped Register Help
 
> What is the Mem function? or am I just misunderstanding that line. Thanks, K

Sorry, missed a couple of lines...

Mem is a signal that is an array of the stuff that you want to store. Thiswould be defined inside the architecture like this...
architecture rtl of foo is
type t_My_Memory_Array is array(0 to 255) of std_ulogic_vector(Write_Data'range);
signal Mem: t_My_Memory_Array;
begin

Also, you don't say what you want to do with the data in the memory once ithas been written but presumably you would at least want to read it back addressed by the same address signal. That was not shown in the code either,but to implement that you would define a new output of the entity (I'll call it Read_Data) that is the same number of bits as 'Write_Data'. Then youadd the following line of code inside the 'if rising_edge' if statement, but outside the 'if Write='1'' statement as shown below

process(clk)
begin
if rising_edge(clk) then
if (Write = '1') then
Mem(Address) <= Write_Data;
end if;
Read_Data <= Mem(Address);
end if;
end process;

Kevin Jennings

KAY 03-16-2013 11:58 PM

Re: Memory Mapped Register Help
 
On Wednesday, March 13, 2013 8:32:45 AM UTC-7, KJ wrote:
> > What is the Mem function? or am I just misunderstanding that line. Thanks, K

>
>
>
> Sorry, missed a couple of lines...
>
>
>
> Mem is a signal that is an array of the stuff that you want to store. This would be defined inside the architecture like this...
>
> architecture rtl of foo is
>
> type t_My_Memory_Array is array(0 to 255) of std_ulogic_vector(Write_Data'range);
>
> signal Mem: t_My_Memory_Array;
>
> begin
>
>
>
> Also, you don't say what you want to do with the data in the memory once it has been written but presumably you would at least want to read it back addressed by the same address signal. That was not shown in the code either, but to implement that you would define a new output of the entity (I'll call it Read_Data) that is the same number of bits as 'Write_Data'. Then you add the following line of code inside the 'if rising_edge' if statement,but outside the 'if Write='1'' statement as shown below
>
>
>
> process(clk)
>
> begin
>
> if rising_edge(clk) then
>
> if (Write = '1') then
>
> Mem(Address) <= Write_Data;
>
> end if;
>
> Read_Data <= Mem(Address);
>
> end if;
>
> end process;
>
>
>
> Kevin Jennings


Thank you so much! I will try to implement it :)


All times are GMT. The time now is 05:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.