Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to create if else statement for VHDL

Status
Not open for further replies.

pearl87

Newbie level 4
Joined
Aug 22, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,309
how to create a if else statement when the statement i as below...
if a>b.c
{P='0110';
D='0000'
eleseif c>b>a
P='0110';
D='1111"
eleseif b>c>a
P='0110';
D='0000'
else a=b=c
P='0000'
D='0000'


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity comparator is
port( a, b, c : in std_logic_vector( 6 downto 0); --
p, D : out std_logic_vector( 3 downto 0));
end comparator;

architecture processing of comparator is

begin
process (a, b, c)
begin
if (a=> b)
then p<='1';
else
p<='0';
end if;
end process;
end architecture processing;


i try to do but dunno what is the problem as i am still new to VHDL codings... please do help me as i need to do this assignment
 

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity comparator is
port( a, b, c : in std_logic_vector( 6 downto 0); --
p, D : out std_logic_vector( 3 downto 0));
end comparator;

architecture processing of comparator is

begin
process (a, b, c)

begin
	if ([B]a <= b[/B]) then 
		p<=[B]"0001"[/B];
	else
		p<=[B]"0000"[/B];
	end if;
end process;

end architecture processing;

Bigger than or equal is written >=
P is a 4 bit vector, you can't assign a bit value to it.

Alex
 
to Mr Alex,
thanks for the help and I am still wondering can i compare 3 input together "a>b>c".... and give 2 output data 4 bit...
 

When you are working with vector and you want to write only one or more bits you can use:
for p in your example

p : out std_logic_vector( 3 downto 0);

p(3)<='1'; -- assign only bit 3 with value 1
p(0)<='0'; -- assign only bit 0 with value 0
p(3 down to 2)<= "01"; -- assign bits 3 and 2 with value 01 (partial assignment)
p(2 down to 0)<= "001"; -- assign bits 2,1 and 0 with value 001

Alex

---------- Post added at 17:26 ---------- Previous post was at 17:24 ----------

You can break it in 2 parts

if ((a>b) and (b>c)) then
set value here
set value here
else
do something
do something more
end if;
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top