1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
| ----PRESET DFF-------
entity DFFPreset is
Port ( preset : in STD_LOGIC;
clk : in STD_LOGIC;
d : in STD_LOGIC;
q : out STD_LOGIC);
end DFFPreset;
architecture Behavioral of DFFPreset is
begin
process(clk,preset)
begin
if preset ='1' then
q<='1';
elsif clk'event and clk ='1' then
q<=d;
end if;
end process;
end Behavioral;
---------RESET DFF---------
entity DFF is
Port ( reset : in STD_LOGIC;
clk : in STD_LOGIC;
D : in STD_LOGIC;
Q : out STD_LOGIC);
end DFF;
architecture Behavioral of DFF is
begin
process(clk,reset)
begin
if reset='1' then
Q <= '0'; -- clear register
elsif (clk'event and clk='1') then
Q<=D; --positive edge of clock is used
end if;
end process;
end Behavioral;
-------------------4 bit Ring COunter-----------------
entity ringcounter is
Port ( reset : in STD_LOGIC;
clk : in STD_LOGIC;
preset : in STD_LOGIC;
count : out STD_LOGIC_VECTOR (3 downto 0));
end ringcounter;
architecture Behavioral of ringcounter is
signal q0,q1,q2 : STD_LOGIC := '0'; ---initialising the signals
--signal temp :STD_LOGIC := '1'; --not using it as of now.
signal q3 :STD_LOGIC := '1';
component DFF is
Port ( reset : in STD_LOGIC;
clk : in STD_LOGIC;
D : in STD_LOGIC;
Q : out STD_LOGIC);
end component;
component DFFPreset is
Port ( preset : in STD_LOGIC;
clk : in STD_LOGIC;
d : in STD_LOGIC;
q : out STD_LOGIC);
end component;
begin
DFFPreset1 : DFFPreset port map(preset,clk,q3,q0);
DFF2 : DFF port map(reset,clk,q0,q1);
DFF3 : DFF port map(reset,clk,q1,q2);
DFF4 : DFF port map(reset,clk,q2,q3);
count <= q3&q2&q1&q0;
end Behavioral; |