Behavioral Model Logic Error , BCD to Excess3 converter

3

3ashmawy

Guest
Hello,

I am trying to write a BCD-Excess3 converter in Behavioral Model. By
Adding 3 to Each Input And Printing the Output.Anyways Here is my
Code.

module Exess3 (In,Out);
input [0:3]In;
output [0:3]Out;
reg [0:3]Out;

always @ (In)
Out = In + 1'd3;

endmodule

module Sim;
reg [0:3]D;
wire [0:3]S;
Exess3 Exess3Sim(D,S);
initial
begin
D = 4'b0000;
repeat(9)
#20 D = D + 1'b1;
end

initial
$monitor ("ABCD = %b w = %b x = %b y = %b z =
%b",D,S[0],S[1],S[2],S[3]);
endmodule


The Output is :
ABCD = 0000 w = 0 x = 0 y = 0 z = 1
ABCD = 0001 w = 0 x = 0 y = 1 z = 0
ABCD = 0010 w = 0 x = 0 y = 1 z = 1
ABCD = 0011 w = 0 x = 1 y = 0 z = 0
ABCD = 0100 w = 0 x = 1 y = 0 z = 1
ABCD = 0101 w = 0 x = 1 y = 1 z = 0
ABCD = 0110 w = 0 x = 1 y = 1 z = 1
ABCD = 0111 w = 1 x = 0 y = 0 z = 0
ABCD = 1000 w = 1 x = 0 y = 0 z = 1
ABCD = 1001 w = 1 x = 0 y = 1 z = 0


The Output should be:
ABCD = 0000 w = 0 x = 0 y = 1 z = 1
ABCD = 0001 w = 0 x = 1 y = 0 z = 0
ABCD = 0010 w = 0 x = 1 y = 0 z = 1
ABCD = 0011 w = 0 x = 1 y = 1 z = 0
ABCD = 0100 w = 0 x = 1 y = 1 z = 1
ABCD = 0101 w = 1 x = 0 y = 0 z = 0
ABCD = 0110 w = 1 x = 0 y = 0 z = 1
ABCD = 0111 w = 1 x = 0 y = 1 z = 0
ABCD = 1000 w = 1 x = 0 y = 1 z = 1
ABCD = 1001 w = 1 x = 1 y = 0 z = 0



Thanx In Advance for any help,

3ashmawy
 
On Apr 13, 6:58 am, "3ashmawy" <3ashm...@gmail.com> wrote:
Hello,

I am trying to write a BCD-Excess3 converter in Behavioral Model. By
Adding 3 to Each Input And Printing the Output.Anyways Here is my
Code.

module Exess3 (In,Out);
input [0:3]In;
output [0:3]Out;
reg [0:3]Out;

always @ (In)
Out = In + 1'd3;

endmodule

module Sim;
reg [0:3]D;
wire [0:3]S;
Exess3 Exess3Sim(D,S);
initial
begin
D = 4'b0000;
repeat(9)
#20 D = D + 1'b1;
end

initial
$monitor ("ABCD = %b w = %b x = %b y = %b z =
%b",D,S[0],S[1],S[2],S[3]);
endmodule

The Output is :
ABCD = 0000 w = 0 x = 0 y = 0 z = 1
ABCD = 0001 w = 0 x = 0 y = 1 z = 0
ABCD = 0010 w = 0 x = 0 y = 1 z = 1
ABCD = 0011 w = 0 x = 1 y = 0 z = 0
ABCD = 0100 w = 0 x = 1 y = 0 z = 1
ABCD = 0101 w = 0 x = 1 y = 1 z = 0
ABCD = 0110 w = 0 x = 1 y = 1 z = 1
ABCD = 0111 w = 1 x = 0 y = 0 z = 0
ABCD = 1000 w = 1 x = 0 y = 0 z = 1
ABCD = 1001 w = 1 x = 0 y = 1 z = 0

The Output should be:
ABCD = 0000 w = 0 x = 0 y = 1 z = 1
ABCD = 0001 w = 0 x = 1 y = 0 z = 0
ABCD = 0010 w = 0 x = 1 y = 0 z = 1
ABCD = 0011 w = 0 x = 1 y = 1 z = 0
ABCD = 0100 w = 0 x = 1 y = 1 z = 1
ABCD = 0101 w = 1 x = 0 y = 0 z = 0
ABCD = 0110 w = 1 x = 0 y = 0 z = 1
ABCD = 0111 w = 1 x = 0 y = 1 z = 0
ABCD = 1000 w = 1 x = 0 y = 1 z = 1
ABCD = 1001 w = 1 x = 1 y = 0 z = 0

Thanx In Advance for any help,

3ashmawy

Your problem is with the line...

Out = In + 1'd3;

The constant "1'd3" specifies a one bit constant with the value "3".
You need at least 2 bits to get the value "3". You can try...

Out = In + 2'd3;
or
Out = In + 4'd3;
or
Out = In + 3;

All of these should work.

David Walker
 
If i wanted the following Simulator to work on the code how would the
description module have an Input and Output vectors while the
simulator have 4 inputs and 4 outputs

Simulator:
=========

module Sim;
reg [0:3]D;
wire x,y,z,w;
Exess3 Exess3Sim(D[0],D[1],D[2],D[3],x,y,z,w);
initial
begin

D = 4'b0000;
#20 repeat(9)
#20 D = D + 1'b1;
end

initial
$monitor ("ABCD = %b w = %b x = %b y = %b z = %b",D,w,x,y,z);
endmodule



Description Module:
===================
module Exess3 (In,Out);
input [0:3]In;
output [0:3]Out;
reg [0:3]Out;

always @ (In)
Out = In + 3;

endmodule




Comment:
========
I tried module
Exess3(In[0],In[1],In[2],In[3],Out[0],Out[1],Out[2],Out[3])


but it didnt work as part of the description module


Any Suggestion?

3ashmawy
 
On Apr 13, 9:07 am, "3ashmawy" <3ashm...@gmail.com> wrote:
If i wanted the following Simulator to work on the code how would the
description module have an Input and Output vectors while the
simulator have 4 inputs and 4 outputs

Simulator:
=========

module Sim;
reg [0:3]D;
wire x,y,z,w;
Exess3 Exess3Sim(D[0],D[1],D[2],D[3],x,y,z,w);
initial
begin

D = 4'b0000;
#20 repeat(9)
#20 D = D + 1'b1;
end

initial
$monitor ("ABCD = %b w = %b x = %b y = %b z = %b",D,w,x,y,z);
endmodule

Description Module:
===================
module Exess3 (In,Out);
input [0:3]In;
output [0:3]Out;
reg [0:3]Out;

always @ (In)
Out = In + 3;

endmodule

Comment:
========
I tried module
Exess3(In[0],In[1],In[2],In[3],Out[0],Out[1],Out[2],Out[3])

but it didnt work as part of the description module

Any Suggestion?

3ashmawy

How about...

Exess3 i_ex3(D, {w, x, y, z});

or even better

Exess3 i_ex3(.In(D), .Out({w, x, y, z}));

David Walker
 

Welcome to EDABoard.com

Sponsor

Back
Top