aboutsummaryrefslogtreecommitdiffstats
path: root/ecp5/synth/blinky.v
diff options
context:
space:
mode:
Diffstat (limited to 'ecp5/synth/blinky.v')
-rw-r--r--ecp5/synth/blinky.v34
1 files changed, 24 insertions, 10 deletions
diff --git a/ecp5/synth/blinky.v b/ecp5/synth/blinky.v
index 5327ab35..ac7c6ea3 100644
--- a/ecp5/synth/blinky.v
+++ b/ecp5/synth/blinky.v
@@ -1,13 +1,16 @@
-module top(input clk_pin, output [3:0] led_pin, output gpio0_pin);
+module top(input clk_pin, input btn_pin, output [3:0] led_pin, output gpio0_pin);
wire clk;
wire [7:0] led;
-
+ wire btn;
wire gpio0;
(* BEL="X0/Y35/PIOA" *) (* IO_TYPE="LVCMOS33" *)
TRELLIS_IO #(.DIR("INPUT")) clk_buf (.B(clk_pin), .O(clk));
+ (* BEL="X4/Y71/PIOA" *) (* IO_TYPE="LVCMOS33" *)
+ TRELLIS_IO #(.DIR("INPUT")) btn_buf (.B(btn_pin), .O(btn));
+
(* BEL="X0/Y23/PIOC" *) (* IO_TYPE="LVCMOS33" *)
TRELLIS_IO #(.DIR("OUTPUT")) led_buf_0 (.B(led_pin[0]), .I(led[0]));
(* BEL="X0/Y23/PIOD" *) (* IO_TYPE="LVCMOS33" *)
@@ -30,27 +33,38 @@ module top(input clk_pin, output [3:0] led_pin, output gpio0_pin);
(* BEL="X0/Y62/PIOD" *) (* IO_TYPE="LVCMOS33" *)
TRELLIS_IO #(.DIR("OUTPUT")) gpio0_buf (.B(gpio0_pin), .I(gpio0));
- localparam ctr_width = 28;
+ localparam ctr_width = 24;
+ localparam ctr_max = 2**ctr_width - 1;
reg [ctr_width-1:0] ctr = 0;
+ reg [9:0] pwm_ctr = 0;
+ reg dir = 0;
- always@(posedge clk)
- ctr <= ctr + 1'b1;
+ always@(posedge clk) begin
+ ctr <= btn ? ctr : (dir ? ctr - 1'b1 : ctr + 1'b1);
+ if (ctr[ctr_width-1 : ctr_width-3] == 0 && dir == 1)
+ dir <= 1'b0;
+ else if (ctr[ctr_width-1 : ctr_width-3] == 7 && dir == 0)
+ dir <= 1'b1;
+ pwm_ctr <= pwm_ctr + 1'b1;
+ end
reg [9:0] brightness [0:7];
-
+ localparam bright_max = 2**10 - 1;
reg [7:0] led_reg;
genvar i;
generate
for (i = 0; i < 8; i=i+1) begin
always @ (posedge clk) begin
- if (ctr[ctr_width-1 : ctr_width-3] > i)
- brightness[i] <= 10'h3FF;
- else if (ctr[ctr_width-1 : ctr_width-3] == i)
+ if (ctr[ctr_width-1 : ctr_width-3] == i)
+ brightness[i] <= bright_max;
+ else if (ctr[ctr_width-1 : ctr_width-3] == (i - 1))
brightness[i] <= ctr[ctr_width-4:ctr_width-13];
+ else if (ctr[ctr_width-1 : ctr_width-3] == (i + 1))
+ brightness[i] <= bright_max - ctr[ctr_width-4:ctr_width-13];
else
brightness[i] <= 0;
- led_reg[i] <= ctr[9:0] < brightness[i];
+ led_reg[i] <= pwm_ctr < brightness[i];
end
end
endgenerate