aboutsummaryrefslogtreecommitdiffstats
path: root/phy_fpga/led_blink_mod.v
blob: 0d26f86add633beb5b01ea4bddfe6b51452994bf (plain)
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
// vim: ts=4 sw=4 noexpandtab
/*
 *   LED blinker
 *
 *   Copyright (c) 2019 Michael Buesch <m@bues.ch>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

`ifndef LED_BLINK_MOD_V_
`define LED_BLINK_MOD_V_


module led_blink #(
	parameter BLINK_ON_CLKS		= 1024,
	parameter BLINK_OFF_CLKS	= 1024,
) (
	input clk,
	input n_reset,
	input enable,
	output reg led,
);
	reg [31:0] led_on_count;
	reg [31:0] led_off_count;

	initial begin
		led <= 0;
		led_on_count <= 0;
		led_off_count <= 0;
	end

	always @(posedge clk) begin
		if (n_reset) begin
			if (led) begin
				if (led_on_count == 0) begin
					led <= 0;
					led_off_count <= BLINK_OFF_CLKS;
				end else begin
					led_on_count <= led_on_count - 1;
				end
			end else begin
				if (led_off_count == 0) begin
					if (enable) begin
						led <= 1;
						led_on_count <= BLINK_ON_CLKS;
					end
				end else begin
					led_off_count <= led_off_count - 1;
				end
			end
		end else begin
			led <= 0;
			led_on_count <= 0;
			led_off_count <= 0;
		end
	end
endmodule

`endif /* LED_BLINK_MOD_V_ */
bues.ch cgit interface