diff --git a/blink.v b/blink.v index ac81a8f..050829a 100644 --- a/blink.v +++ b/blink.v @@ -10,25 +10,34 @@ module blink #( //--------------------------------------------------------- // Step duration: - // - for 0 Hz : 8 s + // - for 0.5 Hz : 2 s // - for others : 4 s //--------------------------------------------------------- - localparam integer STEP_4SEC_MAX = (F_CLK * 4) - 1; - localparam integer STEP_8SEC_MAX = (F_CLK * 8) - 1; + localparam integer STEP_2SEC_MAX = (F_CLK * 2) - 1; + localparam integer STEP_4SEC_MAX = (F_CLK * 4) - 1; // Step timer counter reg [31:0] step_cnt = 32'd0; - // Frequency index: 0..5 → 0,10,20,30,40,50 Hz + // Frequency index: 0..5 → 0, 10, 20, 30, 40, 50 Hz reg [2:0] freq_idx = 3'd0; // Half-period counter and current half-period length in clock cycles - reg [31:0] blink_cnt = 32'd0; - reg [31:0] max_count = 32'd0; + reg [31:0] blink_cnt = 32'd0; + reg [31:0] max_count = 32'd0; - // Base LED signal (before output inversions) + // Base LED signal (before output inversion) reg led_base = 1'b0; + //--------------------------------------------------------- + // 1 Hz generator for pin: divider from F_CLK + // Period 1 Hz = 1 s, half-period = 0.5 s + //--------------------------------------------------------- + localparam integer PIN_1HZ_HALF_MAX = (F_CLK / 2) - 1; + + reg [31:0] pin_cnt = 32'd0; + reg pin_base = 1'b0; + //--------------------------------------------------------- // Function to calculate half-period in clock cycles //--------------------------------------------------------- @@ -54,9 +63,9 @@ module blink #( //--------------------------------------------------------- always @(posedge clk) begin //----------------------------------------------------- - // Step timer: change frequency every 4 or 8 seconds + // Step timer: change frequency every 2 or 4 seconds //----------------------------------------------------- - if (step_cnt >= (freq_idx == 3'd0 ? STEP_8SEC_MAX : STEP_4SEC_MAX)) begin + if (step_cnt >= (freq_idx == 3'd1 ? STEP_2SEC_MAX : STEP_4SEC_MAX)) begin step_cnt <= 32'd0; // Cycle through 0→1→2→3→4→5→0... @@ -74,7 +83,7 @@ module blink #( max_count <= calc_max_count(freq_idx); //----------------------------------------------------- - // Blink generation + // Blink generation for led //----------------------------------------------------- if (max_count == 32'd0) begin // 0 Hz: hold current state, no blinking @@ -88,16 +97,26 @@ module blink #( blink_cnt <= blink_cnt + 32'd1; end end + + //----------------------------------------------------- + // 1 Hz generation for pin (independent of freq_idx) + //----------------------------------------------------- + if (pin_cnt >= PIN_1HZ_HALF_MAX) begin + pin_cnt <= 32'd0; + pin_base <= ~pin_base; + end else begin + pin_cnt <= pin_cnt + 32'd1; + end end //--------------------------------------------------------- // Outputs: - // led = inverted base signal - // pin = same as led + // led = inverted base signal (variable frequency) + // pin = 1 Hz // pin_10 = inverted pin //--------------------------------------------------------- assign led = ~led_base; - assign pin = led; - assign pin_10 = ~pin; + assign pin = pin_base; + assign pin_10 = led; endmodule \ No newline at end of file