Skip to content

Commit 349b9c8

Browse files
committed
Final fixes. IT WORKS!
Bug fixes made: * Correct the assignment of output enable of `adder_sub` * Make sure `i_en` for `dff_posedge` allowed input ONLY during +ve clk * Make `ring_counter` shift ONLY on -ve clk edge * Change bus split arrangement in `top` module. It is now a many-to-one assignment. Other changes: * Tweak test benches to conform to fixes * Change contents of `rom16_8bit` to test different programs
1 parent d0fed10 commit 349b9c8

File tree

6 files changed

+31
-27
lines changed

6 files changed

+31
-27
lines changed

hdl/adder_sub_8.v

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ module adder_sub_8(
2020
);
2121
adder_ripple_8bit r1(
2222
.a(A), .b(B_in), .cin(cin_adder),
23-
.sum(out), .cout(cout)
23+
.sum(add_sub_out), .cout(cout)
2424
);
2525

26+
wire add_sub_low_out_en = ~out_en;
27+
2628
tribuf_8bit tri8(
2729
.in(add_sub_out), .out(out),
28-
.low_enable(out_en)
30+
.low_enable(add_sub_low_out_en)
2931
);
3032
endmodule

hdl/dff_posedge.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module dff_posedge(
1313
output reg [DATA_WIDTH - 1:0] q;
1414
output [DATA_WIDTH - 1:0] qbar;
1515

16-
always @(posedge clk or clr or i_en)
16+
always @(posedge clk or clr)
1717
begin
1818
if(clr)
1919
q <= 0;

hdl/ring_counter.v

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
module ring_counter (t, clk, res);
44
input clk, res;
55
output reg [5:0] t = 6'b100000;
6-
// always @(negedge clk or res or t)
7-
always @(negedge clk)
6+
7+
always @(negedge clk or res)
88
begin
9-
if(res==1)
9+
if(res == 1)
1010
t = 6'b100000;
11-
else
11+
else if(clk == 0) // Essentially shift right ONLY when it is a falling edge
1212
begin
1313
if(t == 6'b000001)
1414
t = 6'b100000;

hdl/rom16_8bit.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ module rom16_8bit(
1313
begin
1414
case(addr)
1515
4'h0: data_out = 8'h08;
16-
4'h1: data_out = 8'h19;
16+
4'h1: data_out = 8'h29;
1717
4'h2: data_out = 8'hee;
1818
4'h3: data_out = 8'hff;
1919
4'h4: data_out = 8'h00;
2020
4'h5: data_out = 8'h00;
2121
4'h6: data_out = 8'h00;
2222
4'h7: data_out = 8'h00;
23-
4'h8: data_out = 8'h08;
24-
4'h9: data_out = 8'h01;
23+
4'h8: data_out = 8'h01;
24+
4'h9: data_out = 8'h08;
2525
4'ha: data_out = 8'h00;
2626
4'hb: data_out = 8'h00;
2727
4'hc: data_out = 8'h00;

hdl/top.v

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
module top(bus, clk, out, clr);
2-
output tri [7:0] bus;
1+
module top(bus_high, bus_low, clk, out, clr);
2+
output tri [3:0] bus_high;
3+
output tri [3:0] bus_low;
34
output [7:0] out;
45
input clk, clr;
56
// Globals
6-
wire [3:0] bus_high, bus_low;
7+
wire [7:0] bus;
78
wire buf_clk;
89

910
// Control signals
@@ -33,14 +34,14 @@ module top(bus, clk, out, clr);
3334
bufif1(buf_clk, clk, low_halt);
3435

3536
program_counter pc(
36-
.inc(inc), .clk(buf_clk), .pc_out_en(pc_out_en), .clr(clr), .out(bus_low)
37+
.inc(inc), .clk(buf_clk), .pc_out_en(pc_out_en), .clr(clr), .out(bus[3:0])
3738
);
3839

3940
wire [3:0] mar_out;
4041
wire ld_mar;
4142
not (ld_mar, low_ld_mar);
4243
dff_posedge #(4) mar(
43-
.d(bus_low), .q(mar_out), .i_en(ld_mar), .clr(clr), .clk(buf_clk)
44+
.d(bus[3:0]), .q(mar_out), .i_en(ld_mar), .clr(clr), .clk(buf_clk)
4445
);
4546

4647
rom16_8bit mem(
@@ -51,37 +52,37 @@ module top(bus, clk, out, clr);
5152
wire ld_ir;
5253
not (ld_ir, low_ld_ir);
5354
dff_posedge #(8) ir(
54-
.d({bus_high, bus_low}), .q(ir_out), .i_en(ld_ir), .clr(clr), .clk(buf_clk)
55+
.d(bus), .q(ir_out), .i_en(ld_ir), .clr(clr), .clk(buf_clk)
5556
);
5657

57-
tribuf_4bit buf0(.in(ir_out[3:0]), .out(bus_low), .low_enable(low_ir_out_en));
58+
tribuf_4bit buf0(.in(ir_out[3:0]), .out(bus[3:0]), .low_enable(low_ir_out_en));
5859
assign op_code = ir_out[7:4]; // Directly pass to control_sequencer
5960

6061

6162
wire [7:0] acc_out;
6263
wire ld_acc;
6364
not (ld_acc, low_ld_acc);
6465
dff_posedge #(8) acc(
65-
.d({bus_high, bus_low}), .q(acc_out), .i_en(ld_acc), .clr(clr), .clk(buf_clk)
66+
.d(bus), .q(acc_out), .i_en(ld_acc), .clr(clr), .clk(buf_clk)
6667
);
6768
wire low_acc_out_en;
6869
assign low_acc_out_en = ~acc_out_en;
69-
tribuf_8bit buf1(.in(acc_out), .out({bus_high, bus_low}), .low_enable(low_acc_out_en));
70+
tribuf_8bit buf1(.in(acc_out), .out(bus), .low_enable(low_acc_out_en));
7071

7172
wire [7:0] b_reg_out;
7273
wire ld_b_reg;
7374
not (ld_b_reg, low_ld_b_reg);
7475
dff_posedge #(8) b_reg(
75-
.d({bus_high, bus_low}), .q(b_reg_out), .i_en(ld_b_reg), .clr(clr), .clk(buf_clk)
76+
.d(bus), .q(b_reg_out), .i_en(ld_b_reg), .clr(clr), .clk(buf_clk)
7677
);
7778

78-
adder_sub_8 asub(.A(acc_out), .B(b_reg_out), .sub(sub_add), .cout(), .out({bus_high, bus_low}), .out_en(subadd_out_en));
79+
adder_sub_8 asub(.A(acc_out), .B(b_reg_out), .sub(sub_add), .cout(), .out(bus), .out_en(subadd_out_en));
7980

8081
wire ld_out_reg;
8182
not (ld_out_reg, low_ld_out_reg);
8283
dff_posedge #(8) out_reg(
83-
.d({bus_high, bus_low}), .q(out), .i_en(ld_out_reg), .clr(clr), .clk(buf_clk)
84+
.d(bus), .q(out), .i_en(ld_out_reg), .clr(clr), .clk(buf_clk)
8485
);
8586

86-
assign bus = {bus_high, bus_low};
87+
assign {bus_high, bus_low} = bus;
8788
endmodule

test/tb_top.v

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module tb_top();
22
reg clk, clr;
33
wire [7:0] out;
4-
wire [7:0] bus;
4+
wire [3:0] bus_high;
5+
wire [3:0] bus_low;
56
top uut(
6-
.bus(bus), .clk(clk), .clr(clr), .out(out)
7+
.bus_high(bus_high), .bus_low(bus_low), .clk(clk), .clr(clr), .out(out)
78
);
89

910
initial
1011
begin
11-
#10 clk = 1'b1;
12+
#10 clk = 1'b0;
1213
end
1314

1415
always
@@ -26,7 +27,7 @@ module tb_top();
2627
begin
2728
#2 clr = 1'b1;
2829
#6 clr = 1'b0;
29-
#300 $finish;
30+
#500 $finish;
3031
end
3132

3233
initial

0 commit comments

Comments
 (0)