Skip to content

Commit 01cc2c6

Browse files
author
Organick
authored
Add files via upload
1 parent 8db7dd0 commit 01cc2c6

File tree

6 files changed

+488
-0
lines changed

6 files changed

+488
-0
lines changed

Lab7/binary_bcd.vhd

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
use ieee.std_logic_unsigned.all;
4+
entity binary_bcd is
5+
generic(N: positive := 6);
6+
port(
7+
clk, reset: in std_logic;
8+
binary_in: in std_logic_vector(N-1 downto 0);
9+
-- bcd0, bcd1, bcd2, bcd3, bcd4: out std_logic_vector(3 downto 0)
10+
bcd0, bcd1: out std_logic_vector(3 downto 0)
11+
);
12+
end binary_bcd ;
13+
architecture behaviour of binary_bcd is
14+
type states is (start, shift, done);
15+
signal state, state_next: states;
16+
signal binary, binary_next: std_logic_vector(N-1 downto 0);
17+
signal bcds, bcds_reg, bcds_next: std_logic_vector(19 downto 0);
18+
-- output register keep output constant during conversion
19+
signal bcds_out_reg, bcds_out_reg_next: std_logic_vector(19 downto 0);
20+
-- need to keep track of shifts
21+
signal shift_counter, shift_counter_next: natural range 0 to N;
22+
begin
23+
process(clk, reset)
24+
begin
25+
if reset = '1' then
26+
binary <= (others => '0');
27+
bcds <= (others => '0');
28+
state <= start;
29+
bcds_out_reg <= (others => '0');
30+
shift_counter <= 0;
31+
elsif falling_edge(clk) then
32+
binary <= binary_next;
33+
bcds <= bcds_next;
34+
state <= state_next;
35+
bcds_out_reg <= bcds_out_reg_next;
36+
shift_counter <= shift_counter_next;
37+
end if;
38+
end process;
39+
convert:
40+
process(state, binary, binary_in, bcds, bcds_reg, shift_counter)
41+
begin
42+
state_next <= state;
43+
bcds_next <= bcds;
44+
binary_next <= binary;
45+
shift_counter_next <= shift_counter;
46+
case state is
47+
when start =>
48+
state_next <= shift;
49+
binary_next <= binary_in;
50+
bcds_next <= (others => '0');
51+
shift_counter_next <= 0;
52+
when shift =>
53+
if shift_counter = N then
54+
state_next <= done;
55+
else
56+
binary_next <= binary(N-2 downto 0) & 'L';
57+
bcds_next <= bcds_reg(18 downto 0) & binary(N-1);
58+
shift_counter_next <= shift_counter + 1;
59+
end if;
60+
when done =>
61+
state_next <= start;
62+
end case;
63+
end process;
64+
bcds_reg(19 downto 16) <= bcds(19 downto 16) + 3 when bcds(19 downto 16) > 4 else
65+
bcds(19 downto 16);
66+
bcds_reg(15 downto 12) <= bcds(15 downto 12) + 3 when bcds(15 downto 12) > 4 else
67+
bcds(15 downto 12);
68+
bcds_reg(11 downto 8) <= bcds(11 downto 8) + 3 when bcds(11 downto 8) > 4 else
69+
bcds(11 downto 8);
70+
bcds_reg(7 downto 4) <= bcds(7 downto 4) + 3 when bcds(7 downto 4) > 4 else
71+
bcds(7 downto 4);
72+
bcds_reg(3 downto 0) <= bcds(3 downto 0) + 3 when bcds(3 downto 0) > 4 else
73+
bcds(3 downto 0);
74+
bcds_out_reg_next <= bcds when state = done else
75+
bcds_out_reg;
76+
-- bcd4 <= bcds_out_reg(19 downto 16);
77+
-- bcd3 <= bcds_out_reg(15 downto 12);
78+
-- bcd2 <= bcds_out_reg(11 downto 8);
79+
bcd1 <= bcds_out_reg(7 downto 4);
80+
bcd0 <= bcds_out_reg(3 downto 0);
81+
end behaviour;

Lab7/clk_divider.vhd

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- Engineer: Mehmet Cagri Aksoy
2+
3+
library IEEE;
4+
use IEEE.STD_LOGIC_1164.ALL;
5+
6+
entity clk_converter is
7+
Port (
8+
clk_in : in STD_LOGIC;
9+
enable : in STD_LOGIC;
10+
rst : in STD_LOGIC;
11+
clk_out: out STD_LOGIC
12+
);
13+
end clk_converter;
14+
15+
architecture Behavioral of clk_converter is
16+
signal temporal: STD_LOGIC :='1';
17+
signal counter : integer range 0 to 100000000 := 0;
18+
begin
19+
process (enable,rst,clk_in,temporal,counter)
20+
begin
21+
if(rst='1') then
22+
temporal <= '1';
23+
counter <= 0;
24+
elsif (enable = '0') then
25+
temporal <= temporal;
26+
counter <= counter;
27+
elsif rising_edge(clk_in) then
28+
if (counter = 100000000) then
29+
temporal <= NOT(temporal);
30+
31+
counter <= 0;
32+
else
33+
counter <= counter + 1;
34+
end if;
35+
end if;
36+
end process;
37+
clk_out <= temporal;
38+
39+
40+
end Behavioral;

Lab7/converter.vhd

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
library IEEE;
3+
use IEEE.STD_LOGIC_1164.ALL;
4+
5+
entity converter is
6+
Port (
7+
clk_in : in STD_LOGIC;
8+
enable : in STD_LOGIC;
9+
rst : in STD_LOGIC;
10+
clk_out: out STD_LOGIC
11+
);
12+
end converter;
13+
14+
architecture Behavioral of converter is
15+
signal temporal: STD_LOGIC :='1';
16+
signal counter : integer range 0 to 50000000 := 0;
17+
begin
18+
frequency_divider: process (enable,rst,clk_in,temporal,counter) begin
19+
if(rst='1') then
20+
temporal <= '1';
21+
counter <= 0;
22+
elsif (enable = '0') then
23+
temporal <= temporal;
24+
counter <= counter;
25+
elsif rising_edge(clk_in) then
26+
if (counter = 49999999) then
27+
temporal <= NOT(temporal);
28+
29+
counter <= 0;
30+
else
31+
counter <= counter + 1;
32+
end if;
33+
end if;
34+
end process;
35+
clk_out <= temporal;
36+
37+
38+
end Behavioral;
39+
40+

Lab7/seven_four.vhd

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
2+
library IEEE;
3+
use IEEE.STD_LOGIC_1164.ALL;
4+
use IEEE.STD_LOGIC_ARITH.ALL;
5+
use IEEE.STD_LOGIC_UNSIGNED.ALL;
6+
7+
entity seven_four is
8+
Port ( in1 : in STD_LOGIC_VECTOR (3 downto 0);
9+
in2 : in STD_LOGIC_VECTOR (3 downto 0);
10+
in3 : in STD_LOGIC_VECTOR (3 downto 0);
11+
in4 : in STD_LOGIC_VECTOR (3 downto 0);
12+
clk : in STD_LOGIC;
13+
dp : out STD_LOGIC;
14+
sel : out STD_LOGIC_VECTOR (3 downto 0);
15+
segment : out STD_LOGIC_VECTOR (6 downto 0)
16+
);
17+
end seven_four;
18+
19+
architecture Behavioral of seven_four is
20+
21+
signal counter : STD_LOGIC_VECTOR (17 downto 0);
22+
signal sev_in1, sev_in2, sev_in3, sev_in4 : STD_LOGIC_VECTOR (6 downto 0);
23+
24+
begin
25+
26+
dp <= '1';
27+
28+
with in1 select
29+
sev_in1 (6 downto 0)<=
30+
"1000000" when "0000",
31+
"1111001" when "0001",
32+
"0100100" when "0010",
33+
"0110000" when "0011",
34+
"0011001" when "0100",
35+
"0010010" when "0101",
36+
"0000010" when "0110",
37+
"1111000" when "0111",
38+
"0000000" when "1000",
39+
"0010000" when "1001",
40+
"0001000" when "1010",
41+
"0000011" when "1011",
42+
"1000110" when "1100",
43+
"0100001" when "1101",
44+
"0000110" when "1110",
45+
"0001110" when "1111",
46+
"1111111" when others;
47+
48+
with in2 select
49+
sev_in2 (6 downto 0)<=
50+
"1000000" when "0000",
51+
"1111001" when "0001",
52+
"0100100" when "0010",
53+
"0110000" when "0011",
54+
"0011001" when "0100",
55+
"0010010" when "0101",
56+
"0000010" when "0110",
57+
"1111000" when "0111",
58+
"0000000" when "1000",
59+
"0010000" when "1001",
60+
"0001000" when "1010",
61+
"0000011" when "1011",
62+
"1000110" when "1100",
63+
"0100001" when "1101",
64+
"0000110" when "1110",
65+
"0001110" when "1111",
66+
"1111111" when others;
67+
68+
69+
with in3 select
70+
sev_in3 (6 downto 0)<=
71+
"1000000" when "0000",
72+
"1111001" when "0001",
73+
"0100100" when "0010",
74+
"0110000" when "0011",
75+
"0011001" when "0100",
76+
"0010010" when "0101",
77+
"0000010" when "0110",
78+
"1111000" when "0111",
79+
"0000000" when "1000",
80+
"0010000" when "1001",
81+
"0001000" when "1010",
82+
"0000011" when "1011",
83+
"1000110" when "1100",
84+
"0100001" when "1101",
85+
"0000110" when "1110",
86+
"0001110" when "1111",
87+
"1111111" when others;
88+
89+
90+
with in4 select
91+
sev_in4 (6 downto 0)<=
92+
"1000000" when "0000",
93+
"1111001" when "0001",
94+
"0100100" when "0010",
95+
"0110000" when "0011",
96+
"0011001" when "0100",
97+
"0010010" when "0101",
98+
"0000010" when "0110",
99+
"1111000" when "0111",
100+
"0000000" when "1000",
101+
"0010000" when "1001",
102+
"0001000" when "1010",
103+
"0000011" when "1011",
104+
"1000110" when "1100",
105+
"0100001" when "1101",
106+
"0000110" when "1110",
107+
"0001110" when "1111",
108+
"1111111" when others;
109+
110+
111+
112+
113+
process (clk, sev_in1, sev_in2, sev_in3, sev_in4)
114+
variable sec : STD_LOGIC_VECTOR (1 downto 0) := "00" ;
115+
begin
116+
if(clk'event and clk = '1') then
117+
counter <= counter + 1;
118+
sec := (counter(17) & counter(16));
119+
end if;
120+
121+
case (sec) is
122+
when "00" =>
123+
sel <= "1110";
124+
segment <= sev_in1;
125+
126+
when "01" =>
127+
sel <= "1101";
128+
segment <= sev_in2;
129+
130+
when "10" =>
131+
sel <= "1011";
132+
segment <= sev_in3;
133+
134+
when "11" =>
135+
sel <= "0111";
136+
segment <= sev_in4;
137+
138+
when others =>
139+
sel <= "1111";
140+
segment <= "1111111";
141+
142+
end case;
143+
144+
end process;
145+
146+
end Behavioral;
147+

Lab7/top.ucf

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
NET "clk100Mhz" LOC = E3 | IOSTANDARD = LVCMOS33;
3+
NET "enable" LOC=J15 | IOSTANDARD=LVCMOS33;
4+
NET "DATA" LOC=L16 | IOSTANDARD=LVCMOS33;
5+
NET "reset" LOC=M13 | IOSTANDARD=LVCMOS33;
6+
7+
NET "ledo<0>" LOC=H17 | IOSTANDARD=LVCMOS33;
8+
NET "ledo<1>" LOC=K15 | IOSTANDARD=LVCMOS33;
9+
NET "ledo<2>" LOC=J13 | IOSTANDARD=LVCMOS33;
10+
NET "ledo<3>" LOC=N14 | IOSTANDARD=LVCMOS33;
11+
NET "ledo<4>" LOC=R18 | IOSTANDARD=LVCMOS33;
12+
NET "ledo<5>" LOC=V17 | IOSTANDARD=LVCMOS33;
13+
NET "ledo<6>" LOC=U17 | IOSTANDARD=LVCMOS33;
14+
NET "ledo<7>" LOC=U16 | IOSTANDARD=LVCMOS33;
15+
16+
NET "seg_out<0>" LOC=H15 | IOSTANDARD=LVCMOS33;
17+
NET "seg_out<1>" LOC=T10 | IOSTANDARD=LVCMOS33;
18+
NET "seg_out<2>" LOC=R10 | IOSTANDARD=LVCMOS33;
19+
NET "seg_out<3>" LOC=K16 | IOSTANDARD=LVCMOS33;
20+
NET "seg_out<4>" LOC=K13 | IOSTANDARD=LVCMOS33;
21+
NET "seg_out<5>" LOC=P15 | IOSTANDARD=LVCMOS33;
22+
NET "seg_out<6>" LOC=T11 | IOSTANDARD=LVCMOS33;
23+
NET "seg_out<7>" LOC=L18 | IOSTANDARD=LVCMOS33;
24+
25+
NET "seg_sel<0>" LOC=J17 | IOSTANDARD=LVCMOS33;
26+
NET "seg_sel<1>" LOC=J18 | IOSTANDARD=LVCMOS33;
27+
NET "seg_sel<2>" LOC=T9 | IOSTANDARD=LVCMOS33;
28+
NET "seg_sel<3>" LOC=J14 | IOSTANDARD=LVCMOS33;
29+
NET "seg_sel<4>" LOC=P14 | IOSTANDARD=LVCMOS33;
30+
NET "seg_sel<5>" LOC=T14 | IOSTANDARD=LVCMOS33;
31+
NET "seg_sel<6>" LOC=K2 | IOSTANDARD=LVCMOS33;
32+
NET "seg_sel<7>" LOC=U13 | IOSTANDARD=LVCMOS33;
33+
34+

0 commit comments

Comments
 (0)