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.

[SOLVED] Comparator gives wrong Output

Status
Not open for further replies.

padfoot_1729

Newbie level 1
Joined
Aug 16, 2019
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
10
Hi guys,

I had been practicing a few problems in verilog and got stuck on this :

Question : write a program so that output should be 1 when 'x' is greater than or equal to 'y'
x and y are binary

My logic module:


Code Verilog - [expand]
1
2
3
4
5
6
7
module comparator(
input x,
input y,
output z);
 
assign z = ~y + x ;
endmodule



My stimulus/ test-bench module :


Code Verilog - [expand]
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
`timescale 1ns / 1ps
module stimulus;
reg x;
reg y;
wire z;
comparator uut (
    .x(x),
    .y(y),
    .z(z)
    );
initial
begin
x=0;
y=0;
#20 x=1;
#20 y=1;
 
#20 x=0;
#40;
 
end
initial
begin
 
$monitor("x=%d, y=%d, z=%d \n",x,y,z);
 
end
endmodule


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

OUTPUT OBTAINED:

output1.png

Please Help with the above issue, output is shown as 0 when x=1 and y=0.

Thank you!!
 
Last edited by a moderator:

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,938
Helped
1,822
Reputation
3,654
Reaction score
1,806
Trophy points
1,393
Location
USA
Activity points
60,151
Since the question wants you to compare values for greater than the inputs x and y should not be single bits but should instead be a vector, so they can be more than just 1'b1 and 1'b0.

If they are supposed to be 1-bit then the assignment z = ~y + x is wrong since adding won't tell you if x >= y

It should be simply z = ~(~x & y); // result is 0 only if x < y, otherwise if x==y or x>y it is 1
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top