bhan1992
Member level 1
- Joined
- Feb 25, 2012
- Messages
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,511
i have an 8-bit up/down counter code as below, the problem is it wont count down. everytime i have a count down input, it just remain as the previous state.
Code:
waveform screenshot:
up_down = 0 'count down', = 1 'count up'
Code:
Code:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity counter_code is
port (
output :out std_logic_vector (7 downto 0);
up_down :in std_logic;
clk :in std_logic;
reset :in std_logic
);
end counter_code;
architecture start of counter_code is
signal count :std_logic_vector (7 downto 0);
begin
process (clk, reset, up_down)
begin
if (reset = '1' and rising_edge(clk)) then
count <= (others=>'0');
elsif (rising_edge(clk)) then -- rising edge
if (up_down = '1') then
count <= count + 1;
elsif (up_down = '0' and count /= "00000000") then
count <= count - 1;
end if;
end if;
end process;
output <= count;
end start;
waveform screenshot:
up_down = 0 'count down', = 1 'count up'