I am building a 2 digit BCD adder using only one module. I am rather new to verilog so i don't know if i made a mistake with some of the assignments, but the simulation wont output any answer it just give me the X error for my output. I dont know if i made a mistake in coding the module or coding the simulation but all the waveform output shows is the inputs but give me no outputs. I just want to know where i went wrong. I am kinda stuck here.
The code for module is as follows:
`timescale 1ns / 1ps
module two_digit_BCDAdder(input [7:0] X, input Load, input clk, output [8:0]R );
reg [7:0] Q=0;
always @(posedge clk)
begin
if (Load)
Q<=X;
else
Q<=Q;
end
// 8 bit register
wire sum1, sum3;
//wires for both upper parallel adders sum1 left adder sum 3 right adder
wire cout1, cout2, cout3, cout4;
// wires for cout, being cout1 top left adder, cout 2 bottom left adder,
// cout3 top right adder, cout 4 bottom right adder
wire cin;
// wire for or gate connected to cin
wire d1,d2;
// D1 connects or gate of the comparator and cout 1 to PA bottom left,
// D2 connects or gate of the comparator and cout 1 to PA bottom right,
wire C1,C2;
// C1 comparator on the left
// C2 comparator on the right
assign cin = (cout1|cout2);
// Cin or gate
assign d1 = (cout1|C1);
assign d2 =(cout3|C2);
// Creation of or gates
assign C1 = (sum1 > 4'b1001);
assign C2= (sum3 > 4'b1001);
// Comparator sum hase tobe greater than 9 for BCD addition
assign {cout3, sum3}= {Q[0],Q[1],Q[2],Q[3]}+{X[0],X[1],X[2],X[3]};
// Top right Parallel Adder
assign {cout4,{R[0],R[1],R[2],R[3]}} = sum3+{1'b0,d2,d2,1'b0};
// Bottom left Comparator
assign {cout1,sum1} = {Q[4],Q[5],Q[6],Q[7]}+{X[4],X[5],X[6],X[7]}+cin;
// Top left Parallel Adder
assign {cout2,{R[4],R[5],R[6],R[7]}} = sum1 +{1'b0,d1,d1,1'b0};
// bottom left Parallel Adder
assign R[8]=(d1|cout2);
//or gate for final carry led
endmodule
This is the simulation code i am working with:
`timescale 1ns / 1ps
module BCD_sim();
reg [7:0]x;
reg b;
reg clk;
wire[8:0]r;
two_digit_BCDAdder uut(x,b,clk,r);
initial
begin
clk =0;
forever #1 clk=~clk;
end
initial
begin
x=0; b=0;
//Values for test
#2 x=55; b=1;
#2 x=55; b=0;
#4;
#2 x=99; b=1;
#2 x=99; b=0;
#4;
#2 x=87; b=1;
#2 x=78; b=0;
#4;
#2 x=25; b=1;
#2 x=75; b=0;
#4;
#2 x=33; b=1;
#2 x=66; b=0;
#4;
#2 x=69; b=1;
#2 x=96; b=0;
$finish;
end
endmodule