Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Help 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.

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Simulate in what? Modelsim? If so, select the trace, right-click, select format, and then decimal.

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I am using ISE Project Navigator, it has it's own sim called ISim.

    --- Quote Start ---

    Simulate in what? Modelsim? If so, select the trace, right-click, select format, and then decimal.

    Cheers,

    Dave

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Select 'c' in the wave window, right click it and you will have option to change the display format like decimal, unsigned, Hexadecimal. you can choose there.