S
salman sheikh
Guest
Hello All,
I am trying to build a 21 bit delay that operates like this. When an
enable signal becomes high, start counting and after 20 clock pulses,
output a high pulse for one clock cycle. The code below does not count
correctly. Why? Can i not have a count inside the process statement or
does it have to be in the clock process with some enables in the other
process?
Salman
---
entity Delay21 is
port ( ena : in std_logic;
output : out std_logic;
rst : in std_logic ;
clk : in std_logic );
end entity;
architecture arch of Delay21 is
signal count : integer range 0 to 21;
type state is (idle, increment, done);
signal current_state, next_state : state;
begin
process(rst, clk)
begin
if rst = '1' then
current_state <= idle;
elsif clk'event and clk='1' then
current_state <= next_state;
end if;
end process;
process (ena, current_state)
begin
case (current_state) is
when idle =>
output <= '0';
if ena = '1' then
count <= 0;
next_state <= increment;
else
next_state <= idle;
end if;
when increment =>
output <= '0';
count <= count + 1;
if count = 20 then
next_state <= done;
else
next_state <= increment;
end if;
when done =>
output <= '1';
next_state <= idle;
end case;
end process;
end architecture;
I am trying to build a 21 bit delay that operates like this. When an
enable signal becomes high, start counting and after 20 clock pulses,
output a high pulse for one clock cycle. The code below does not count
correctly. Why? Can i not have a count inside the process statement or
does it have to be in the clock process with some enables in the other
process?
Salman
---
entity Delay21 is
port ( ena : in std_logic;
output : out std_logic;
rst : in std_logic ;
clk : in std_logic );
end entity;
architecture arch of Delay21 is
signal count : integer range 0 to 21;
type state is (idle, increment, done);
signal current_state, next_state : state;
begin
process(rst, clk)
begin
if rst = '1' then
current_state <= idle;
elsif clk'event and clk='1' then
current_state <= next_state;
end if;
end process;
process (ena, current_state)
begin
case (current_state) is
when idle =>
output <= '0';
if ena = '1' then
count <= 0;
next_state <= increment;
else
next_state <= idle;
end if;
when increment =>
output <= '0';
count <= count + 1;
if count = 20 then
next_state <= done;
else
next_state <= increment;
end if;
when done =>
output <= '1';
next_state <= idle;
end case;
end process;
end architecture;