diff --git a/double_dabble_combinational/performance_test.xlsx b/double_dabble_combinational/performance_test.xlsx index 8edf3ec..f10d9f2 100644 Binary files a/double_dabble_combinational/performance_test.xlsx and b/double_dabble_combinational/performance_test.xlsx differ diff --git a/double_dabble_combinational/readme.md b/double_dabble_combinational/readme.md index e7deb5b..7a00c16 100644 --- a/double_dabble_combinational/readme.md +++ b/double_dabble_combinational/readme.md @@ -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() ); diff --git a/double_dabble_combinational/top.bat b/double_dabble_combinational/top.bat new file mode 100644 index 0000000..7a79553 --- /dev/null +++ b/double_dabble_combinational/top.bat @@ -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 diff --git a/double_dabble_combinational/top.gtkw b/double_dabble_combinational/top.gtkw new file mode 100644 index 0000000..994b1ab --- /dev/null +++ b/double_dabble_combinational/top.gtkw @@ -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 diff --git a/double_dabble_combinational/top.v b/double_dabble_combinational/top.v new file mode 100644 index 0000000..456c1c2 --- /dev/null +++ b/double_dabble_combinational/top.v @@ -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 diff --git a/double_dabble_combinational/top_tb.v b/double_dabble_combinational/top_tb.v new file mode 100644 index 0000000..0afc302 --- /dev/null +++ b/double_dabble_combinational/top_tb.v @@ -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 diff --git a/double_dabble_sequential/double_dabble.v b/double_dabble_sequential/double_dabble.v index 4b617d3..76e4069 100644 --- a/double_dabble_sequential/double_dabble.v +++ b/double_dabble_sequential/double_dabble.v @@ -36,6 +36,7 @@ module DoubleDabble #( Done_o <= 0; Binary <= 0; BCD <= 0; + BCD_o <= 0; State <= DOUBLE; end @@ -88,16 +89,6 @@ module DoubleDabble #( Done_o <= 1'b0; end end - - generate - genvar k; - for(k=0; k