Forum Discussion

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

VHDL Help for Counter

I have to make a counter and I'm a little bit lost, any help is appreciated!

variables:

inputs:

Enable - 2 bit vector

Clock - 1 bit - 1000 Hz.

Hold - 2 bit vector

Reset - 1 bit

outputs:

Out_H - 1 bit

Out_L - 1 bit

Here is the way it needs to work:

It needs to count to ten seconds based on the 1000 Hz input clock. It needs to have a reset, which is already in the file. However, a few things are different: The output[ clk_temp] in the file is our Out_H (active high). You need to make an Out_L which is the active low version of that. Also, you need to change it so that it will only count and so that Out_H can only possibly be 1 when both bits of Enable[Enable[0] and Enable[1]] are equal to 1. And in the part where it flips the output(clk_temp <= not clk_temp) make it so that it will only flip it if the counter has counted all the way to ten seconds AND neither bit in Hold is 1(both are 0).

2 Replies

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

    Heres what I have as of now, still getting a decent amound of errors and I'm having trouble dealing with two enables and I'm not really sure how to treat the hold function. Any help is greatly appreciated.

    ----------------------------------------------------------------------------------

    -- Company:

    -- Engineer:

    --

    -- Create Date: 13:38:57 11/24/2012

    -- Design Name:

    -- Module Name: Counter_2 - Behavioral

    -- Project Name:

    -- Target Devices:

    -- Tool versions:

    -- Description:

    --

    -- Dependencies:

    --

    -- Revision:

    -- Revision 0.01 - File Created

    -- Additional Comments:

    --

    ----------------------------------------------------------------------------------

    library IEEE;

    use IEEE.STD_LOGIC_1164.ALL;

    -- Uncomment the following library declaration if using

    -- arithmetic functions with Signed or Unsigned values

    --use IEEE.NUMERIC_STD.ALL;

    -- Uncomment the following library declaration if instantiating

    -- any Xilinx primitives in this code.

    --library UNISIM;

    --use UNISIM.VComponents.all;

    entity Counter_2 is

    Port ( E1 : in STD_LOGIC;

    E2 : in STD_LOGIC;

    Clk : in STD_LOGIC;

    Hold : in STD_LOGIC_VECTOR (1 downto 0);

    Reset : in STD_LOGIC;

    Out_H : out STD_LOGIC;

    Out_L : out STD_LOGIC);

    end Counter_2;

    architecture Behavioral of Counter_2 is

    signal clk_temp1 : std_logic;

    signal clk_temp2 : std_logic;

    signal count : integer range 0 to 10000 := 0;

    signal enable : std_logic;

    begin

    enable <= E1 and E2;

    process (clk, reset, count, hold)

    begin

    if (reset = '1') then

    clk_temp1 <= '0';

    clk_temp2 <= '0';

    count <= 0;

    elsif (clk ='1' and clk'event) then

    if (hold = '1') then

    count <= count+1;

    else

    if (count = 1) then

    clk_temp1 <= not clk_temp1;

    clk_temp2 <= not clk_temp2;

    count <= 0;

    end if;

    if (rising_edge(enable)) then

    count <= 10000;

    elsif (rising_edge(clk)) then

    if count > 0 then

    Out_H <= '1';

    Out_L <= '0';

    count <= count -1;

    elsif count = 0 then

    Out_H <= '0';

    Out_L <= '1';

    end if;

    end if;

    end if;

    end if;

    end process;

    Out_H <= clk_temp1;

    Out_L <= clk_temp2;

    end Behavioral;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    what errors are you getting?

    Plus I notice this appears to have been generated using a Xilinx template - you realise this is an Altera Forum?