Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

VHDL Code Of 2 input XOR -gate

Status
Not open for further replies.

channaveer_018

Newbie level 1
Joined
Jun 3, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,292
Hi,
I am new to VHDL programing and i had written a VHDL code on 2 input XOR gate using process and it compiles successfully but in test bench waveform i am unable to get the output that is for all possible inputs i am getting 0 output , I am using Xilinx 9.1 and the following is code

entity XOR2 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
C : out STD_LOGIC);
end XOR2;

architecture Behavioral of XOR2 is
begin

process(A,B)
begin
if((A='0') and (B='1')) then
C<='1';
elsif((A='1') and (B='0')) then
C<='1';
else
C<='0';
end if;
end process;

end Behavioral;
 

blooz

Advanced Member level 2
Joined
Dec 29, 2010
Messages
561
Helped
121
Reputation
242
Reaction score
116
Trophy points
1,343
Location
India
Activity points
4,989
There is no problem with the code ...
Works fine and here is the output in Xilinx ISE 13.1
 
Last edited:

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
Your code is fine.

Another way to have the XOR function is


Code VHDL - [expand]
1
2
if (A /= B) then C<='1';  -- if A not equal to B
else C<='0';


but in this case you will get a result of 1 even if the inputs are 'U' or 'Z'

or


Code VHDL - [expand]
1
C<= (A XOR B );


which will give a result of 0/1 only is both inputs are set to 0/1

Alex
 

ahmed_mahmoud

Junior Member level 1
Joined
Apr 22, 2010
Messages
19
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,416
i guess the second solution is better because there is no need for process
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
You can use any of the three ways in or out of a process, you just have to change the if else that can be used only inside the process with when else that can be used out of a process.


Code VHDL - [expand]
1
2
C<='1' WHEN (A /= B)
ELSE  '0';




Code VHDL - [expand]
1
2
C<='1' WHEN ((A='0') and (B='1')) OR ((A='1') and (B='0'))
ELSE  '0';





Alex
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top