Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Board configuration: tang_nano_9k_lcd_480_272_tm1638_hackathon
// This module uses few parameterization and relaxed typing rules

// Updated hackathon_top.sv
module hackathon_top
(
input logic clock,
Expand All @@ -10,13 +9,9 @@ module hackathon_top
input logic [7:0] key,
output logic [7:0] led,

// A dynamic seven-segment display

output logic [7:0] abcdefgh,
output logic [7:0] digit,

// LCD screen interface

input logic [8:0] x,
input logic [8:0] y,

Expand All @@ -26,33 +21,29 @@ module hackathon_top

inout logic [3:0] gpio
);

// Exercise: Instantiate the ultrasonic module
// and the 7-segment display controller module,
// connect them with each other and with GPIO

// START_SOLUTION

// For rotary encoder A/B signals
wire a, b;

sync_and_debounce # (.w (2))
i_sync_and_debounce
(
.clk ( clock ),
.reset ( reset ),
.sw_in ( gpio [3:2] ),
.sw_out ( { b, a } )
);

// Connect A and B directly to gpio pins
assign a = gpio[2];
assign b = gpio[3];

// Connect switch directly to gpio[0]
wire sw = gpio[0]; // Direct connection to GPIO0

wire [15:0] value;
wire sw_state;

rotary_encoder i_rotary_encoder
(
.clk ( clock ),
.reset ( reset ),
.a ( a ),
.b ( b ),
.value ( value )
.value ( value ),
.sw ( sw ), // Direct connection to switch
.sw_state ( sw_state )
);

seven_segment_display
Expand All @@ -62,11 +53,12 @@ module hackathon_top
.clk ( clock ),
.rst ( reset ),
.number ( 32' (value) ),
.dots ( '0 ),
.dots ( {8{sw_state}} ), // Control decimal points with switch state
.abcdefgh ( abcdefgh ),
.digit ( digit )
);

// END_SOLUTION
// Display switch state on all LEDs
assign led = {8{sw_state}}; // Control LEDs with switch state

endmodule
endmodule
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
`include "config.svh"

// Rotary Encoder Ky-040

module rotary_encoder
(
input clk,
input reset,
input a,
input b,
output logic [15:0] value
output logic [15:0] value,
input sw,
output logic sw_state
);

logic prev_a;
Expand All @@ -22,7 +22,7 @@ module rotary_encoder
always_ff @ (posedge clk)
if (reset)
begin
value <= - 16'd1; // To do: figure out why we have to start with -1 and not 0
value <= - 16'd1;
end
else if (a && ! prev_a)
begin
Expand All @@ -32,4 +32,12 @@ module rotary_encoder
value <= value - 16'd1;
end

endmodule
// Simple switch handling with optional inversion
// Try both options to see which works with your hardware
// Option 1: Direct assignment
assign sw_state = sw;

// Option 2: Inverted (if switch is active-low)
// assign sw_state = !sw;

endmodule
Loading