diff --git a/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/hackathon_top.sv b/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/hackathon_top.sv index e09b12a8..9d29e62e 100644 --- a/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/hackathon_top.sv +++ b/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/hackathon_top.sv @@ -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, @@ -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, @@ -33,18 +28,18 @@ module hackathon_top // 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 ( @@ -52,7 +47,9 @@ module hackathon_top .reset ( reset ), .a ( a ), .b ( b ), - .value ( value ) + .value ( value ), + .sw ( sw ), // Direct connection to switch + .sw_state ( sw_state ) ); seven_segment_display @@ -62,11 +59,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 \ No newline at end of file diff --git a/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/rotary_encoder.sv b/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/rotary_encoder.sv index 015c63a1..066e9cb7 100644 --- a/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/rotary_encoder.sv +++ b/labs/9_events/2025_02_21_tijuana_solutions/extra_peripherals/2_rotary_encoder/rotary_encoder.sv @@ -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; @@ -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 @@ -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 \ No newline at end of file