-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbitJKFlipFlop.vhd
40 lines (35 loc) · 1.06 KB
/
nbitJKFlipFlop.vhd
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
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.numeric_std.all;
entity nbitJKFlipFlop is
generic (
n : integer := 1
);
port (
clk : IN std_logic;
j : IN std_logic_vector(n-1 downto 0);
k : IN std_logic_vector(n-1 downto 0);
q : OUT std_logic_vector(n-1 downto 0);
q_bar : OUT std_logic_vector(n-1 downto 0)
) ;
end nbitJKFlipFlop ;
architecture arch of nbitJKFlipFlop is
begin
update_ff : process( clk )
begin
if rising_edge(clk) then
for i in 0 to n-1 loop
if j(i) = '0' and k(i) = '1' then
q(i) <= '0';
q_bar(i) <= '1';
elsif j(i) = '1' and k(i) = '0' then
q(i) <= '1';
q_bar(i) <= '0';
elsif j(i) = '1' and k(i) = '1' then
q(i) <= not q(i);
q_bar(i) <= not q_bar(i);
end if;
end loop;
end if;
end process ; -- update_ff
end architecture ; -- arch