someone can help me with this vhdl code for johnson counter. here is my
implementation, I'm note sure about that. The correct image is the
second one.
I have written this code in a first vhdl file, This is the Flip flop
declaration, I will use it as a component later :
1 | entity register_Johnson_entity is
|
2 | port (D : in std_logic_vector (2 downto 0); clock : in std_logic; reset: in std_logic; q: out std_logic_vector(2 downto 0));
|
3 | end register_Johnson;
|
4 |
|
5 | architecture reg_johnson of register_Johnson_entity is
|
6 |
|
7 | flip_flop_async : process( clock, reset)
|
8 | begin
|
9 | if reset = '1' then
|
10 | q <= (others => "000")
|
11 | else
|
12 | q<= D;
|
13 | end if;
|
14 | end process;
|
15 |
|
16 | end architecture;
|
this is the other file that containt the main code, and where I use the
component flip flop async:
1 | use ieee.std_logic_1164.all;
|
2 |
|
3 | entity counter_johnson is
|
4 | port (clock: in std_logic; tc: std_logic_vector(2 downto 0);
|
5 | end entity;
|
6 |
|
7 | architecture john of counter_johnson is
|
8 |
|
9 | signal feedback : std_logic_vector(2 downto 0);
|
10 | signal q : std_logic_vector (2 downto 0);
|
11 |
|
12 |
|
13 | component register_Johnson_entity is
|
14 |
|
15 | port (D : in std_logic_vector (2 downto 0); clock : in std_logic; reset: in std_logic; q: out std_logic_vector(2 downto 0));
|
16 | end register_Johnson;
|
17 | end component;
|
18 |
|
19 | -- registers update
|
20 | q(1)<=q(0);
|
21 | q(2)<=q(1);
|
22 | q(2)<= not q(0);
|
23 |
|
24 |
|
25 | -- the counter is cleared when tc =1
|
26 | reset_jonshon : process(q(2),q(1))
|
27 | tc<= q(2) and not q(1);
|
28 | if tc == '1' then
|
29 | -- reset operation
|
30 | q(1)=(2)=q(0)= '0';
|
31 | else tc == '0';
|
32 | end process;
|
33 |
|
34 | -- port map operation
|
35 |
|
36 | port map (not feedback => D ;q(0) => D; q(1) => d );
|