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

Reply

VHDL - Coding problem (beginner question)

 
Thread Tools Search this Thread
Old 08-01-2003, 10:13 AM   #1
Default Coding problem (beginner question)


I am new in the VHDL world. I have a question that a lot
of people among you will be able to answer? I use often
the following description but with different bus width.
But I am obliged to declare the whole, each time I change
the bus width. My question is: Does there exist a way to
code the entity with the bus width as a parameter ?

Thank in advance

smu

---------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity fd14ce is
Port ( ce : in std_logic;
clk : in std_logic;
clr : in std_logic;
d : in std_logic_vector(13 downto 0);
q : out std_logic_vector(13 downto 0));
end fd14ce;

architecture fd14ce_a of fd14ce is
begin
process (clk, clr) begin
if ( clr = '1') then
q <= (others => '0');
elsif ( rising_edge( clk) and ce='1') then
q <= d;
end if;
end process;
end fd14ce_a;




smu
  Reply With Quote
Old 08-01-2003, 11:59 AM   #2
Jamie
 
Posts: n/a
Default Re: Coding problem (beginner question)
Look up the keyword GENERIC

Jamie


"smu" <> wrote in message
news:3f2a2dde$0$1925$...
> I am new in the VHDL world. I have a question that a lot
> of people among you will be able to answer? I use often
> the following description but with different bus width.
> But I am obliged to declare the whole, each time I change
> the bus width. My question is: Does there exist a way to
> code the entity with the bus width as a parameter ?
>
> Thank in advance
>
> smu
>
> ---------------------------------------------------------
>
> library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
> use IEEE.STD_LOGIC_ARITH.ALL;
> use IEEE.STD_LOGIC_UNSIGNED.ALL;
>
> entity fd14ce is
> Port ( ce : in std_logic;
> clk : in std_logic;
> clr : in std_logic;
> d : in std_logic_vector(13 downto 0);
> q : out std_logic_vector(13 downto 0));
> end fd14ce;
>
> architecture fd14ce_a of fd14ce is
> begin
> process (clk, clr) begin
> if ( clr = '1') then
> q <= (others => '0');
> elsif ( rising_edge( clk) and ce='1') then
> q <= d;
> end if;
> end process;
> end fd14ce_a;
>
>





Jamie
  Reply With Quote
Old 08-01-2003, 12:09 PM   #3
Jonathan Bromley
 
Posts: n/a
Default Re: Coding problem (beginner question)
"smu" <> wrote in message
news:3f2a2dde$0$1925$...

> I am new in the VHDL world. I have a question that a lot
> of people among you will be able to answer? I use often
> the following description but with different bus width.
> But I am obliged to declare the whole, each time I change
> the bus width. My question is: Does there exist a way to
> code the entity with the bus width as a parameter ?


Yes, there are at least two possible methods.

> library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
> use IEEE.STD_LOGIC_ARITH.ALL;
> use IEEE.STD_LOGIC_UNSIGNED.ALL;


Already there are two problems here:

1) You don't need any arithmetic packages for the "fd14ce"
design. I suggest it's better to USE only the packages
you really need.

2) It is a VERY BAD IDEA to use both std_logic_arith and
std_logic_unsigned. I guess you are using some FPGA
tools that add these lines automatically. It's very
bad style. Learn how to use the numeric_std package
for all your

> entity fd14ce is

[14-bit edge-triggered register with asynchronous clear
and synchronous clock-enable]

Here are the two possible methods.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
(1) Using a generic to set the width

library ieee;
use ieee.std_logic_1164.all;

entity fdce_N is
generic ( N: positive := 1 ); -- bus width
port ( ce : in std_logic;
clk : in std_logic;
clr : in std_logic;
d : in std_logic_vector(N-1 downto 0);
q : out std_logic_vector(N-1 downto 0)
);
end;

Your architecture can remain the same. When you create an
instance of a component that matches this entity, you need
a generic map in addition to a port map:

signal Source, Result: std_logic_vector(15 downto 0);
...
...
inst: fdce_N
generic map (N => 12)
port map (...
d => Source,
q => Result);

Or perhaps even better...

inst: fdce_N
generic map ( N => Source'length )
port map ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
(2) Using unconstrained ports
library ieee;
use ieee.std_logic_1164.all;

entity fdce_any_width is
port ( ce : in std_logic;
clk : in std_logic;
clr : in std_logic;
d : in std_logic_vector;
q : out std_logic_vector
);
end;

The ports on this entity will automatically resize
to match the signal you connect to them. Once again
the architecture can remain the same.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
When you use unconstrained ports, there is a risk that
some fool will connect different-size buses to the D
and Q ports. To protect against this it is a good idea
to put an assertion into the architecture:

architecture ...
... -- signal declarations
begin
assert D'LENGTH = Q'LENGTH
report "Input and output ports have different width"
severity FAILURE;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Some synthesis tools don't handle unconstrained ports,
so try a simple example first, before you commit
to a lot of work. And of course you cannot synthesise
a design whose top level has unconstrained ports.

Good luck.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.





Jonathan Bromley
  Reply With Quote
Old 06-28-2006, 06:13 AM   #4
shobhit24
Junior Member
 
Join Date: Jun 2006
Posts: 5
Default
Hi

can u plz write me code for SRT Division(Sweeney,Robertson and Tocher)

I would be very thankfull to u,

Plz reply fast


shobhit24
shobhit24 is offline   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
Comcast + Wireless Internet Problem shadoweloc General Help Related Topics 1 07-01-2008 06:19 PM
matrix reloaded dialog problem? rolling DVD Video 1 02-18-2005 11:39 PM
Re: Odd mouse question «bonehead;\) A+ Certification 1 11-27-2004 04:22 AM
Re: Safe Mode Question (A+ question) Gordon Findlay A+ Certification 0 06-16-2004 10:48 AM
Re: The purpose of dvd region coding? Shouse DVD Video 1 09-02-2003 05:47 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