I want to make a counter that on every rising clock edge, adds 1 to my
'counter' out and resets on a rising edge if 'reset = 1'. I had problems
with working directly on the 'counter', so I have the extra signal
'countr' as a temp.
However, when I run that code, it only adds 1 every two rising edges.
Can someone explain why?
1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 |
|
5 | entity Counter is
|
6 | port (
|
7 | clk : in std_logic;
|
8 | reset : in std_logic;
|
9 | count : out std_logic_vector(3 downto 0)
|
10 | );
|
11 | end Counter;
|
12 |
|
13 | architecture rtl of Counter is
|
14 | signal countr : std_logic_vector(3 downto 0);
|
15 |
|
16 | begin
|
17 | process(clk)
|
18 | begin
|
19 | if(rising_edge(clk)) then
|
20 | countr <= std_logic_vector(to_unsigned(to_integer(unsigned(countr)) + 1, 4));
|
21 | if(reset = '1') then
|
22 | countr <= (others => '0');
|
23 | end if;
|
24 | end if;
|
25 | count <= countr;
|
26 | end process;
|
27 | end architecture rtl;
|