Init with first project
This commit is contained in:
parent
c1e302872f
commit
70af4f9445
10 changed files with 36610 additions and 1 deletions
16
README.md
16
README.md
|
@ -1,3 +1,17 @@
|
|||
# icefunVHDL
|
||||
|
||||
Tinkering with the iceFUN FPGA board, based on the iCE40-HX8K FPGA
|
||||
Tinkering with the iceFUN FPGA board, based on the iCE40-HX8K FPGA.
|
||||
|
||||
This work is loosely based on the provided code distributed at [the DevanTech github repository](https://github.com/devantech/iceFUN). Since I'm not familiar with VHDL, this repository will be used to both write VHDL for the board, and slowly work my way up to learning Verliog.
|
||||
|
||||
Tools used:
|
||||
- [yosys](https://github.com/YosysHQ/yosys)
|
||||
- [GHDL](https://github.com/ghdl/ghdl)
|
||||
- [GHDL plugin for yosys](https://github.com/ghdl/ghdl-yosys-plugin)
|
||||
- [nextpnr-ice40](https://github.com/YosysHQ/nextpnr)
|
||||
- [iceFUNprog](https://github.com/devantech/iceFUNprog)
|
||||
|
||||
At time of writing, `iceFUNprog` is necessary on my specific setup, as `openFPGAloader` erroneously claims `unable to open ftdi device: -3 (device not found)`.
|
||||
|
||||
Currently working projects:
|
||||
- SimpleCounter: Counter using clock divider for input, and 8x4 LED matrix for display
|
||||
|
|
7
simpleCounter/Makefile
Normal file
7
simpleCounter/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
build:
|
||||
yosys -m ghdl -p 'ghdl -fsynopsys leds.vhd ledmux.vhd matrixToSevenSeg.vhd -e leds; write_verilog leds.v; synth_ice40 -top leds -json leds.json'
|
||||
nextpnr-ice40 --hx8k --package cb132 --json leds.json --pcf leds.pcf --asc leds.asc
|
||||
icepack leds.asc leds.bin
|
||||
|
||||
burn:
|
||||
iceFUNprog leds.bin
|
72
simpleCounter/ledmux.vhd
Normal file
72
simpleCounter/ledmux.vhd
Normal file
|
@ -0,0 +1,72 @@
|
|||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.std_logic_unsigned.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity ledmux is
|
||||
port(
|
||||
clock : in std_logic;
|
||||
reset_n : in std_logic;
|
||||
leds0 : in std_logic_vector(7 downto 0);
|
||||
leds1 : in std_logic_vector(7 downto 0);
|
||||
leds2 : in std_logic_vector(7 downto 0);
|
||||
leds3 : in std_logic_vector(7 downto 0);
|
||||
ledRow : out std_logic_vector(7 downto 0);
|
||||
ledCol : out std_logic_vector(3 downto 0)
|
||||
);
|
||||
end entity ledmux;
|
||||
|
||||
architecture arch of ledmux is
|
||||
|
||||
signal counter : std_logic_vector(12 downto 0);
|
||||
begin
|
||||
|
||||
syncCounter : process(clock) begin
|
||||
if(rising_edge(clock))then
|
||||
if(reset_n = '0') then
|
||||
counter <= (others => '0');
|
||||
else
|
||||
counter <= counter + "0000000000001";
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
muxCol : process (clock) begin
|
||||
if (reset_n = '0') then
|
||||
ledCol <= "0000";
|
||||
else
|
||||
case counter(12 downto 11) is
|
||||
when "00" =>
|
||||
ledCol <= "1110";
|
||||
when "01" =>
|
||||
ledCol <= "1101";
|
||||
when "10" =>
|
||||
ledCol <= "1011";
|
||||
when "11" =>
|
||||
ledCol <= "0111";
|
||||
when others =>
|
||||
ledCol <= "1111";
|
||||
end case;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
muxScan : process(clock) begin
|
||||
if (reset_n = '0') then
|
||||
ledRow <= leds0;
|
||||
else
|
||||
case counter(12 downto 11) is
|
||||
when "00" =>
|
||||
ledRow <= leds0;
|
||||
when "01" =>
|
||||
ledRow <= leds1;
|
||||
when "10" =>
|
||||
ledRow <= leds2;
|
||||
when "11" =>
|
||||
ledRow <= leds3;
|
||||
when others =>
|
||||
ledRow <= leds0;
|
||||
end case;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
end arch;
|
21580
simpleCounter/leds.asc
Normal file
21580
simpleCounter/leds.asc
Normal file
File diff suppressed because it is too large
Load diff
BIN
simpleCounter/leds.bin
Normal file
BIN
simpleCounter/leds.bin
Normal file
Binary file not shown.
14275
simpleCounter/leds.json
Normal file
14275
simpleCounter/leds.json
Normal file
File diff suppressed because it is too large
Load diff
19
simpleCounter/leds.pcf
Normal file
19
simpleCounter/leds.pcf
Normal file
|
@ -0,0 +1,19 @@
|
|||
# For iceFUN board
|
||||
|
||||
set_io --warn-no-port ledRow[0] C10
|
||||
set_io --warn-no-port ledRow[1] A10
|
||||
set_io --warn-no-port ledRow[2] D7
|
||||
set_io --warn-no-port ledRow[3] D6
|
||||
set_io --warn-no-port ledRow[4] A7
|
||||
set_io --warn-no-port ledRow[5] C7
|
||||
set_io --warn-no-port ledRow[6] A4
|
||||
set_io --warn-no-port ledRow[7] C4
|
||||
set_io --warn-no-port ledCol[0] A12
|
||||
set_io --warn-no-port ledCol[1] D10
|
||||
set_io --warn-no-port ledCol[2] A6
|
||||
set_io --warn-no-port ledCol[3] C5
|
||||
set_io --warn-no-port buttons[0] A5
|
||||
set_io --warn-no-port buttons[1] A11
|
||||
set_io --warn-no-port buttons[2] C6
|
||||
set_io --warn-no-port buttons[3] C11
|
||||
set_io --warn-no-port clock P7
|
424
simpleCounter/leds.v
Normal file
424
simpleCounter/leds.v
Normal file
|
@ -0,0 +1,424 @@
|
|||
/* Generated by Yosys 0.33 (git sha1 2584903a060) */
|
||||
|
||||
module ledmux(clock, reset_n, leds0, leds1, leds2, leds3, ledrow, ledcol);
|
||||
wire _00_;
|
||||
wire [12:0] _01_;
|
||||
wire [12:0] _02_;
|
||||
wire _03_;
|
||||
wire _04_;
|
||||
wire _05_;
|
||||
wire _06_;
|
||||
wire _07_;
|
||||
wire [3:0] _08_;
|
||||
wire [3:0] _09_;
|
||||
wire _10_;
|
||||
wire _11_;
|
||||
wire _12_;
|
||||
wire _13_;
|
||||
wire _14_;
|
||||
wire [7:0] _15_;
|
||||
wire [7:0] _16_;
|
||||
reg [12:0] _17_;
|
||||
input clock;
|
||||
wire clock;
|
||||
wire [12:0] counter;
|
||||
output [3:0] ledcol;
|
||||
wire [3:0] ledcol;
|
||||
output [7:0] ledrow;
|
||||
wire [7:0] ledrow;
|
||||
input [7:0] leds0;
|
||||
wire [7:0] leds0;
|
||||
input [7:0] leds1;
|
||||
wire [7:0] leds1;
|
||||
input [7:0] leds2;
|
||||
wire [7:0] leds2;
|
||||
input [7:0] leds3;
|
||||
wire [7:0] leds3;
|
||||
input reset_n;
|
||||
wire reset_n;
|
||||
assign _00_ = ~ reset_n;
|
||||
assign _01_ = counter + 13'h0001;
|
||||
assign _02_ = _00_ ? 13'h0000 : _01_;
|
||||
assign _03_ = ~ reset_n;
|
||||
assign _04_ = counter[12:11] == 2'h0;
|
||||
assign _05_ = counter[12:11] == 2'h1;
|
||||
assign _06_ = counter[12:11] == 2'h2;
|
||||
assign _07_ = counter[12:11] == 2'h3;
|
||||
function [3:0] \189 ;
|
||||
input [3:0] a;
|
||||
input [15:0] b;
|
||||
input [3:0] s;
|
||||
(* parallel_case *)
|
||||
casez (s)
|
||||
4'b???1:
|
||||
\189 = b[3:0];
|
||||
4'b??1?:
|
||||
\189 = b[7:4];
|
||||
4'b?1??:
|
||||
\189 = b[11:8];
|
||||
4'b1???:
|
||||
\189 = b[15:12];
|
||||
default:
|
||||
\189 = a;
|
||||
endcase
|
||||
endfunction
|
||||
assign _08_ = \189 (4'hf, 16'h7bde, { _07_, _06_, _05_, _04_ });
|
||||
assign _09_ = _03_ ? 4'h0 : _08_;
|
||||
assign _10_ = ~ reset_n;
|
||||
assign _11_ = counter[12:11] == 2'h0;
|
||||
assign _12_ = counter[12:11] == 2'h1;
|
||||
assign _13_ = counter[12:11] == 2'h2;
|
||||
assign _14_ = counter[12:11] == 2'h3;
|
||||
function [7:0] \205 ;
|
||||
input [7:0] a;
|
||||
input [31:0] b;
|
||||
input [3:0] s;
|
||||
(* parallel_case *)
|
||||
casez (s)
|
||||
4'b???1:
|
||||
\205 = b[7:0];
|
||||
4'b??1?:
|
||||
\205 = b[15:8];
|
||||
4'b?1??:
|
||||
\205 = b[23:16];
|
||||
4'b1???:
|
||||
\205 = b[31:24];
|
||||
default:
|
||||
\205 = a;
|
||||
endcase
|
||||
endfunction
|
||||
assign _15_ = \205 (leds0, { leds3, leds2, leds1, leds0 }, { _14_, _13_, _12_, _11_ });
|
||||
assign _16_ = _10_ ? leds0 : _15_;
|
||||
always @(posedge clock)
|
||||
_17_ <= _02_;
|
||||
assign counter = _17_;
|
||||
assign ledrow = _16_;
|
||||
assign ledcol = _09_;
|
||||
endmodule
|
||||
|
||||
module leds(clock, buttons, ledRow, ledCol);
|
||||
wire _00_;
|
||||
reg [25:0] _01_;
|
||||
reg _02_;
|
||||
reg _03_;
|
||||
reg _04_;
|
||||
wire [25:0] _05_;
|
||||
wire [25:0] _06_;
|
||||
wire [7:0] _07_;
|
||||
wire [7:0] _08_;
|
||||
wire [7:0] _09_;
|
||||
wire [7:0] _10_;
|
||||
wire [7:0] _11_;
|
||||
wire [3:0] _12_;
|
||||
input [3:0] buttons;
|
||||
wire [3:0] buttons;
|
||||
input clock;
|
||||
wire clock;
|
||||
wire [7:0] \conv_inst:19 ;
|
||||
wire [7:0] \conv_inst:20 ;
|
||||
wire [7:0] \conv_inst:21 ;
|
||||
wire [7:0] \conv_inst:22 ;
|
||||
wire [25:0] counter;
|
||||
wire key0_d1;
|
||||
wire key0_d2;
|
||||
wire key0_d3;
|
||||
output [3:0] ledCol;
|
||||
wire [3:0] ledCol;
|
||||
output [7:0] ledRow;
|
||||
wire [7:0] ledRow;
|
||||
wire [3:0] ledrow_sig;
|
||||
wire [7:0] leds0_sig;
|
||||
wire [7:0] leds1_sig;
|
||||
wire [7:0] leds2_sig;
|
||||
wire [7:0] leds3_sig;
|
||||
wire [7:0] \mux_inst:31 ;
|
||||
wire [3:0] \mux_inst:32 ;
|
||||
wire reset_n;
|
||||
assign _00_ = ~ reset_n;
|
||||
assign _05_ = counter + 26'h0000001;
|
||||
assign _06_ = _00_ ? 26'h0000000 : _05_;
|
||||
always @(posedge clock)
|
||||
_01_ <= _06_;
|
||||
always @(posedge clock)
|
||||
_02_ <= buttons[0];
|
||||
always @(posedge clock)
|
||||
_03_ <= key0_d1;
|
||||
always @(posedge clock)
|
||||
_04_ <= key0_d2;
|
||||
matrixtosevenseg conv_inst (
|
||||
.clock(clock),
|
||||
.led0_out(_07_),
|
||||
.led1_out(_08_),
|
||||
.led2_out(_09_),
|
||||
.led3_out(_10_),
|
||||
.num_in(ledrow_sig),
|
||||
.reset_n(reset_n)
|
||||
);
|
||||
ledmux mux_inst (
|
||||
.clock(clock),
|
||||
.ledcol(_12_),
|
||||
.ledrow(_11_),
|
||||
.leds0(leds0_sig),
|
||||
.leds1(leds1_sig),
|
||||
.leds2(leds2_sig),
|
||||
.leds3(leds3_sig),
|
||||
.reset_n(reset_n)
|
||||
);
|
||||
assign counter = _01_;
|
||||
assign key0_d1 = _02_;
|
||||
assign key0_d2 = _03_;
|
||||
assign key0_d3 = _04_;
|
||||
assign reset_n = key0_d3;
|
||||
assign ledrow_sig = counter[25:22];
|
||||
assign leds0_sig = \conv_inst:19 ;
|
||||
assign leds1_sig = \conv_inst:20 ;
|
||||
assign leds2_sig = \conv_inst:21 ;
|
||||
assign leds3_sig = \conv_inst:22 ;
|
||||
assign \conv_inst:19 = _07_;
|
||||
assign \conv_inst:20 = _08_;
|
||||
assign \conv_inst:21 = _09_;
|
||||
assign \conv_inst:22 = _10_;
|
||||
assign \mux_inst:31 = _11_;
|
||||
assign \mux_inst:32 = _12_;
|
||||
assign ledRow = \mux_inst:31 ;
|
||||
assign ledCol = \mux_inst:32 ;
|
||||
endmodule
|
||||
|
||||
module matrixtosevenseg(clock, reset_n, num_in, led0_out, led1_out, led2_out, led3_out);
|
||||
wire _00_;
|
||||
wire _01_;
|
||||
wire _02_;
|
||||
wire _03_;
|
||||
wire _04_;
|
||||
wire _05_;
|
||||
wire _06_;
|
||||
wire _07_;
|
||||
wire _08_;
|
||||
wire _09_;
|
||||
wire _10_;
|
||||
wire _11_;
|
||||
wire _12_;
|
||||
wire _13_;
|
||||
wire _14_;
|
||||
wire _15_;
|
||||
wire _16_;
|
||||
wire [7:0] _17_;
|
||||
wire [7:0] _18_;
|
||||
wire [7:0] _19_;
|
||||
wire [7:0] _20_;
|
||||
wire [7:0] _21_;
|
||||
wire [7:0] _22_;
|
||||
wire [7:0] _23_;
|
||||
wire [7:0] _24_;
|
||||
input clock;
|
||||
wire clock;
|
||||
output [7:0] led0_out;
|
||||
wire [7:0] led0_out;
|
||||
output [7:0] led1_out;
|
||||
wire [7:0] led1_out;
|
||||
output [7:0] led2_out;
|
||||
wire [7:0] led2_out;
|
||||
output [7:0] led3_out;
|
||||
wire [7:0] led3_out;
|
||||
input [3:0] num_in;
|
||||
wire [3:0] num_in;
|
||||
input reset_n;
|
||||
wire reset_n;
|
||||
function [7:0] \115 ;
|
||||
input [7:0] a;
|
||||
input [127:0] b;
|
||||
input [15:0] s;
|
||||
(* parallel_case *)
|
||||
casez (s)
|
||||
16'b???????????????1:
|
||||
\115 = b[7:0];
|
||||
16'b??????????????1?:
|
||||
\115 = b[15:8];
|
||||
16'b?????????????1??:
|
||||
\115 = b[23:16];
|
||||
16'b????????????1???:
|
||||
\115 = b[31:24];
|
||||
16'b???????????1????:
|
||||
\115 = b[39:32];
|
||||
16'b??????????1?????:
|
||||
\115 = b[47:40];
|
||||
16'b?????????1??????:
|
||||
\115 = b[55:48];
|
||||
16'b????????1???????:
|
||||
\115 = b[63:56];
|
||||
16'b???????1????????:
|
||||
\115 = b[71:64];
|
||||
16'b??????1?????????:
|
||||
\115 = b[79:72];
|
||||
16'b?????1??????????:
|
||||
\115 = b[87:80];
|
||||
16'b????1???????????:
|
||||
\115 = b[95:88];
|
||||
16'b???1????????????:
|
||||
\115 = b[103:96];
|
||||
16'b??1?????????????:
|
||||
\115 = b[111:104];
|
||||
16'b?1??????????????:
|
||||
\115 = b[119:112];
|
||||
16'b1???????????????:
|
||||
\115 = b[127:120];
|
||||
default:
|
||||
\115 = a;
|
||||
endcase
|
||||
endfunction
|
||||
assign _18_ = \115 (8'hff, 128'hf6767e7e77ee6e6efe6e6eef6e6eff7e, { _16_, _15_, _14_, _13_, _12_, _11_, _10_, _09_, _08_, _07_, _06_, _05_, _04_, _03_, _02_, _01_ });
|
||||
function [7:0] \133 ;
|
||||
input [7:0] a;
|
||||
input [127:0] b;
|
||||
input [15:0] s;
|
||||
(* parallel_case *)
|
||||
casez (s)
|
||||
16'b???????????????1:
|
||||
\133 = b[7:0];
|
||||
16'b??????????????1?:
|
||||
\133 = b[15:8];
|
||||
16'b?????????????1??:
|
||||
\133 = b[23:16];
|
||||
16'b????????????1???:
|
||||
\133 = b[31:24];
|
||||
16'b???????????1????:
|
||||
\133 = b[39:32];
|
||||
16'b??????????1?????:
|
||||
\133 = b[47:40];
|
||||
16'b?????????1??????:
|
||||
\133 = b[55:48];
|
||||
16'b????????1???????:
|
||||
\133 = b[63:56];
|
||||
16'b???????1????????:
|
||||
\133 = b[71:64];
|
||||
16'b??????1?????????:
|
||||
\133 = b[79:72];
|
||||
16'b?????1??????????:
|
||||
\133 = b[87:80];
|
||||
16'b????1???????????:
|
||||
\133 = b[95:88];
|
||||
16'b???1????????????:
|
||||
\133 = b[103:96];
|
||||
16'b??1?????????????:
|
||||
\133 = b[111:104];
|
||||
16'b?1??????????????:
|
||||
\133 = b[119:112];
|
||||
16'b1???????????????:
|
||||
\133 = b[127:120];
|
||||
default:
|
||||
\133 = a;
|
||||
endcase
|
||||
endfunction
|
||||
assign _19_ = \133 (8'hff, 128'hf6767e7e77ee6e6efe6e6e006e6eff7e, { _16_, _15_, _14_, _13_, _12_, _11_, _10_, _09_, _08_, _07_, _06_, _05_, _04_, _03_, _02_, _01_ });
|
||||
function [7:0] \151 ;
|
||||
input [7:0] a;
|
||||
input [127:0] b;
|
||||
input [15:0] s;
|
||||
(* parallel_case *)
|
||||
casez (s)
|
||||
16'b???????????????1:
|
||||
\151 = b[7:0];
|
||||
16'b??????????????1?:
|
||||
\151 = b[15:8];
|
||||
16'b?????????????1??:
|
||||
\151 = b[23:16];
|
||||
16'b????????????1???:
|
||||
\151 = b[31:24];
|
||||
16'b???????????1????:
|
||||
\151 = b[39:32];
|
||||
16'b??????????1?????:
|
||||
\151 = b[47:40];
|
||||
16'b?????????1??????:
|
||||
\151 = b[55:48];
|
||||
16'b????????1???????:
|
||||
\151 = b[63:56];
|
||||
16'b???????1????????:
|
||||
\151 = b[71:64];
|
||||
16'b??????1?????????:
|
||||
\151 = b[79:72];
|
||||
16'b?????1??????????:
|
||||
\151 = b[87:80];
|
||||
16'b????1???????????:
|
||||
\151 = b[95:88];
|
||||
16'b???1????????????:
|
||||
\151 = b[103:96];
|
||||
16'b??1?????????????:
|
||||
\151 = b[111:104];
|
||||
16'b?1??????????????:
|
||||
\151 = b[119:112];
|
||||
16'b1???????????????:
|
||||
\151 = b[127:120];
|
||||
default:
|
||||
\151 = a;
|
||||
endcase
|
||||
endfunction
|
||||
assign _20_ = \151 (8'hff, 128'hfe7e817e8f019191009f0eef91710000, { _16_, _15_, _14_, _13_, _12_, _11_, _10_, _09_, _08_, _07_, _06_, _05_, _04_, _03_, _02_, _01_ });
|
||||
assign _21_ = _00_ ? 8'hff : _17_;
|
||||
assign _22_ = _00_ ? 8'hff : _18_;
|
||||
assign _23_ = _00_ ? 8'hff : _19_;
|
||||
assign _24_ = _00_ ? 8'hff : _20_;
|
||||
assign _00_ = ~ reset_n;
|
||||
assign _01_ = num_in == 4'h0;
|
||||
assign _02_ = num_in == 4'h1;
|
||||
assign _03_ = num_in == 4'h2;
|
||||
assign _04_ = num_in == 4'h3;
|
||||
assign _05_ = num_in == 4'h4;
|
||||
assign _06_ = num_in == 4'h5;
|
||||
assign _07_ = num_in == 4'h6;
|
||||
assign _08_ = num_in == 4'h7;
|
||||
assign _09_ = num_in == 4'h8;
|
||||
assign _10_ = num_in == 4'h9;
|
||||
assign _11_ = num_in == 4'ha;
|
||||
assign _12_ = num_in == 4'hb;
|
||||
assign _13_ = num_in == 4'hc;
|
||||
assign _14_ = num_in == 4'hd;
|
||||
assign _15_ = num_in == 4'he;
|
||||
assign _16_ = num_in == 4'hf;
|
||||
function [7:0] \97 ;
|
||||
input [7:0] a;
|
||||
input [127:0] b;
|
||||
input [15:0] s;
|
||||
(* parallel_case *)
|
||||
casez (s)
|
||||
16'b???????????????1:
|
||||
\97 = b[7:0];
|
||||
16'b??????????????1?:
|
||||
\97 = b[15:8];
|
||||
16'b?????????????1??:
|
||||
\97 = b[23:16];
|
||||
16'b????????????1???:
|
||||
\97 = b[31:24];
|
||||
16'b???????????1????:
|
||||
\97 = b[39:32];
|
||||
16'b??????????1?????:
|
||||
\97 = b[47:40];
|
||||
16'b?????????1??????:
|
||||
\97 = b[55:48];
|
||||
16'b????????1???????:
|
||||
\97 = b[63:56];
|
||||
16'b???????1????????:
|
||||
\97 = b[71:64];
|
||||
16'b??????1?????????:
|
||||
\97 = b[79:72];
|
||||
16'b?????1??????????:
|
||||
\97 = b[87:80];
|
||||
16'b????1???????????:
|
||||
\97 = b[95:88];
|
||||
16'b???1????????????:
|
||||
\97 = b[103:96];
|
||||
16'b??1?????????????:
|
||||
\97 = b[111:104];
|
||||
16'b?1??????????????:
|
||||
\97 = b[119:112];
|
||||
16'b1???????????????:
|
||||
\97 = b[127:120];
|
||||
default:
|
||||
\97 = a;
|
||||
endcase
|
||||
endfunction
|
||||
assign _17_ = \97 (8'hff, 128'h000000000001f191fe8171e0ff1dff00, { _16_, _15_, _14_, _13_, _12_, _11_, _10_, _09_, _08_, _07_, _06_, _05_, _04_, _03_, _02_, _01_ });
|
||||
assign led0_out = _21_;
|
||||
assign led1_out = _22_;
|
||||
assign led2_out = _23_;
|
||||
assign led3_out = _24_;
|
||||
endmodule
|
99
simpleCounter/leds.vhd
Normal file
99
simpleCounter/leds.vhd
Normal file
|
@ -0,0 +1,99 @@
|
|||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.std_logic_unsigned.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity leds is
|
||||
port(
|
||||
clock : in std_logic;
|
||||
buttons : in std_logic_vector(3 downto 0);
|
||||
ledRow : out std_logic_vector(7 downto 0);
|
||||
ledCol : out std_logic_vector(3 downto 0)
|
||||
);
|
||||
end entity leds;
|
||||
|
||||
architecture arch of leds is
|
||||
|
||||
component ledmux is
|
||||
port(
|
||||
clock : in std_logic;
|
||||
reset_n : in std_logic;
|
||||
leds0 : in std_logic_vector(7 downto 0);
|
||||
leds1 : in std_logic_vector(7 downto 0);
|
||||
leds2 : in std_logic_vector(7 downto 0);
|
||||
leds3 : in std_logic_vector(7 downto 0);
|
||||
ledRow : out std_logic_vector(7 downto 0);
|
||||
ledCol : out std_logic_vector(3 downto 0)
|
||||
);
|
||||
end component;
|
||||
|
||||
component matrixToSevenSeg is
|
||||
port(
|
||||
clock : in std_logic;
|
||||
reset_n : in std_logic;
|
||||
num_in : in std_logic_vector(3 downto 0);
|
||||
led0_out : out std_logic_vector(7 downto 0);
|
||||
led1_out : out std_logic_vector(7 downto 0);
|
||||
led2_out : out std_logic_vector(7 downto 0);
|
||||
led3_out : out std_logic_vector(7 downto 0)
|
||||
);
|
||||
end component;
|
||||
|
||||
signal counter : std_logic_vector(25 downto 0);
|
||||
signal key0_d1 : std_logic;
|
||||
signal key0_d2 : std_logic;
|
||||
signal key0_d3 : std_logic;
|
||||
signal reset_n : std_logic;
|
||||
signal ledRow_sig : std_logic_vector(3 downto 0);
|
||||
signal leds0_sig : std_logic_vector(7 downto 0);
|
||||
signal leds1_sig : std_logic_vector(7 downto 0);
|
||||
signal leds2_sig : std_logic_vector(7 downto 0);
|
||||
signal leds3_sig : std_logic_vector(7 downto 0);
|
||||
begin
|
||||
|
||||
ledRow_sig <= counter(25 downto 22);
|
||||
|
||||
syncReset : process(clock) begin
|
||||
if (rising_edge(clock)) then
|
||||
key0_d1 <= buttons(0);
|
||||
key0_d2 <= key0_d1;
|
||||
key0_d3 <= key0_d2;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
reset_n <= key0_d3;
|
||||
|
||||
syncCounter : process (clock) begin
|
||||
if (rising_edge(clock)) then
|
||||
if (reset_n = '0') then
|
||||
counter <= "00" & x"000000";
|
||||
else
|
||||
counter <= counter + ("00" & x"000001");
|
||||
end if;
|
||||
end if;
|
||||
end process syncCounter;
|
||||
|
||||
conv_inst : component matrixToSevenSeg
|
||||
port map(
|
||||
clock => clock,
|
||||
reset_n => reset_n,
|
||||
num_in => ledRow_sig,
|
||||
led0_out => leds0_sig,
|
||||
led1_out => leds1_sig,
|
||||
led2_out => leds2_sig,
|
||||
led3_out => leds3_sig
|
||||
);
|
||||
|
||||
mux_inst : component ledmux
|
||||
port map(
|
||||
clock => clock,
|
||||
reset_n => reset_n,
|
||||
leds0 => leds0_sig,
|
||||
leds1 => leds1_sig,
|
||||
leds2 => leds2_sig,
|
||||
leds3 => leds3_sig,
|
||||
ledRow => ledRow,
|
||||
ledCol => ledCol
|
||||
);
|
||||
|
||||
end arch;
|
119
simpleCounter/matrixToSevenSeg.vhd
Normal file
119
simpleCounter/matrixToSevenSeg.vhd
Normal file
|
@ -0,0 +1,119 @@
|
|||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.std_logic_unsigned.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity matrixToSevenSeg is
|
||||
port(
|
||||
clock : in std_logic;
|
||||
reset_n : in std_logic;
|
||||
num_in : in std_logic_vector(3 downto 0);
|
||||
led0_out : out std_logic_vector(7 downto 0);
|
||||
led1_out : out std_logic_vector(7 downto 0);
|
||||
led2_out : out std_logic_vector(7 downto 0);
|
||||
led3_out : out std_logic_vector(7 downto 0)
|
||||
);
|
||||
end entity matrixToSevenSeg;
|
||||
|
||||
architecture arch of matrixToSevenSeg is
|
||||
|
||||
begin
|
||||
|
||||
matrixConvert : process(clock) begin
|
||||
if ('0' = reset_n) then
|
||||
led0_out <= "11111111";
|
||||
led1_out <= "11111111";
|
||||
led2_out <= "11111111";
|
||||
led3_out <= "11111111";
|
||||
else
|
||||
case num_in is
|
||||
when "0000" => --0
|
||||
led0_out <= "00000000";
|
||||
led1_out <= "01111110";
|
||||
led2_out <= "01111110";
|
||||
led3_out <= "00000000";
|
||||
when "0001" => --1
|
||||
led0_out <= "11111111";
|
||||
led1_out <= "11111111";
|
||||
led2_out <= "11111111";
|
||||
led3_out <= "00000000";
|
||||
when "0010" => --2
|
||||
led0_out <= "00011101";
|
||||
led1_out <= "01101110";
|
||||
led2_out <= "01101110";
|
||||
led3_out <= "01110001";
|
||||
when "0011" => --3
|
||||
led0_out <= "11111111";
|
||||
led1_out <= "01101110";
|
||||
led2_out <= "01101110";
|
||||
led3_out <= "10010001";
|
||||
when "0100" => --4
|
||||
led0_out <= "11100000";
|
||||
led1_out <= "11101111";
|
||||
led2_out <= "00000000";
|
||||
led3_out <= "11101111";
|
||||
when "0101" => --5
|
||||
led0_out <= "01110001";
|
||||
led1_out <= "01101110";
|
||||
led2_out <= "01101110";
|
||||
led3_out <= "00001110";
|
||||
when "0110" => --6
|
||||
led0_out <= "10000001";
|
||||
led1_out <= "01101110";
|
||||
led2_out <= "01101110";
|
||||
led3_out <= "10011111";
|
||||
when "0111" => --7
|
||||
led0_out <= "11111110";
|
||||
led1_out <= "11111110";
|
||||
led2_out <= "11111110";
|
||||
led3_out <= "00000000";
|
||||
when "1000" => --8
|
||||
led0_out <= "10010001";
|
||||
led1_out <= "01101110";
|
||||
led2_out <= "01101110";
|
||||
led3_out <= "10010001";
|
||||
when "1001" => --9
|
||||
led0_out <= "11110001";
|
||||
led1_out <= "01101110";
|
||||
led2_out <= "01101110";
|
||||
led3_out <= "10010001";
|
||||
when "1010" => --A
|
||||
led0_out <= "00000001";
|
||||
led1_out <= "11101110";
|
||||
led2_out <= "11101110";
|
||||
led3_out <= "00000001";
|
||||
when "1011" => --B
|
||||
led0_out <= "00000000";
|
||||
led1_out <= "01110111";
|
||||
led2_out <= "01110111";
|
||||
led3_out <= "10001111";
|
||||
when "1100" => --C
|
||||
led0_out <= "00000000";
|
||||
led1_out <= "01111110";
|
||||
led2_out <= "01111110";
|
||||
led3_out <= "01111110";
|
||||
when "1101" => --D
|
||||
led0_out <= "00000000";
|
||||
led1_out <= "01111110";
|
||||
led2_out <= "01111110";
|
||||
led3_out <= "10000001";
|
||||
when "1110" => --E
|
||||
led0_out <= "00000000";
|
||||
led1_out <= "01110110";
|
||||
led2_out <= "01110110";
|
||||
led3_out <= "01111110";
|
||||
when "1111" => --F
|
||||
led0_out <= "00000000";
|
||||
led1_out <= "11110110";
|
||||
led2_out <= "11110110";
|
||||
led3_out <= "11111110";
|
||||
when others => --XXXX
|
||||
led0_out <= "11111111";
|
||||
led1_out <= "11111111";
|
||||
led2_out <= "11111111";
|
||||
led3_out <= "11111111";
|
||||
end case;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
end arch;
|
Loading…
Add table
Add a link
Reference in a new issue