remove pll from original project
[trilby-hat-fpga] / blinky.v
1 module top(input clk,
2                 //#input btn,
3                 output green_led_d7,
4                 output orange_led_d8,
5                 output red_led_d5,
6                 output yellow_led_d6
7         );
8     localparam ctr_width = 24;
9     localparam ctr_max = 2**ctr_width - 1;
10     reg [ctr_width-1:0] ctr = 0;
11     reg [9:0] pwm_ctr = 0;
12     reg dir = 0;
13         reg btn = 0;
14
15     always@(posedge clk) begin
16     ctr <= dir ? ctr - 1'b1 - btn: ctr + 1'b1 + btn;
17         if (ctr[ctr_width-1 : ctr_width-3] == 0 && dir == 1)
18             dir <= 1'b0;
19         else if (ctr[ctr_width-1 : ctr_width-3] == 7 && dir == 0)
20             dir <= 1'b1;
21         pwm_ctr <= pwm_ctr + 1'b1;
22     end
23
24     reg [9:0] brightness [0:7];
25     localparam bright_max = 2**10 - 1;
26     reg [7:0] led_reg;
27
28     genvar i;
29     generate
30     for (i = 0; i < 8; i=i+1) begin
31        always @ (posedge clk) begin
32             if (ctr[ctr_width-1 : ctr_width-3] == i)
33                 brightness[i] <= bright_max;
34             else if (ctr[ctr_width-1 : ctr_width-3] == (i - 1))
35                 brightness[i] <= ctr[ctr_width-4:ctr_width-13];
36              else if (ctr[ctr_width-1 : ctr_width-3] == (i + 1))
37                  brightness[i] <= bright_max - ctr[ctr_width-4:ctr_width-13];
38             else
39                 brightness[i] <= 0;
40             led_reg[i] <= pwm_ctr < brightness[i];
41        end
42     end
43     endgenerate
44
45     // assign led = led_reg;
46         assign green_led_d7  = led_reg[2];
47         assign red_led_d5    = led_reg[3];
48         assign yellow_led_d6 = led_reg[4];
49         assign orange_led_d8 = led_reg[5];
50
51 endmodule