DSPRelated.com
Forums

Single Port RAM in matlab

Started by Sanjay April 30, 2004
Hi,

I want to design a single ported RAM [Random Access
Memory] in matlab.

The Memory will have address, Data and Write Enable as
a Input Port.

Behaviour is

if addr>=0
if WE == 1
X(addr) = din;
end
Dout <= X(addr);
end;

So I need to define X as a array
I've defined as
X = zeros(1,128); % assume RAM size is 128

When I compile this code,I get error message as

while evaluating expression: Subscript indices must
either be real
positive integers or logicals

Can anyone help me on M script of RAM? Thanks in Advance
Sanjay

____________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html





Hi Sanjay,

In MATLAB, the array indices begin at 1 and not 0. So, change your code
accordingly and it should work.

Venu
----- Original Message -----
From: Sanjay <>
Date: Friday, April 30, 2004 2:46 am
Subject: [matlab] Single Port RAM in matlab

> Hi,
>
> I want to design a single ported RAM [Random Access
> Memory] in matlab.
>
> The Memory will have address, Data and Write Enable as
> a Input Port.
>
> Behaviour is
>
> if addr>=0
> if WE == 1
> X(addr) = din;
> end
> Dout <= X(addr);
> end;
>
> So I need to define X as a array
> I've defined as
> X = zeros(1,128); % assume RAM size is 128
>
> When I compile this code,I get error message as
>
> while evaluating expression: Subscript indices must
> either be real
> positive integers or logicals
>
> Can anyone help me on M script of RAM? > Thanks in Advance
> Sanjay >
>
> ____________________________________________________________
> Yahoo! Messenger - Communicate instantly..."Ping"
> your friends today! Download Messenger Now
> http://uk.messenger.yahoo.com/download/index.html >
> _____________________________________
> Note: If you do a simple "reply" with your email client, only the
> author of this message will receive your answer. You need to do a
> "reply all" if you want your answer to be distributed to the
> entire group.
>
> _____________________________________
> About this discussion group:
>
> To Join:
>
> To Post:
>
> To Leave:
>
> Archives: http://www.yahoogroups.com/group/matlab
>
> More DSP-Related Groups: http://www.dsprelated.com/groups.php3
> Yahoo! Groups Links >


I suspect the your problem is the first line of code
(addr>=0) which makes it possible for addr=0 and
X(addr) would be X(0). Vector indeces must be greater
than zero.

--- Sanjay <> wrote:
> Hi,
>
> I want to design a single ported RAM [Random Access
> Memory] in matlab.
>
> The Memory will have address, Data and Write Enable
> as
> a Input Port.
>
> Behaviour is
>
> if addr>=0
> if WE == 1
> X(addr) = din;
> end
> Dout <= X(addr);
> end;
>
> So I need to define X as a array
> I've defined as
> X = zeros(1,128); % assume RAM size is 128
>
> When I compile this code,I get error message as
>
> while evaluating expression: Subscript indices must
> either be real
> positive integers or logicals
>
> Can anyone help me on M script of RAM? > Thanks in Advance
> Sanjay
____________________________________________________________
> Yahoo! Messenger - Communicate instantly..."Ping"
> your friends today! Download Messenger Now
> http://uk.messenger.yahoo.com/download/index.html

=====
Juan I. Arvelo, Jr., Ph.D.
Johns Hopkins University
11100 Johns Hopkins Rd.
Laurel, MD 20723
240.228.4293

__________________________________


Hi,

Thank You for quick response.
addr > 0 worked.
But Now I landed with different issue.

My requirement is I need a Read Before write memory.
Here is my m code

function demux_out=syn_demux_ref(t,addr,din,we)
% Persistent variables for memory functions
X =(128:1);
persistent d0;
% Initialize persistent variables
if (t==0)
X = zeros(128:1);
d0 =0;
end
if (addr > 0)
if (we == 1)
X(addr) = din;
end
d0 = X(addr);
end demux_out =[d0];
return

what happens here is I write first into array and then
d0 will read it.

But my requrement is read before write, so I expect
zeros to be outputted from my array.

when I modify my m code as below

function demux_out=syn_demux_ref(t,addr,din,we)
% Persistent variables for memory functions
X =(128:1);
persistent d0;
% Initialize persistent variables
if (t==0)
X = zeros(128:1);
d0 =0;
end
if (addr > 0)
d0 = X(addr);
if (we == 1)
X(addr) = din;
end
end demux_out =[d0];
return

It does not work.
Matlab gives following error

Error in MATLAB Function block 'demux/Demux_ref/MATLAB
Fcn' while evaluating expression: Index exceeds matrix
dimensions

I'm not able to trace where exactly I'm doing mistake.

Is there a way I can do Read before write.

Thanks
Sanjay --- Ahmed El-Saied <> wrote: >
This Error results that you may had made an index =
> 0
> there is no index 0 in matlab ,,,, begin index from
> 1
> X(1) ---> First Element
> X(0) ---> Error , There is no index zero
> ----- Original Message -----
> From: "Sanjay" <>
> To: <>
> Sent: Friday, April 30, 2004 11:46 AM
> Subject: [matlab] Single Port RAM in matlab > > Hi,
> >
> > I want to design a single ported RAM [Random
> Access
> > Memory] in matlab.
> >
> > The Memory will have address, Data and Write
> Enable as
> > a Input Port.
> >
> > Behaviour is
> >
> > if addr>=0
> > if WE == 1
> > X(addr) = din;
> > end
> > Dout <= X(addr);
> > end;
> >
> > So I need to define X as a array
> > I've defined as
> > X = zeros(1,128); % assume RAM size is 128
> >
> > When I compile this code,I get error message as
> >
> > while evaluating expression: Subscript indices
> must
> > either be real
> > positive integers or logicals
> >
> > Can anyone help me on M script of RAM?
> >
> >
> > Thanks in Advance
> > Sanjay
> >
> >
> >
> >
> >
> >
> >
> >
>
____________________________________________________________
> > Yahoo! Messenger - Communicate instantly..."Ping"
> > your friends today! Download Messenger Now
> > http://uk.messenger.yahoo.com/download/index.html
> >
> >
> >
> > _____________________________________
> > Note: If you do a simple "reply" with your email
> client, only the author
> of this message will receive your answer. You need
> to do a "reply all" if
> you want your answer to be distributed to the entire
> group.
> >
> > _____________________________________
> > About this discussion group:
> >
> > To Join:
> >
> > To Post:
> >
> > To Leave:
> >
> > Archives: http://www.yahoogroups.com/group/matlab
> >
> > More DSP-Related Groups:
> http://www.dsprelated.com/groups.php3
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
>


____________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html



The matlab statement zeros(128:1); produces an empty
array. If you want to initialize a 128 x 1 size array
try zeros(128,1);

AMK Message: 6
Date: Mon, 3 May 2004 06:15:55 +0100 (BST)
From: Sanjay <>
Subject: Re: Single Port RAM in matlab

Hi,

Thank You for quick response.
addr > 0 worked.
But Now I landed with different issue.

My requirement is I need a Read Before write memory.
Here is my m code

function demux_out=syn_demux_ref(t,addr,din,we)
% Persistent variables for memory functions
X =(128:1);
persistent d0;
% Initialize persistent variables
if (t==0)
X = zeros(128:1);
d0 =0;
end
if (addr > 0)
if (we == 1)
X(addr) = din;
end
d0 = X(addr);
end demux_out =[d0];
return

what happens here is I write first into array and then
d0 will read it.

But my requrement is read before write, so I expect
zeros to be outputted from my array.

when I modify my m code as below

function demux_out=syn_demux_ref(t,addr,din,we)
% Persistent variables for memory functions
X =(128:1);
persistent d0;
% Initialize persistent variables
if (t==0)
X = zeros(128:1);
d0 =0;
end
if (addr > 0)
d0 = X(addr);
if (we == 1)
X(addr) = din;
end
end demux_out =[d0];
return

It does not work.
Matlab gives following error

Error in MATLAB Function block 'demux/Demux_ref/MATLAB
Fcn' while evaluating expression: Index exceeds matrix
dimensions

I'm not able to trace where exactly I'm doing mistake.

Is there a way I can do Read before write.

Thanks
Sanjay __________________________________