Altera_Forum
Honored Contributor
12 years agoHelp with a ssimple 0 to 3 counter using integers
Hi, I am trying to design a counter from 0 to 3 using integers. The code that I used is below
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Counter is
Port ( C : out integer range 0 to 3;
clk : in STD_LOGIC;
Reset : in STD_LOGIC;
end Counter;
architecture Behavioral of Counter is
signal count : integer range 0 to 3;
begin
process(Reset, clk)
begin
if Reset = '1' then
count <=0;
elsif Rising_edge(clk) then
if count < 3 then
count <= count +1;
else
count <= 0;
end if;
end if;
end process;
c <= count;
end Behavioral;
I want the output 'c' to display 0,1,2,3 but when I simulate it the 'c' gives 0,1,10,11. I am declaring 'c' right or do I need to use another type? Any advice is welcome, thanks in advance.