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

Reply

VHDL - Perhaps a newbie question...

 
Thread Tools Search this Thread
Old 12-22-2003, 10:16 AM   #1
Default Perhaps a newbie question...


Hello

I have a Dual Field Adder Entity, which is controlled by the control signal
fsel: If fsel is high the the
cout port is always 0 the adder performs a XOR operation, else this Adder
performs a normal addition with carry and sum.
Now i have the following problem: I have got 1 bit control signal for the
fsel. But i have to combine this 1
bit signal with a 32 bit input with a nand operation. How can i do this in
VHDL? Because for a logic operation as nand both operands need to be the
same length. Is there a trick? hope someone can give me a hint

Thanks a lot

library ieee;
use ieee.std_logic_1164.all;

entity dual_adder is
port (cin: in std_ulogic_vector(31 downto 0);
sin: in std_ulogic_vector(31 downto 0);
pin: in std_ulogic_vector(31 downto 0);
fsel: in std_ulogic;
cout: out std_ulogic_vector(31 downto 0);
sout: out std_ulogic_vector(31 downto 0)
);
end dual_adder;

architecture structural of dual_adder is
signal cinout : std_ulogic_vector(31 downto 0);
signal sinout : std_ulogic_vector(31 downto 0);
signal pinout : std_ulogic_vector(31 downto 0);
signal orout : std_ulogic_vector(31 downto 0);

begin
cinout <= not (cin and sin and fsel);
sinout <= cin xnor sin;
pinout <= pin nand
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
orout <= cinout or pinout;
cout <= orout nand cinout;
sout <= pin xnor sinout;
end structural;




Klaus Kleiner
  Reply With Quote
Old 12-22-2003, 10:53 AM   #2
Allan Herriman
 
Posts: n/a
Default Re: Perhaps a newbie question...
On Mon, 22 Dec 2003 11:16:32 +0100, "Klaus Kleiner"
<> wrote:

>Hello
>
>I have a Dual Field Adder Entity, which is controlled by the control signal
>fsel: If fsel is high the the
>cout port is always 0 the adder performs a XOR operation, else this Adder
>performs a normal addition with carry and sum.
>Now i have the following problem: I have got 1 bit control signal for the
>fsel. But i have to combine this 1
>bit signal with a 32 bit input with a nand operation. How can i do this in
>VHDL? Because for a logic operation as nand both operands need to be the
>same length. Is there a trick? hope someone can give me a hint



foo <= not bar when fsel = '1' else (others => '1');

It's not quite nand (think about what happens when fsel is 'X') but I
think it probably does what you want.

Regards,
Allan.


Allan Herriman
  Reply With Quote
Old 12-22-2003, 11:40 AM   #3
Egbert Molenkamp
 
Posts: n/a
Default Re: Perhaps a newbie question...

"Klaus Kleiner" <> schreef in bericht
news:bs6g86$a490g$...
> Hello
>
> I have a Dual Field Adder Entity, which is controlled by the control

signal
> fsel: If fsel is high the the
> cout port is always 0 the adder performs a XOR operation, else this Adder
> performs a normal addition with carry and sum.
> Now i have the following problem: I have got 1 bit control signal for the
> fsel. But i have to combine this 1
> bit signal with a 32 bit input with a nand operation. How can i do this in
> VHDL? Because for a logic operation as nand both operands need to be the
> same length. Is there a trick? hope someone can give me a hint


I added 4 possible solutions (functions included in a test environment).

Egbert Molenkamp


ENTITY and_bus_with_bit IS
GENERIC (buswidth : natural := 4);
PORT ( ibit : IN bit;
ibus : IN bit_vector(buswidth-1 DOWNTO 0);
obus : OUT bit_vector(buswidth-1 DOWNTO 0));
END and_bus_with_bit;

ARCHITECTURE demo1 OF and_bus_with_bit IS
FUNCTION "and" (l : IN bit; r : IN bit_vector)
RETURN bit_vector IS
VARIABLE res : bit_vector(r'RANGE);
BEGIN
FOR i IN r'RANGE LOOP
res(i) := l AND r(i);
END LOOP;
RETURN res;
END "and";

FUNCTION "and" (l : IN bit_vector; r : IN bit)
RETURN bit_vector IS
BEGIN
RETURN r and l;
END "and";

BEGIN
obus <= ibus AND ibit;
END demo1;

ARCHITECTURE demo2 OF and_bus_with_bit IS
FUNCTION "and" (l : IN bit; r : IN bit_vector)
RETURN bit_vector IS
CONSTANT lvec : bit_vector(r'RANGE) := (OTHERS => l);
BEGIN
RETURN lvec AND r;
END "and";

FUNCTION "and" (l : IN bit_vector; r : IN bit)
RETURN bit_vector IS
BEGIN
RETURN r and l;
END "and";

BEGIN
obus <= ibus AND ibit;
END demo2;


ARCHITECTURE demo3 OF and_bus_with_bit IS
FUNCTION "and" (l : IN bit; r : IN bit_vector)
RETURN bit_vector IS
CONSTANT nul_vector : bit_vector(r'RANGE) := (OTHERS => '0');
BEGIN
IF l ='1'
THEN RETURN r;
ELSE RETURN nul_vector;
END IF;
END "and";

FUNCTION "and" (l : IN bit_vector; r : IN bit)
RETURN bit_vector IS
BEGIN
RETURN r and l;
END "and";

BEGIN
obus <= ibus AND ibit;
END demo3;

ARCHITECTURE demo4 OF and_bus_with_bit IS
FUNCTION "and" (l : IN bit; r : IN bit_vector)
RETURN bit_vector IS
BEGIN
RETURN (r'RANGE => l) AND r;
END "and";

FUNCTION "and" (l : IN bit_vector; r : IN bit)
RETURN bit_vector IS
BEGIN
RETURN r and l;
END "and";

BEGIN
obus <= ibus AND ibit;
END demo4;




Egbert Molenkamp
  Reply With Quote
Old 12-22-2003, 12:18 PM   #4
Klaus Kleiner
 
Posts: n/a
Default Re: Perhaps a newbie question...

> I added 4 possible solutions (functions included in a test environment).


Thanks a lot for your help so I have to program a litte bit to solve my
problem. I have got another question perhaps you can give me a hint here

As you can see I have got a Ripple Carry Adder Entity. Now with this entity
for 1 bit I need instances with 2 bit, 3 bit 4 bit, 5 bit, 6 bit and 7 bit.
I have added the code for the 2-bit Ripple Carry Adder which works fine. But
is it somehow possible to do this with parameters? Because else I have to
write an own architecture for each single RCA and I dont know if this is
efficient

Thanks again for your help

library ieee;
use ieee.std_logic_1164.all;

entity RCA is port (
x,y: in std_ulogic;
cin: in std_ulogic;
cout: out std_ulogic;
sout: out std_ulogic
);
end RCA;

architecture RTL of RCA is
begin
sout <= (x xnor y) xnor cin;
cout <= (x nand y) nand ((x xnor y) or cin);
end RTL;
------------------------------------------------------------------
-- START: 2 Bit RCA
------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity BIT_2_RCA is port (
x0,y0: in std_ulogic;
x1,y1: in std_ulogic;
cin: in std_ulogic;
cout: out std_ulogic;
s0,s1: out std_ulogic
);
end BIT_2_RCA;


architecture RTL of BIT_2_RCA is

component RCA
port
(
x,y: in std_ulogic;
cin: in std_ulogic;
cout: out std_ulogic;
sout: out std_ulogic
);
end component;

signal carry : std_ulogic;
signal carry1 : std_ulogic;

begin
RCA0: RCA port map (x=>x0,y=>y0,cin=>'0',cout=>carry,sout=>s0);
RCA1: RCA port map (x=>x1,y=>y1,cin=>carry,cout=>carry1,sout=>s1);
end RTL;
------------------------------------------------------------------
-- ENDE: 2 Bit RCA
------------------------------------------------------------------




Klaus Kleiner
  Reply With Quote
Old 12-22-2003, 02:56 PM   #5
Egbert Molenkamp
 
Posts: n/a
Default Re: Perhaps a newbie question...
"Klaus Kleiner" <> schreef in bericht
news:bs6ndn$a7li2$...
>
> > I added 4 possible solutions (functions included in a test environment).

>
> Thanks a lot for your help so I have to program a litte bit to solve my
> problem. I have got another question perhaps you can give me a hint here
>
> As you can see I have got a Ripple Carry Adder Entity. Now with this

entity
> for 1 bit I need instances with 2 bit, 3 bit 4 bit, 5 bit, 6 bit and 7

bit.
> I have added the code for the 2-bit Ripple Carry Adder which works fine.

But
> is it somehow possible to do this with parameters? Because else I have to
> write an own architecture for each single RCA and I dont know if this is
> efficient
>


Use a generic in the entity:

ENTITY ... IS
GENERIC (w : integer := ;
PORT (x,y : std_logic_vector(w-1 DOWNTO 0); etc.

In the architure you can use a GENERATE statement something like:

ARCHITECTURE ...
BEGIN
label_required : FOR i IN 1 TO w GENERATE
inst: RCA PORT MAP (x(i),...)
END GENERATE;

The first and last instantantiation is probable a little bit different.

However, consider NOT using this approach (except for the generic in the
entity)!

There are packages available, i.e. numeric_std, that can handle your
problem.
If X and Y are vectors of type std_logic_vector you can write
unsigned(X) + unsigned (Y)
(of in case you use the synops package std_logic_unsigned, you can write: X
+ Y)
The synthesis tool will recognise the adder.

Egbert Molenkamp




Egbert Molenkamp
  Reply With Quote
Old 12-22-2003, 03:04 PM   #6
Klaus Kleiner
 
Posts: n/a
Default Re: Perhaps a newbie question...


> There are packages available, i.e. numeric_std, that can handle your
> problem.
> If X and Y are vectors of type std_logic_vector you can write
> unsigned(X) + unsigned (Y)
> (of in case you use the synops package std_logic_unsigned, you can write:

X
> + Y)
> The synthesis tool will recognise the adder.


Thanks again for your tip, but i have to use a a Carry Select Adder which
consists of 2 2-bit Ripple Carry Adder, 2 3-bit Ripple Carry Adder, 2 4-bit
Ripple Carry Adder, 4 5-bit Ripple Carry Adder, 2 6-bit Ripple Carry Adder,
2 7-bit Ripple Carry Adder. So i cant do this with a simple adder....




Klaus Kleiner
  Reply With Quote
Old 12-22-2003, 06:00 PM   #7
Mike Treseler
 
Posts: n/a
Default Re: Perhaps a newbie question...
Klaus Kleiner wrote:

> Thanks again for your tip, but i have to use a a Carry Select Adder which
> consists of 2 2-bit Ripple Carry Adder, 2 3-bit Ripple Carry Adder, 2 4-bit
> Ripple Carry Adder, 4 5-bit Ripple Carry Adder, 2 6-bit Ripple Carry Adder,
> 2 7-bit Ripple Carry Adder. So i cant do this with a simple adder....


What is the source of this curious constraint?

-- Mike Treseler



Mike Treseler
  Reply With Quote
Old 12-23-2003, 05:17 PM   #8
Tim Hubberstey
 
Posts: n/a
Default Re: Perhaps a newbie question...
Mike Treseler wrote:
>
> Klaus Kleiner wrote:
>
> > Thanks again for your tip, but i have to use a a Carry Select Adder which
> > consists of 2 2-bit Ripple Carry Adder, 2 3-bit Ripple Carry Adder, 2 4-bit
> > Ripple Carry Adder, 4 5-bit Ripple Carry Adder, 2 6-bit Ripple Carry Adder,
> > 2 7-bit Ripple Carry Adder. So i cant do this with a simple adder....

>
> What is the source of this curious constraint?


Curious constraints are often features of homework problems.
--
Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com


Tim Hubberstey
  Reply With Quote
Old 12-23-2003, 05:30 PM   #9
Steve Harrad
 
Posts: n/a
Default Re: Perhaps a newbie question...

> > What is the source of this curious constraint?

>
> Curious constraints are often features of homework problems.


No it isn't a homework. Its a project and we have to build an Multiplier in
GF(2^m) for the LEON Processor. And therefore for summing up the final carry
and sum array we need a Carry Select adder which consists of different
Ripple Carry Adders




Steve Harrad
  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
Sorry for the painfully newbie question Chip L DVD Video 2 03-20-2007 03:25 PM
Newbie PC DVD region question Geoff B DVD Video 8 03-11-2006 05:48 AM
Another newbie question Jerold Pearson DVD Video 1 12-11-2004 02:25 AM
Newbie Question: DVD Capacities Chris Kotchey DVD Video 3 09-29-2004 03:49 PM
Newbie Question Jeff Turl A+ Certification 6 10-18-2003 10:16 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