Skip to content

Commit

Permalink
Merge pull request #61 from leonow32/decimal_counter
Browse files Browse the repository at this point in the history
Decimal counter
  • Loading branch information
leonow32 authored Dec 29, 2023
2 parents 6d9fae2 + e96e970 commit ed49f83
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 12 deletions.
Binary file modified double_dabble_combinational/performance_test.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion double_dabble_combinational/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Testbench tries to convert all possible values from zero to maximum and from max
.INPUT_BITS(),
.OUTPUT_DIGITS(),
.OUTPUT_BITS() // Optional
) DUT(
) DoubleDabble_inst(
.Binary_i(),
.BCD_o()
);
Expand Down
13 changes: 13 additions & 0 deletions double_dabble_combinational/top.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
iverilog -o top.o ^
top.v ^
top_tb.v ^
double_dabble.v ^
../rotary_encoder/encoder.v ^
../synchronizer/synchronizer.v ^
../edge_detector/edge_detector.v ^
../display_multiplexed_variable/display_multiplex.v ^
../decoder_7seg/decoder_7seg.v ^
../strobe_generator/strobe_generator.v
vvp top.o
del top.o
47 changes: 47 additions & 0 deletions double_dabble_combinational/top.gtkw
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[*]
[*] GTKWave Analyzer v3.3.100 (w)1999-2019 BSI
[*] Mon Dec 25 10:29:58 2023
[*]
[dumpfile] "top.vcd"
[dumpfile_mtime] "Mon Dec 25 10:29:37 2023"
[dumpfile_size] 88325
[savefile] "top.gtkw"
[timestart] 0
[size] 1920 1009
[pos] -9 -9
*-17.902624 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
[treeopen] top_tb.
[treeopen] top_tb.DUT.
[treeopen] top_tb.DUT.DisplayMultiplex_inst.
[treeopen] top_tb.DUT.Encoder_inst.
[sst_width] 197
[signals_width] 201
[sst_expanded] 1
[sst_vpaned_height] 297
@28
top_tb.Reset
top_tb.Clock
@200
-Encoder
@28
top_tb.DUT.Encoder_inst.AsyncA_i
top_tb.DUT.Encoder_inst.AsyncB_i
top_tb.DUT.Encoder_inst.Increment_o
top_tb.DUT.Encoder_inst.Decrement_o
@200
-Counter
@24
top_tb.DUT.Counter[15:0]
@22
top_tb.DUT.Decimal[15:0]
@200
-Display
@22
top_tb.DUT.DisplayMultiplex_inst.Data_i[31:0]
@28
top_tb.DUT.DisplayMultiplex_inst.SwitchCathode_o
@22
top_tb.DUT.DisplayMultiplex_inst.Cathodes_o[7:0]
top_tb.DUT.DisplayMultiplex_inst.Segments_o[7:0]
[pattern_trace] 1
[pattern_trace] 0
80 changes: 80 additions & 0 deletions double_dabble_combinational/top.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 231224

`default_nettype none

module top #(
parameter CLOCK_HZ = 25_000_000
)(
input wire Clock, // Pin 20
input wire Reset, // Pin 17
input wire EncoderA_i, // Pin 68
input wire EncoderB_i, // Pin 67
output wire [7:0] Cathodes_o, // Pin 40 41 42 43 45 47 51 52
output wire [7:0] Segments_o // Pin 39 38 37 36 35 34 30 29
);

// Encoder instance
wire Increment;
wire Decrement;

Encoder Encoder_inst(
.Clock(Clock),
.Reset(Reset),
.AsyncA_i(EncoderA_i),
.AsyncB_i(EncoderB_i),
.AsyncS_i(1'b1),
.Increment_o(Increment),
.Decrement_o(Decrement),
.ButtonPress_o(),
.ButtonRelease_o(),
.ButtonState_o()
);

// Up/down counter, range 0...9999 decimal
reg [15:0] Counter;

always @(posedge Clock, negedge Reset) begin
if(!Reset) begin
Counter <= 0;
end else if(Increment) begin
if(Counter == 16'd9999)
Counter <= 16'd0;
else
Counter <= Counter + 1'b1;
end else if(Decrement) begin
if(Counter == 16'd0)
Counter <= 16'd9999;
else
Counter <= Counter - 1'b1;
end
end

// Binary to BCD converter
wire [15:0] Decimal;

DoubleDabble #(
.INPUT_BITS(16),
.OUTPUT_DIGITS(4)
) DoubleDabble_inst(
.Binary_i(Counter),
.BCD_o(Decimal)
);

// Display instance
DisplayMultiplex #(
.CLOCK_HZ(CLOCK_HZ),
.SWITCH_PERIOD_US(1000),
.DIGITS(8)
) DisplayMultiplex_inst(
.Clock(Clock),
.Reset(Reset),
.Data_i({Decimal, Counter}),
.DecimalPoints_i(8'b00010000),
.Cathodes_o(Cathodes_o),
.Segments_o(Segments_o),
.SwitchCathode_o()
);

endmodule

`default_nettype wire
74 changes: 74 additions & 0 deletions double_dabble_combinational/top_tb.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 231224

`timescale 1ns/1ns

`default_nettype none
module top_tb();

parameter CLOCK_HZ = 1_000_000;
parameter real HALF_PERIOD_NS = 1_000_000_000.0 / (2 * CLOCK_HZ);

// Clock generator
reg Clock = 1'b1;
always begin
#HALF_PERIOD_NS;
Clock = !Clock;
end

// Variables
reg Reset = 0;
reg AsyncA = 1;
reg AsyncB = 1;
integer i;

// Variable dump
initial begin
$dumpfile("top.vcd");
$dumpvars(0, top_tb);
end

// Instantiate device under test
top #(
.CLOCK_HZ(CLOCK_HZ)
) DUT(
.Clock(Clock),
.Reset(Reset),
.EncoderA_i(AsyncA),
.EncoderB_i(AsyncB),
.Cathodes_o(),
.Segments_o()
);

// Test sequence
initial begin
$timeformat(-9, 3, "ns", 10);
$display("===== START =====");

@(posedge Clock);
Reset = 1'b1;

// 10 increment events
for(i=0; i<10; i=i+1) begin
#10000 AsyncA = 1'b0;
#10000 AsyncB = 1'b0;
#10000 AsyncA = 1'b1;
#10000 AsyncB = 1'b1;
#20000;
end

// 20 decrement events
for(i=0; i<20; i=i+1) begin
#10000 AsyncB = 1'b0;
#10000 AsyncA = 1'b0;
#10000 AsyncB = 1'b1;
#10000 AsyncA = 1'b1;
#20000;
end

@(posedge Clock);

$display("====== END ======");
$finish;
end

endmodule
11 changes: 1 addition & 10 deletions double_dabble_sequential/double_dabble.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module DoubleDabble #(
Done_o <= 0;
Binary <= 0;
BCD <= 0;
BCD_o <= 0;
State <= DOUBLE;
end

Expand Down Expand Up @@ -88,16 +89,6 @@ module DoubleDabble #(
Done_o <= 1'b0;
end
end

generate
genvar k;
for(k=0; k<OUTPUT_DIGITS; k=k+1) begin: Digit
wire [3:0] Dig = BCD[(k*4+3)-:4];
//assign Dig[k] = BCD[(k*4+3)-:4];
//assign Digit[k] = BCD[(k*4-1)-:4];
end
endgenerate


endmodule

Expand Down
2 changes: 1 addition & 1 deletion double_dabble_sequential/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Testbench tries to convert all possible values from zero to maximum and from max
DoubleDabble #(
.INPUT_BITS(),
.OUTPUT_DIGITS()
) DUT(
) DoubleDabble_inst(
.Clock(Clock),
.Reset(Reset),
.Start_i(),
Expand Down
13 changes: 13 additions & 0 deletions double_dabble_sequential/top.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
iverilog -o top.o ^
top.v ^
top_tb.v ^
double_dabble.v ^
../rotary_encoder/encoder.v ^
../synchronizer/synchronizer.v ^
../edge_detector/edge_detector.v ^
../display_multiplexed_variable/display_multiplex.v ^
../decoder_7seg/decoder_7seg.v ^
../strobe_generator/strobe_generator.v
vvp top.o
del top.o
65 changes: 65 additions & 0 deletions double_dabble_sequential/top.gtkw
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[*]
[*] GTKWave Analyzer v3.3.100 (w)1999-2019 BSI
[*] Mon Dec 25 10:26:31 2023
[*]
[dumpfile] "top.vcd"
[dumpfile_mtime] "Mon Dec 25 10:16:22 2023"
[dumpfile_size] 123314
[savefile] "top.gtkw"
[timestart] 0
[size] 1920 1009
[pos] -1 -1
*-18.008570 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
[treeopen] top_tb.
[treeopen] top_tb.DUT.
[treeopen] top_tb.DUT.DisplayMultiplex_inst.
[treeopen] top_tb.DUT.DoubleDabble_inst.
[treeopen] top_tb.DUT.Encoder_inst.
[sst_width] 197
[signals_width] 230
[sst_expanded] 1
[sst_vpaned_height] 466
@28
top_tb.Reset
top_tb.Clock
@200
-Encoder
@28
top_tb.DUT.Encoder_inst.AsyncA_i
top_tb.DUT.Encoder_inst.AsyncB_i
[color] 3
top_tb.DUT.Encoder_inst.Increment_o
top_tb.DUT.Encoder_inst.Decrement_o
@200
-Counter
@24
top_tb.DUT.Counter[15:0]
@200
-Double Dabble
@22
top_tb.DUT.DoubleDabble_inst.Binary_i[15:0]
@28
[color] 3
top_tb.DUT.DoubleDabble_inst.Start_i
@24
top_tb.DUT.DoubleDabble_inst.Counter[3:0]
@28
top_tb.DUT.DoubleDabble_inst.Busy_o
[color] 3
top_tb.DUT.DoubleDabble_inst.Done_o
@22
top_tb.DUT.DoubleDabble_inst.BCD[15:0]
top_tb.DUT.DoubleDabble_inst.BCD_o[15:0]
@200
-Display
@23
top_tb.DUT.Decimal[15:0]
@22
top_tb.DUT.DisplayMultiplex_inst.Data_i[31:0]
@28
top_tb.DUT.DisplayMultiplex_inst.SwitchCathode_o
@22
top_tb.DUT.DisplayMultiplex_inst.Cathodes_o[7:0]
top_tb.DUT.DisplayMultiplex_inst.Segments_o[7:0]
[pattern_trace] 1
[pattern_trace] 0
Loading

0 comments on commit ed49f83

Please sign in to comment.