Help me write a VHDL code for a down counter

Status
Not open for further replies.

balakrishna

Newbie level 4
Joined
May 3, 2007
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
hi,

I want to write vhdl code for a down counter. After the count decrements to zero, the counter have to generate a pulse to indicate COUNT = 0. This pulse duration should be les than one clock pulse duration.

Please anybody help me to write code.

I already writtened the code for this. But the problem is, the output pulse is high continuously. I am using this pulse as enable pulse in the code. Pulse is in logic '1' state continuously so it causes a problem.

Thanks & regds,

Balakrishna
 

vhdl help

Hi Balakrishna,

Plz put a if condition like,

if count = 0 then

pulse <= '1';

else

pulse <= '0';

end if;

This condition should be under the clock, which you are going to use. With this condition your pulse would be equal to one clock duration for high.

Please try this and let me know.

Regards,
Sachin
 

Re: vhdl help

Check this out!
Hope this helps!

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity dcounter is
  
  port (
    rst   : in  std_logic;
    clk   : in  std_logic;
    ld    : in  std_logic;
    din   : in  std_logic_vector(7 downto 0);
    pulse : out std_logic);

end dcounter;

architecture behave of dcounter is
signal count : std_logic_vector(7 downto 0);
signal count_nx : std_logic_vector(7 downto 0);
begin  -- behave
with (count_nx /= "00000000" and count = "00000000") select
  pulse <= '1' when true,
           '0' when others;

  process (clk, rst)
  begin  -- process
    if rst = '1' then                   -- asynchronous reset (active high)
      count <= (others => '0');
    elsif clk'event and clk = '1' then  -- rising clock edge
      count <= count_nx;
    end if;
  end process;

  process (count, ld)
  begin  -- process
    if ld = '1' then
      count_nx <= din;
    else
      count_nx <= count - 1;
    end if;
  end process;
end behave;
 

Re: vhdl help

Creating a pulse less that one clock cycle, is notmally never needed. Also it is not a good design appriach for a fully sunchonoes design.
Normally you can always design, that a full clock pulse can be used.


Making smaller pulses, you must and the outptu of a flipflop with the clock signal, but that can result in glitches.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…