data/full_repos/permissive/189940829/Lab1-Timer/timer.v
data/verilator_xmls/9f66e3d9-b185-40cc-94b7-4c2bbcd83adf.xml
module stopwatch_01(clk,key_reset,key_start_pause,key_display_stop,

                    hex0,hex1,hex2,hex3,hex4,hex5,

                    led0,led1,led2,led3 );

  input clk,key_reset,key_start_pause,key_display_stop;
  output [6:0] hex0,hex1,hex2,hex3,hex4,hex5;
  output led0,led1,led2,led3;
  reg led0,led1,led2,led3;
  reg display_work;

  reg counter_work;

  parameter DELAY_TIME = 10000000;


  reg [3:0] minute_display_high ;
  reg [3:0] minute_display_low  ;
  reg [3:0] second_display_high ;
  reg [3:0] second_display_low  ;
  reg [3:0] msecond_display_high;
  reg [3:0] msecond_display_low ;

  reg [ 3:0] minute_counter_high ;
  reg [ 3:0] minute_counter_low  ;
  reg [ 3:0] second_counter_high ;
  reg [ 3:0] second_counter_low  ;
  reg [ 3:0] msecond_counter_high;
  reg [ 3:0] msecond_counter_low ;
  reg [31:0] counter_50M         ;
  parameter CONST_50M = 500000;

  reg reset_1_time;
  reg [31:0] counter_reset;
  reg start_1_time;
  reg [31:0] counter_start;
  reg display_1_time;
  reg [31:0] counter_display;
  reg start;
  reg display;


  sevenseg LED8_minute_display_high (minute_display_high,hex5);
  sevenseg LED8_minute_display_low (minute_display_low,hex4);
  sevenseg LED8_second_display_high (second_display_high,hex3);
  sevenseg LED8_second_display_low (second_display_low,hex2);
  sevenseg LED8_msecond_display_high (msecond_display_high,hex1);
  sevenseg LED8_msecond_display_low (msecond_display_low,hex0);

  initial begin
    start = 0;
    display = 1;

    led0 = start;
    led1 = display;
    led2 = 0;
    led3 = 0;

    counter_reset = 0;
    counter_start = 0;
    counter_display = 0;

    counter_50M = 0;
    msecond_counter_low = 0;
    msecond_counter_high = 0;
    second_counter_low = 0;
    second_counter_high = 0;
    minute_counter_low = 0;
    minute_counter_high = 0;

    msecond_display_low = 0;
    msecond_display_high = 0;
    second_display_low = 0;
    second_display_high = 0;
    minute_display_low = 0;
    minute_display_high = 0;
  end

  always @ (posedge clk)

    begin
      if(key_reset == 0)
        counter_reset = counter_reset + 1;
      else
        counter_reset = 0;

      if(key_start_pause == 0)
        counter_start = counter_start + 1;
      else
        counter_start = 0;

      if(key_display_stop == 0)
        counter_display = counter_display + 1;
      else
        counter_display = 0;

      if(counter_start == DELAY_TIME)
        start = ~start;

      if(counter_display == DELAY_TIME)
        display = ~display;

      if(counter_reset == DELAY_TIME) begin
        counter_50M = 0;
        msecond_counter_low = 0;
        msecond_counter_high = 0;
        second_counter_low = 0;
        second_counter_high = 0;
        minute_counter_low = 0;
        minute_counter_high = 0;
      end


      if(start == 1) begin
        counter_50M = counter_50M + 1;
        if(counter_50M == CONST_50M) begin
          counter_50M = 0;
          msecond_counter_low = msecond_counter_low + 1;
          if(msecond_counter_low == 10) begin
            msecond_counter_low = 0;
            msecond_counter_high = msecond_counter_high + 1;
            if(msecond_counter_high == 10) begin
              msecond_counter_high = 0;
              second_counter_low = second_counter_low + 1;
              if(second_counter_low == 10) begin
                second_counter_low = 0;
                second_counter_high = second_counter_high + 1;
                if(second_counter_high == 6) begin
                  second_counter_high = 0;
                  minute_counter_low = minute_counter_low + 1;
                  if(minute_counter_low == 10) begin
                    minute_counter_low = 0;
                    minute_counter_high = minute_counter_high + 1;
                    if(minute_counter_high == 6) begin
                      minute_counter_high = 0;
                      led3 = 1;
                    end
                  end
                end
              end
            end
          end
        end
      end

      if(display == 1 || counter_reset == DELAY_TIME) begin
        msecond_display_low = msecond_counter_low;
        msecond_display_high = msecond_counter_high;
        second_display_low = second_counter_low;
        second_display_high = second_counter_high;
        minute_display_low = minute_counter_low;
        minute_display_high = minute_counter_high;
      end

    led0 = start;
    led1 = display;
end
endmodule
module stopwatch_01(clk,key_reset,key_start_pause,key_display_stop,

                    hex0,hex1,hex2,hex3,hex4,hex5,

                    led0,led1,led2,led3 );


  input clk,key_reset,key_start_pause,key_display_stop;
  output [6:0] hex0,hex1,hex2,hex3,hex4,hex5;
  output led0,led1,led2,led3;
  reg led0,led1,led2,led3;
  reg display_work;

  reg counter_work;

  parameter DELAY_TIME = 10000000;


  reg [3:0] minute_display_high ;
  reg [3:0] minute_display_low  ;
  reg [3:0] second_display_high ;
  reg [3:0] second_display_low  ;
  reg [3:0] msecond_display_high;
  reg [3:0] msecond_display_low ;

  reg [ 3:0] minute_counter_high ;
  reg [ 3:0] minute_counter_low  ;
  reg [ 3:0] second_counter_high ;
  reg [ 3:0] second_counter_low  ;
  reg [ 3:0] msecond_counter_high;
  reg [ 3:0] msecond_counter_low ;
  reg [31:0] counter_50M         ;
  parameter CONST_50M = 500000;

  reg reset_1_time;
  reg [31:0] counter_reset;
  reg start_1_time;
  reg [31:0] counter_start;
  reg display_1_time;
  reg [31:0] counter_display;
  reg start;
  reg display;


  sevenseg LED8_minute_display_high (minute_display_high,hex5);
  sevenseg LED8_minute_display_low (minute_display_low,hex4);
  sevenseg LED8_second_display_high (second_display_high,hex3);
  sevenseg LED8_second_display_low (second_display_low,hex2);
  sevenseg LED8_msecond_display_high (msecond_display_high,hex1);
  sevenseg LED8_msecond_display_low (msecond_display_low,hex0);

  initial begin
    start = 0;
    display = 1;

    led0 = start;
    led1 = display;
    led2 = 0;
    led3 = 0;

    counter_reset = 0;
    counter_start = 0;
    counter_display = 0;

    counter_50M = 0;
    msecond_counter_low = 0;
    msecond_counter_high = 0;
    second_counter_low = 0;
    second_counter_high = 0;
    minute_counter_low = 0;
    minute_counter_high = 0;

    msecond_display_low = 0;
    msecond_display_high = 0;
    second_display_low = 0;
    second_display_high = 0;
    minute_display_low = 0;
    minute_display_high = 0;
  end

  always @ (posedge clk)

    begin
      if(key_reset == 0)
        counter_reset = counter_reset + 1;
      else
        counter_reset = 0;

      if(key_start_pause == 0)
        counter_start = counter_start + 1;
      else
        counter_start = 0;

      if(key_display_stop == 0)
        counter_display = counter_display + 1;
      else
        counter_display = 0;

      if(counter_start == DELAY_TIME)
        start = ~start;

      if(counter_display == DELAY_TIME)
        display = ~display;

      if(counter_reset == DELAY_TIME) begin
        counter_50M = 0;
        msecond_counter_low = 0;
        msecond_counter_high = 0;
        second_counter_low = 0;
        second_counter_high = 0;
        minute_counter_low = 0;
        minute_counter_high = 0;
      end


      if(start == 1) begin
        counter_50M = counter_50M + 1;
        if(counter_50M == CONST_50M) begin
          counter_50M = 0;
          msecond_counter_low = msecond_counter_low + 1;
          if(msecond_counter_low == 10) begin
            msecond_counter_low = 0;
            msecond_counter_high = msecond_counter_high + 1;
            if(msecond_counter_high == 10) begin
              msecond_counter_high = 0;
              second_counter_low = second_counter_low + 1;
              if(second_counter_low == 10) begin
                second_counter_low = 0;
                second_counter_high = second_counter_high + 1;
                if(second_counter_high == 6) begin
                  second_counter_high = 0;
                  minute_counter_low = minute_counter_low + 1;
                  if(minute_counter_low == 10) begin
                    minute_counter_low = 0;
                    minute_counter_high = minute_counter_high + 1;
                    if(minute_counter_high == 6) begin
                      minute_counter_high = 0;
                      led3 = 1;
                    end
                  end
                end
              end
            end
          end
        end
      end

      if(display == 1 || counter_reset == DELAY_TIME) begin
        msecond_display_low = msecond_counter_low;
        msecond_display_high = msecond_counter_high;
        second_display_low = second_counter_low;
        second_display_high = second_counter_high;
        minute_display_low = minute_counter_low;
        minute_display_high = minute_counter_high;
      end

    led0 = start;
    led1 = display;
end
endmodule