summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-12-05 14:42:32 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-12-05 14:42:32 +0100
commit959edc17ff8f4b71a258c3c66d25bd904fb98bf0 (patch)
tree9dc8802fcd0249acd5104644b3f3e185dd6885d4
parent074e43d92ac7de3fc8fb5ba6c4596c5cc58c4a0d (diff)
downloadiceFUN-959edc17ff8f4b71a258c3c66d25bd904fb98bf0.tar.gz
iceFUN-959edc17ff8f4b71a258c3c66d25bd904fb98bf0.tar.bz2
iceFUN-959edc17ff8f4b71a258c3c66d25bd904fb98bf0.zip
Modify blinky and add testbench
-rw-r--r--.gitignore2
-rw-r--r--blinky/.gitignore3
-rw-r--r--blinky/Makefile12
-rw-r--r--blinky/blinky.v25
-rw-r--r--blinky/blinky_tb.v35
-rw-r--r--blinky/iceFUN.pcf1
-rw-r--r--readMe4
7 files changed, 67 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ac9c187
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.asc
+*.bin
diff --git a/blinky/.gitignore b/blinky/.gitignore
new file mode 100644
index 0000000..dee9626
--- /dev/null
+++ b/blinky/.gitignore
@@ -0,0 +1,3 @@
+blinky.json
+blinky_tb
+blinky_tb.vcd
diff --git a/blinky/Makefile b/blinky/Makefile
index c254fc0..0345112 100644
--- a/blinky/Makefile
+++ b/blinky/Makefile
@@ -2,14 +2,13 @@
PROJ = blinky
DEVICE = 8k
-# Files
FILES = blinky.v
-.PHONY: blinky clean burn
+.PHONY: blinky clean burn sim
blinky:
# synthesize using Yosys
- yosys -p "synth_ice40 -top top -json $(PROJ).json" $(FILES)
+ yosys -p "synth_ice40 -top blinky -json $(PROJ).json" $(FILES)
# Place and route using nextpnr
nextpnr-ice40 -r --hx8k --json $(PROJ).json --package cb132 --asc $(PROJ).asc --opt-timing --pcf iceFUN.pcf
@@ -19,5 +18,10 @@ blinky:
burn:
iceFUNprog $(PROJ).bin
+sim:
+ iverilog -o blinky_tb blinky_tb.v blinky.v
+ vvp blinky_tb
+ gtkwave blinky_tb.vcd
+
clean:
- rm *.asc *.bin *blif
+ rm -f *.asc *.bin *blif *.vcd $(PROG).json $(PROJ)_tb
diff --git a/blinky/blinky.v b/blinky/blinky.v
index 8447683..2b23000 100644
--- a/blinky/blinky.v
+++ b/blinky/blinky.v
@@ -1,26 +1,25 @@
/*
- *
+ *
* Copyright(C) 2018 Gerald Coe, Devantech Ltd <gerry@devantech.co.uk>
- *
+ *
* Permission to use, copy, modify, and/or distribute this software for any purpose with or
* without fee is hereby granted, provided that the above copyright notice and
* this permission notice appear in all copies.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
+ *
*/
-
// Blink an LED provided an input clock
-/* module */
-module top (clk, led1, led2, led3, led4, led5, led6, led7, led8, lcol1, lcol2, lcol3, lcol4 );
+module blinky (clk, btn, led1, led2, led3, led4, led5, led6, led7, led8, lcol1, lcol2, lcol3, lcol4 );
/* I/O */
input clk;
+ input btn;
output led1;
output led2;
output led3;
@@ -38,13 +37,17 @@ module top (clk, led1, led2, led3, led4, led5, led6, led7, led8, lcol1, lcol2, l
reg [31:0] counter = 32'b0;
/* LED drivers - counter is inverted for display because leds are active low */
- assign {led8, led7, led6, led5, led4, led3, led2, led1} = counter[26:19] ^ 8'hff;
+ assign {led8, led7, led6, led5, led4, led3, led2, led1} = counter[28:21] ^ 8'hff;
assign {lcol4, lcol3, lcol2, lcol1} = 4'b1110;
-
- /* Count up on every edge of the incoming 12MHz clk */
+ /* Count on every edge of the incoming 12MHz clk */
always @ (posedge clk) begin
- counter <= counter + 1;
+ if (btn) begin
+ counter <= counter + 1;
+ end
+ else begin
+ counter <= counter - 1;
+ end
end
endmodule
diff --git a/blinky/blinky_tb.v b/blinky/blinky_tb.v
new file mode 100644
index 0000000..b6d3b08
--- /dev/null
+++ b/blinky/blinky_tb.v
@@ -0,0 +1,35 @@
+`timescale 1ns/1ns
+
+module blinky_tb;
+ reg clk;
+ reg btn;
+
+ initial begin
+ $dumpfile("blinky_tb.vcd");
+ $dumpvars(0,blinky_tb);
+
+ // $monitor("Time = %0t clk = %0d sig = %0d", $time, clk, sig);
+
+ clk = 0;
+ btn = 1;
+ #10 btn = 0;
+ #20 $finish;
+ end
+
+ wire led1;
+ wire led2;
+ wire led3;
+ wire led4;
+ wire led5;
+ wire led6;
+ wire led7;
+ wire led8;
+ wire lcol1;
+ wire lcol2;
+ wire lcol3;
+ wire lcol4;
+ blinky blinky_1 (clk, btn, led1, led2, led3, led4, led5, led6, led7, led8, lcol1, lcol2, lcol3, lcol4);
+
+ always #1 clk = ~clk;
+
+endmodule
diff --git a/blinky/iceFUN.pcf b/blinky/iceFUN.pcf
index cc011c4..1d4ce2c 100644
--- a/blinky/iceFUN.pcf
+++ b/blinky/iceFUN.pcf
@@ -13,3 +13,4 @@ set_io --warn-no-port lcol2 D10
set_io --warn-no-port lcol3 A6
set_io --warn-no-port lcol4 C5
set_io --warn-no-port clk P7
+set_io --warn-no-port btn A5
diff --git a/readMe b/readMe
index 117884b..e579d6a 100644
--- a/readMe
+++ b/readMe
@@ -1,3 +1,7 @@
+# mpb's iceFUN
+
+Original README from https://github.com/devantech/iceFUN:
+
To build these projects, install the icestorm toolchain from http://www.clifford.at/icestorm/
and the iceFUN programmer from https://github.com/devantech/iceFUNprog