Skip to content

Commit ef324cf

Browse files
author
Organick
authored
Add files via upload
1 parent 908b024 commit ef324cf

File tree

8 files changed

+979
-0
lines changed

8 files changed

+979
-0
lines changed

Lab7 with Task/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 with Task/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 with Task/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+

0 commit comments

Comments
 (0)