summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordevantech <35335852+devantech@users.noreply.github.com>2019-03-27 15:46:07 +0000
committerGitHub <noreply@github.com>2019-03-27 15:46:07 +0000
commit4c1e26675235f455fb12770ef815ec4ad7c20a52 (patch)
treee46d96fd74d52d5b31ebc04c328aaaa9a99812c3
parent4a2fe3067cb08f12318c1e1ea0c1c27abe8ce051 (diff)
downloadiceFUN-4c1e26675235f455fb12770ef815ec4ad7c20a52.tar.gz
iceFUN-4c1e26675235f455fb12770ef815ec4ad7c20a52.tar.bz2
iceFUN-4c1e26675235f455fb12770ef815ec4ad7c20a52.zip
Add files via upload
-rw-r--r--music/Makefile21
-rw-r--r--music/iceFUN.pcf25
-rw-r--r--music/ledscan.v62
-rw-r--r--music/music.v132
-rw-r--r--music/readMe9
-rw-r--r--music/top.v115
6 files changed, 364 insertions, 0 deletions
diff --git a/music/Makefile b/music/Makefile
new file mode 100644
index 0000000..499116a
--- /dev/null
+++ b/music/Makefile
@@ -0,0 +1,21 @@
+# Project setup
+PROJ = music
+
+# Files
+FILES = top.v
+
+.PHONY: iceFUN clean burn
+
+iceFUN:
+ # synthesize using Yosys
+ yosys -p "synth_ice40 -top top -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
+ # Convert to bitstream using IcePack
+ icepack $(PROJ).asc $(PROJ).bin
+
+burn:
+ iceFUNprog $(PROJ).bin
+
+clean:
+ rm *.asc *.bin *blif
diff --git a/music/iceFUN.pcf b/music/iceFUN.pcf
new file mode 100644
index 0000000..5fb58d0
--- /dev/null
+++ b/music/iceFUN.pcf
@@ -0,0 +1,25 @@
+# For iceFUN board
+
+set_io --warn-no-port led1 C10
+set_io --warn-no-port led2 A10
+set_io --warn-no-port led3 D7
+set_io --warn-no-port led4 D6
+set_io --warn-no-port led5 A7
+set_io --warn-no-port led6 C7
+set_io --warn-no-port led7 A4
+set_io --warn-no-port led8 C4
+set_io --warn-no-port lcol1 A12
+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 spkp M12
+set_io --warn-no-port spkm M6
+set_io --warn-no-port key1 C11
+set_io --warn-no-port key2 C6
+set_io --warn-no-port key3 A11
+set_io --warn-no-port key4 A5
+set_io --warn-no-port red P14
+set_io --warn-no-port green N14
+set_io --warn-no-port blue L14
+
+set_io --warn-no-port clk12MHz P7
diff --git a/music/ledscan.v b/music/ledscan.v
new file mode 100644
index 0000000..dee7c7d
--- /dev/null
+++ b/music/ledscan.v
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+// LedScan takes the four led columns as inputs and outputs them to the led matrix
+
+module LedScan (
+ input clk12MHz,
+ input [7:0] leds1,
+ input [7:0] leds2,
+ input [7:0] leds3,
+ input [7:0] leds4,
+ output reg [7:0] leds,
+ output reg [3:0] lcol
+ );
+
+
+ /* Counter register */
+ reg [11:0] timer = 12'b0;
+
+
+ always @ (posedge clk12MHz) begin
+ case (timer[11:10])
+ 2'b00: begin
+ leds[7:0] <= leds1[7:0];
+ lcol[3:0] <= 4'b1110;
+ end
+ 2'b01: begin
+ leds[7:0] <= leds2[7:0];
+ lcol[3:0] <= 4'b1101;
+ end
+ 2'b10: begin
+ leds[7:0] <= leds3[7:0];
+ lcol[3:0] <= 4'b1011;
+ end
+ 2'b11: begin
+ leds[7:0] <= leds4[7:0];
+ lcol[3:0] <= 4'b0111;
+ end
+ endcase
+ end
+
+
+// increment the scan timer
+ always @ (posedge clk12MHz) begin
+ timer <= timer + 1;
+ end
+
+endmodule
diff --git a/music/music.v b/music/music.v
new file mode 100644
index 0000000..2ef6c6b
--- /dev/null
+++ b/music/music.v
@@ -0,0 +1,132 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+// LedScan takes the four led columns as inputs and outputs them to the led matrix
+
+module Music (
+ input clk12MHz,
+ input [7:0] midi,
+ output reg note
+ );
+
+ reg [14:0] notetime; // = 22933;
+
+// Timer register */
+ reg [14:0] timer = 15'b0;
+
+// increment the note timer
+ always @ (posedge clk12MHz) begin
+ if (timer==notetime) begin
+ timer <= 15'b0;
+ if(midi[7:0]==0) note <= note;
+ else note <= !note;
+ end
+ else timer <= timer + 1;
+ end
+
+
+ always @ (posedge clk12MHz) begin
+ notetime <= notetime;
+ case (midi[7:0])
+ 8'd60: notetime <= 22933; // C C4
+ 8'd67: notetime <= 15306; // G G4
+ 8'd72: notetime <= 11467; // c C5
+ 8'd74: notetime <= 10216; // d D5
+ 8'd76: notetime <= 9101; // e E5
+ endcase
+ end
+
+endmodule
+
+
+
+module CloseEncounters (
+ input clkNote,
+ input key,
+ output reg [7:0] midi
+ );
+
+ reg [2:0] state = 3'b000;
+
+ always @ (posedge clkNote) begin
+ midi[7:0] <= 0;
+ case (state)
+ 3'b000:
+ begin
+ if(key==0) state <= 3'b001;
+ else state <= 3'b000;
+ end
+ 3'b001:
+ begin
+ midi[7:0] <= 74;
+ state <= 3'b010;
+ end
+ 3'b010:
+ begin
+ midi[7:0] <= 76;
+ state <= 3'b011;
+ end
+ 3'b011:
+ begin
+ midi[7:0] <= 72;
+ state <= 3'b100;
+ end
+ 3'b100:
+ begin
+ midi[7:0] <= 60;
+ state <= 3'b101;
+ end
+ 3'b101:
+ begin
+ midi[7:0] <= 67;
+ state <= 3'b110;
+ end
+ 3'b110:
+ begin
+ midi[7:0] <= 67;
+ state <= 3'b000;
+ end
+ default: state <= 3'b000;
+ endcase
+ end
+
+endmodule
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/music/readMe b/music/readMe
new file mode 100644
index 0000000..2dad4e6
--- /dev/null
+++ b/music/readMe
@@ -0,0 +1,9 @@
+To build the music project, install the icestorm toolchain from http://www.clifford.at/icestorm/
+and the iceFUN programmer from https://github.com/devantech/iceFUNprog
+
+Open a terminal in the music folder and enter:
+make iceFUN
+make burn
+
+This project adds a tune to the leds project
+
diff --git a/music/top.v b/music/top.v
new file mode 100644
index 0000000..42c3a7a
--- /dev/null
+++ b/music/top.v
@@ -0,0 +1,115 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+`include "music.v"
+`include "ledscan.v"
+
+module top (
+ input clk12MHz,
+ input key1,
+ input key2,
+ input key3,
+ input key4,
+ output led1,
+ output led2,
+ output led3,
+ output led4,
+ output led5,
+ output led6,
+ output led7,
+ output led8,
+ output lcol1,
+ output lcol2,
+ output lcol3,
+ output lcol4,
+ output spkp,
+ output spkm
+ );
+
+// Counter register
+ reg [31:0] counter;
+
+// Midi note number
+ wire [7:0] midi;
+
+// these are the led holding registers, whatever you write to these appears on the led display
+ reg [7:0] leds1;
+ reg [7:0] leds2;
+ reg [7:0] leds3;
+ reg [7:0] leds4;
+
+// The output from the ledscan module
+ wire [7:0] leds;
+ wire [3:0] lcol;
+
+// The output from the music module
+ wire note;
+
+// map the output of ledscan to the port pins
+ assign { led8, led7, led6, led5, led4, led3, led2, led1 } = leds[7:0];
+ assign { lcol4, lcol3, lcol2, lcol1 } = lcol[3:0];
+
+
+// map the note output from the music module to the port pins
+ assign spkp = note;
+ assign spkm = !note;
+
+// instantiate the led scan module
+ LedScan scan (
+ .clk12MHz(clk12MHz),
+ .leds1(leds1),
+ .leds2(leds2),
+ .leds3(leds3),
+ .leds4(leds4),
+ .leds(leds),
+ .lcol(lcol)
+ );
+
+// instantiate the music module
+ Music music (
+ .clk12MHz(clk12MHz),
+ .midi(midi),
+ .note(note)
+ );
+
+// instantiate the close encounters module
+ CloseEncounters CE (
+ .clkNote(counter[21]),
+ .key(key1),
+ .midi(midi)
+ );
+
+
+// This is where you place data in the leds matrix for display.
+// Here we put a counter on the 1st column and a simple pattern on the others
+ always @ (*) begin
+ leds1[7:0] = ~counter[28:21];
+ leds2[7:0] = 8'b11111100;
+ leds3[7:0] = 8'b11100011;
+ leds4[7:4] = 4'b0011;
+ leds4[3:0] = {key4, key3, key2, key1 };
+ end
+
+// increment the counter every clock, only the upper bits are mapped to the leds.
+ always @ (posedge clk12MHz) begin
+ counter <= counter + 1;
+ end
+
+endmodule
+
+
+