Skip to content

Commit d46a243

Browse files
committed
First commit
1 parent b7bf315 commit d46a243

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

Diff for: Makefile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
PROJ_DIR := src/
2+
DEVICES_DIR := devices/
3+
4+
PROJ = $(PROJ_DIR)/stopwatch
5+
6+
all: $(PROJ).rpt $(PROJ).bin
7+
8+
$(PROJ).json: $(PROJ).v
9+
yosys -ql $(PROJ).yslog -p 'synth_ice40 -top top -json $@' $<
10+
11+
$(PROJ).asc: $(PROJ).json icebreaker.pcf
12+
nextpnr-ice40 -ql $(PROJ).nplog --up5k --package sg48 --freq 12 --asc $@ --pcf $(DEVICES_DIR)/icebreaker.pcf --json $<
13+
14+
$(PROJ).bin: $(PROJ).asc
15+
icepack $< $@
16+
17+
$(PROJ).rpt: $(PROJ).asc
18+
icetime -d up5k -c 12 -mtr $@ $<
19+
20+
$(PROJ)_tb: $(PROJ)_tb.v $(PROJ).v
21+
iverilog -o $@ $^
22+
23+
$(PROJ)_tb.vcd: $(PROJ)_tb
24+
vvp -N $< +vcd=$@
25+
26+
$(PROJ)_syn.v: $(PROJ).json
27+
yosys -p 'read_json $^; write_verilog $@'
28+
29+
$(PROJ)_syntb: $(PROJ)_tb.v $(PROJ)_syn.v
30+
iverilog -o $@ $^ `yosys-config --datdir/ice40/cells_sim.v`
31+
32+
$(PROJ)_syntb.vcd: $(PROJ)_syntb
33+
vvp -N $< +vcd=$@
34+
35+
prog: $(PROJ).bin
36+
iceprog $<
37+
38+
sudo-prog: $(PROJ).bin
39+
@echo 'Executing prog as root!!!'
40+
sudo iceprog $<
41+
42+
clean:
43+
rm -f $(PROJ).yslog $(PROJ).nplog $(PROJ).json $(PROJ).asc $(PROJ).rpt $(PROJ).bin
44+
rm -f $(PROJ)_tb $(PROJ)_tb.vcd $(PROJ)_syn.v $(PROJ)_syntb $(PROJ)_syntb.vcd
45+
46+
.SECONDARY:
47+
.PHONY: all prog clean

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# FPGA projects
2+
3+
This repo houses a collection of projects that use the iCEBreaker FPGA and the open source suite of tools for simulation, synthesis and place-and-route.

Diff for: devices/icebreaker.pcf

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 12 MHz clock
2+
set_io -nowarn CLK 35
3+
4+
# RS232
5+
set_io -nowarn RX 6
6+
set_io -nowarn TX 9
7+
8+
# LEDs and Button
9+
set_io -nowarn BTN_N 10
10+
set_io -nowarn LEDR_N 11
11+
set_io -nowarn LEDG_N 37
12+
13+
# RGB LED Driver
14+
set_io -nowarn LED_RED_N 39
15+
set_io -nowarn LED_GRN_N 40
16+
set_io -nowarn LED_BLU_N 41
17+
18+
# SPI Flash
19+
set_io -nowarn FLASH_SCK 15
20+
set_io -nowarn FLASH_SSB 16
21+
set_io -nowarn FLASH_IO0 14
22+
set_io -nowarn FLASH_IO1 17
23+
set_io -nowarn FLASH_IO2 12
24+
set_io -nowarn FLASH_IO3 13
25+
26+
# PMOD 1A
27+
set_io -nowarn P1A1 4
28+
set_io -nowarn P1A2 2
29+
set_io -nowarn P1A3 47
30+
set_io -nowarn P1A4 45
31+
set_io -nowarn P1A7 3
32+
set_io -nowarn P1A8 48
33+
set_io -nowarn P1A9 46
34+
set_io -nowarn P1A10 44
35+
36+
# PMOD 1B
37+
set_io -nowarn P1B1 43
38+
set_io -nowarn P1B2 38
39+
set_io -nowarn P1B3 34
40+
set_io -nowarn P1B4 31
41+
set_io -nowarn P1B7 42
42+
set_io -nowarn P1B8 36
43+
set_io -nowarn P1B9 32
44+
set_io -nowarn P1B10 28
45+
46+
# LEDs and Buttons (PMOD 2)
47+
set_io -nowarn LED1 26
48+
set_io -nowarn LED2 27
49+
set_io -nowarn LED3 25
50+
set_io -nowarn LED4 23
51+
set_io -nowarn LED5 21
52+
set_io -nowarn BTN1 20
53+
set_io -nowarn BTN2 19
54+
set_io -nowarn BTN3 18

Diff for: src/counter/counter.v

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
module counter(
2+
input CLK,
3+
output P1A1, P1A2, P1A3, P1A4, P1A7, P1A8, P1A9, P1A10
4+
);
5+
6+
/*
7+
using the 1bitsquared 7 segment display PMOD
8+
9+
////AAAA//// ////AAAA////
10+
// // // //
11+
FF BB FF BB
12+
// // // //
13+
////GGGG//// ////GGGG////
14+
// // // //
15+
EE CC EE CC
16+
// // // //
17+
////DDDD//// ////DDDD////
18+
19+
pin assignments:
20+
AA --> P1A1
21+
AB --> P1A2
22+
AC --> P1A3
23+
AD --> P1A4
24+
AE --> P1A7
25+
AF --> P1A8
26+
AG --> P1A9
27+
CA --> P1A10 (mux for digits)
28+
(decimal point unconnected)
29+
*/
30+
localparam COUNT_MAX = 99;
31+
32+
reg [7:0] count;
33+
wire [3:0] msd; // most significant digit
34+
wire [3:0] lsd;
35+
36+
always @(*) begin
37+
38+
end
39+
40+
wire ss_ctrl;
41+
wire [6:0] ss_bits;
42+
wire [7:0] seven_segment = {ss_ctrl, ss_bits}; // control and data bus
43+
assign { P1A10, P1A9, P1A8, P1A7, P1A4, P1A3, P1A2, P1A1 } = seven_segment; // assign to PMOD
44+
45+
seven_seg_decoder ss_decode_u(
46+
.din()
47+
);
48+
49+
module seven_seg_decoder (
50+
input [3:0] din,
51+
output [6:0] dout
52+
);
53+
reg digit;
54+
always @(*) begin
55+
digit = 7'b 1000000; // no latches
56+
case (din)
57+
4'h0: digit = 7'b 0111111;
58+
4'h1: digit = 7'b 0000110;
59+
4'h2: digit = 7'b 1011011;
60+
4'h3: digit = 7'b 1011011;
61+
4'h4: digit = 7'b 1100110;
62+
4'h5: digit = 7'b 1101101;
63+
4'h6: digit = 7'b 1111101;
64+
4'h7: digit = 7'b 0000111;
65+
4'h8: digit = 7'b 1011011;
66+
4'h9: digit = 7'b 1101111;
67+
4'hA: digit = 7'b 1110111;
68+
4'hB: digit = 7'b 1111100;
69+
4'hC: digit = 7'b 0111001;
70+
4'hD: digit = 7'b 1011110;
71+
4'hE: digit = 7'b 1111001;
72+
4'hF: digit = 7'b 1110001;
73+
endcase
74+
end
75+
assign dout = digit;
76+
endmodule
77+
78+
endmodule

0 commit comments

Comments
 (0)