Advertisement
regzarr

LSIC - Main System

Nov 25th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns/1ps
  2.  
  3. module MainSystem(
  4.     input rst,              // Reset input (PIN_B8)
  5.     input clk,              // 50 MHz clock input (PIN_P11)
  6.     input switch_pause,     // Pause switch (PIN_C10)
  7.     input btn_start,        // Start button (PIN_A7)
  8.     output [6:0] hex0,      // 7-segment output for digit 0
  9.     output [6:0] hex1,      // 7-segment output for digit 1
  10.     output [6:0] hex2,      // 7-segment output for digit 2
  11.     output [6:0] hex3,      // 7-segment output for digit 3
  12.     output [6:0] hex4,      // 7-segment output for digit 4
  13.     output [6:0] hex5       // 7-segment output for digit 5
  14. );
  15.  
  16.     // Internal signals
  17.     wire clk_2_5MHz;         // 2.5 MHz clock from FrequencyDivider
  18.     wire [31:0] ms_count;    // Millisecond counter from TimeMeasurement
  19.     reg [1:0] opcode;        // FSM opcode for TimeMeasurement
  20.  
  21.     // Instantiate FrequencyDivider
  22.     FrequencyDivider freq_div (
  23.         .clk_in(clk),       // Input 50 MHz clock
  24.         .rst(rst),          // Reset input
  25.         .clk_out(clk_2_5MHz) // Output 2.5 MHz clock
  26.     );
  27.  
  28.     // Instantiate TimeMeasurement
  29.     TimeMeasurement timer (
  30.         .clk(clk_2_5MHz),    // 2.5 MHz clock input
  31.         .rst(rst),           // Reset input
  32.         .opcode(opcode),     // FSM control opcode
  33.         .ms_count(ms_count)  // Millisecond counter output
  34.     );
  35.  
  36.     // Instantiate SevenSegmentController
  37.     SevenSegmentController display (
  38.         .ms_count(ms_count), // Millisecond counter input
  39.         .hex0(hex0),         // 7-segment digit 0
  40.         .hex1(hex1),         // 7-segment digit 1
  41.         .hex2(hex2),         // 7-segment digit 2
  42.         .hex3(hex3),         // 7-segment digit 3
  43.         .hex4(hex4),         // 7-segment digit 4
  44.         .hex5(hex5)          // 7-segment digit 5
  45.     );
  46.  
  47.     // FSM logic for opcode control
  48.     always @(*) begin
  49.         // Default state: no operation
  50.         opcode = 2'b00;
  51.  
  52.         if (btn_start) begin
  53.             opcode = 2'b01; // Start
  54.         end else if (switch_pause) begin
  55.             opcode = 2'b11; // Pause
  56.         end
  57.     end
  58.  
  59. endmodule
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement