File size: 1,933 Bytes
e3c2ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 18.09.2021 12:06:18
// Design Name: 
// Module Name: led_flash
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module led_flash(
    input clk,
    input rst_n,
    output led
    );
    
    parameter [63:0] CLK_RATE = 100000000;
    parameter [63:0]  FLASH_RATE_ON_MS = 1000;
    parameter [63:0]  FLASH_RATE_OFF_MS = 1000;    
    
    parameter [63:0]  FLASH_RATE_ON_CYCLES = CLK_RATE*FLASH_RATE_ON_MS/1000;
    parameter [63:0]  FLASH_RATE_OFF_CYCLES = CLK_RATE*FLASH_RATE_OFF_MS/1000;
    
    logic [31:0] flash_counter;
    logic on_not_off_flag;
    
    
    
    always_ff@(posedge clk, negedge rst_n) begin
       if (rst_n == 0) begin
           flash_counter <= 0;
           on_not_off_flag <= 0;
           
       end
       else begin
           if (on_not_off_flag) begin
               if (flash_counter < FLASH_RATE_ON_CYCLES-1) begin
                   flash_counter <= flash_counter + 1;
                   
               end  
               else begin
                   flash_counter <= 0;
                   on_not_off_flag <= ~on_not_off_flag;
                   
               end
           end
           else begin
               if (flash_counter < FLASH_RATE_OFF_CYCLES-1) begin
                   flash_counter <= flash_counter + 1;
                   
               end  
               else begin
                   flash_counter <= 0;
                   on_not_off_flag <= ~on_not_off_flag;
               
               end
           end  
       end
    end
    
    assign led = on_not_off_flag;
    
    
    
    
endmodule