Guest
Hello folks,
I would like to have a counter which counts only from 0000 to 1111 so i
have used a mod function. but somehow during the simulation i exceed
"1111" and getting message as follows:
"RUNTIME: Fatal Error: RUNTIME_0043 addr_counter.vhd (54): Value 17 out
of range (0 to 16)"
I understand tht my counter is exceeding "1111" so on as i hve given a
range for int_count signal but is tht range is incorrect ? or should i
consider as differnt datatype?
Can someof you find the fault in my code ?
Sincerely,
ALI
------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
------------------------------------------------------------------
ENTITY ADDR_COUNTER IS
GENERIC
(
WIDTH : NATURAL := 4
);
PORT
(
CLK : IN STD_LOGIC;
RST : IN STD_LOGIC;
EN_COUNT : IN STD_LOGIC;
UPDOWN : IN STD_LOGIC;
FULL : OUT STD_LOGIC;
EMPTY : OUT STD_LOGIC
);
END ADDR_COUNTER;
------------------------------------------------------------------
ARCHITECTURE ARCH_COUNTER OF ADDR_COUNTER IS
CONSTANT LENGTH : INTEGER := 2 ** WIDTH;
SIGNAL INT_COUNT : INTEGER RANGE 0 TO LENGTH;
------------------------------------------------------------------
BEGIN
FULL <= '1' WHEN INT_COUNT = LENGTH ELSE '0';
EMPTY <= '1' WHEN INT_COUNT = 0 ELSE '1';
COUNT_PRO: PROCESS (CLK, RST)
BEGIN
IF RST = '0' THEN
INT_COUNT <= 0;
FULL <= '0';
EMPTY <= '1';
ELSIF (CLK'EVENT AND CLK = '1') THEN
IF EN_COUNT = '1' THEN
IF UPDOWN='1' THEN
INT_COUNT <= INT_COUNT + 1 MOD LENGTH;
ELSE
INT_COUNT <= INT_COUNT - 1 MOD LENGTH;
END IF;
END IF;
END IF;
END PROCESS COUNT_PRO;
------------------------------------------------------------------
END ARCH_COUNTER;
------------------------------------------------------------------
I would like to have a counter which counts only from 0000 to 1111 so i
have used a mod function. but somehow during the simulation i exceed
"1111" and getting message as follows:
"RUNTIME: Fatal Error: RUNTIME_0043 addr_counter.vhd (54): Value 17 out
of range (0 to 16)"
I understand tht my counter is exceeding "1111" so on as i hve given a
range for int_count signal but is tht range is incorrect ? or should i
consider as differnt datatype?
Can someof you find the fault in my code ?
Sincerely,
ALI
------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
------------------------------------------------------------------
ENTITY ADDR_COUNTER IS
GENERIC
(
WIDTH : NATURAL := 4
);
PORT
(
CLK : IN STD_LOGIC;
RST : IN STD_LOGIC;
EN_COUNT : IN STD_LOGIC;
UPDOWN : IN STD_LOGIC;
FULL : OUT STD_LOGIC;
EMPTY : OUT STD_LOGIC
);
END ADDR_COUNTER;
------------------------------------------------------------------
ARCHITECTURE ARCH_COUNTER OF ADDR_COUNTER IS
CONSTANT LENGTH : INTEGER := 2 ** WIDTH;
SIGNAL INT_COUNT : INTEGER RANGE 0 TO LENGTH;
------------------------------------------------------------------
BEGIN
FULL <= '1' WHEN INT_COUNT = LENGTH ELSE '0';
EMPTY <= '1' WHEN INT_COUNT = 0 ELSE '1';
COUNT_PRO: PROCESS (CLK, RST)
BEGIN
IF RST = '0' THEN
INT_COUNT <= 0;
FULL <= '0';
EMPTY <= '1';
ELSIF (CLK'EVENT AND CLK = '1') THEN
IF EN_COUNT = '1' THEN
IF UPDOWN='1' THEN
INT_COUNT <= INT_COUNT + 1 MOD LENGTH;
ELSE
INT_COUNT <= INT_COUNT - 1 MOD LENGTH;
END IF;
END IF;
END IF;
END PROCESS COUNT_PRO;
------------------------------------------------------------------
END ARCH_COUNTER;
------------------------------------------------------------------