Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - modulo function

 
Thread Tools Search this Thread
Old 05-18-2009, 10:39 PM   #1
Default modulo function


Hi
I am quite fresh with vhdl and i have a problem. How to realize modulo
function using signals not variables?
For example: modulo_signal <= sample_signal mod 65536;

Best regards,
qharz



qharz
  Reply With Quote
Old 05-19-2009, 01:05 AM   #2
AndreasWallner
 
Posts: n/a
Default Re: modulo function
On May 18, 11:39*pm, "qharz" <tkucha...@gmail.com> wrote:
> Hi
> I am quite fresh with vhdl and i have a problem. How to realize modulo
> function using signals not variables?
> For example: modulo_signal <= sample_signal mod 65536;
>
> Best regards,
> qharz


If you need to calculate mod 2^n it is as simple as just using the
array slice containing the data you seek.
You know x mod m gives you the rest of the division of x/m. If m is
2^n, you simply need to take the lower n bits of the array to get your
result.

x / m for m = 2^n is x >> m, the rest is then the part shifted away,
or x - (( x >> m ) << m), or if x is an std_logic_vector( ? downto 0),
result <= x( n - 1 downto 0);

Hope that helps,
Andreas Wallner


AndreasWallner
  Reply With Quote
Old 05-19-2009, 01:27 AM   #3
qharz
 
Posts: n/a
Default Re: modulo function

> x / m for m = 2^n is x >> m, the rest is then the part shifted away,
> or x - (( x >> m ) << m), or if x is an std_logic_vector( ? downto 0),
> result <= x( n - 1 downto 0);
>

It helps,
Thank You very much

qharz


qharz
  Reply With Quote
Old 05-19-2009, 01:52 PM   #4
Andy
 
Posts: n/a
Default Re: modulo function
On May 18, 4:39*pm, "qharz" <tkucha...@gmail.com> wrote:
> Hi
> I am quite fresh with vhdl and i have a problem. How to realize modulo
> function using signals not variables?
> For example: modulo_signal <= sample_signal mod 65536;
>
> Best regards,
> qharz


As long as the signal data types are either integer,
numeric_std.signed or .unsigned, your example will work just fine.
Numeric_std defines the modulo operator with .unsigned, .signed or
integer RH operands. It is also directly synthesizable so long as the
RH operand is a static (i.e. value is known at synthesis time),
integral power of two, which simplifies to simply a slice operation.
For the purposes of synthesis, "static" also includes such things as
for-loop indices, since loops are unrolled anyway.

Andy


Andy
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent function for itoa in Linux gcc compiler suse Software 0 03-06-2009 05:30 AM
How to assign a returns value of a javascript function to a hiddenfield in a webpart Chander Software 0 12-20-2007 09:14 AM
How to call C# function in javascript visj4u Software 2 04-23-2007 03:24 PM
MS Access not recognising Date() function tessythampan Software 0 08-28-2006 11:51 AM
I lost the "Help and Support" function from my start menu Keith A+ Certification 1 03-14-2005 03:05 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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