B
bob
Guest
I have a counter (16 bit). I want to use the MSB bit 15 to signal that
the counter is full and STOP further counting. The max count would be
1000 0000 0000 0000 = full flag set
The code below works as when the MSB = hi the full flag goes high,
but for some reason an extra count is allowed.
I get 1000 0000 0000 0001.
Any ideas?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter16bit is
port (
CLK: in STD_LOGIC;
RESET: in STD_LOGIC;
RESET2: in STD_LOGIC;
FULL: inout STD_LOGIC;
COUNT: inout STD_LOGIC_VECTOR(15 downto 0)
);
end counter16bit;
architecture Behavioral of counter16bit is
begin
process (CLK, RESET, RESET2)
begin
if RESET='1' or RESET2='0' then
COUNT <= "0000000000000000";
FULL <= '0';
elsif CLK='1' and CLK'event and full='0' then -- rising
edge of clk!
COUNT <= COUNT + 1;
FULL <= COUNT(15);
end if;
end process;
the counter is full and STOP further counting. The max count would be
1000 0000 0000 0000 = full flag set
The code below works as when the MSB = hi the full flag goes high,
but for some reason an extra count is allowed.
I get 1000 0000 0000 0001.
Any ideas?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter16bit is
port (
CLK: in STD_LOGIC;
RESET: in STD_LOGIC;
RESET2: in STD_LOGIC;
FULL: inout STD_LOGIC;
COUNT: inout STD_LOGIC_VECTOR(15 downto 0)
);
end counter16bit;
architecture Behavioral of counter16bit is
begin
process (CLK, RESET, RESET2)
begin
if RESET='1' or RESET2='0' then
COUNT <= "0000000000000000";
FULL <= '0';
elsif CLK='1' and CLK'event and full='0' then -- rising
edge of clk!
COUNT <= COUNT + 1;
FULL <= COUNT(15);
end if;
end process;