dark_plan
Newbie level 2
- Joined
- Mar 26, 2010
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Philippines
- Activity points
- 1,311
Hello!
I need an algorithm for the following scenario:
Let's say I have an input called "start" that goes high for a very short period of time then goes low again. Say I have an output called "b" that goes high for one second as soon as "start" is detected to be high then goes low again.
Pretty easy to explain the scenario but I really can't think of how to code it in vhdl. Still, I tried my luck and came up with the following code:
-----------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity delay is
port(b: out std_logic;
clock, start: in std_logic);
end delay;
architecture archi of delay is
constant counter: natural := 50e6;
signal enableCounter: natural range 0 to counter := 50e6; --- I am using spartan 3e which has a clock speed of 50MHz
signal tick: std_logic := '0';
begin
process (clock, start)
begin
if start = '1' then
if rising_edge(clock) then
tick <= '1';
case tick is
when '1' =>
b <= '1';
if enableCounter = 0 then
tick <= '0';
enableCounter <= counter;
else
enableCounter <= enableCounter - 1;
end if;
when '0' =>
b <= '0';
when others =>
end case;
end if;
end if;
end process;
end archi;
-----------------------------
However, I know just by looking at the code that it's wrong as the line 'if start = '1' then' only gets evaluated for a very short time. Anyone who could perhaps improve the code or help me come up with a better algorithm?
Thanks in advance!
I need an algorithm for the following scenario:
Let's say I have an input called "start" that goes high for a very short period of time then goes low again. Say I have an output called "b" that goes high for one second as soon as "start" is detected to be high then goes low again.
Pretty easy to explain the scenario but I really can't think of how to code it in vhdl. Still, I tried my luck and came up with the following code:
-----------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity delay is
port(b: out std_logic;
clock, start: in std_logic);
end delay;
architecture archi of delay is
constant counter: natural := 50e6;
signal enableCounter: natural range 0 to counter := 50e6; --- I am using spartan 3e which has a clock speed of 50MHz
signal tick: std_logic := '0';
begin
process (clock, start)
begin
if start = '1' then
if rising_edge(clock) then
tick <= '1';
case tick is
when '1' =>
b <= '1';
if enableCounter = 0 then
tick <= '0';
enableCounter <= counter;
else
enableCounter <= enableCounter - 1;
end if;
when '0' =>
b <= '0';
when others =>
end case;
end if;
end if;
end process;
end archi;
-----------------------------
However, I know just by looking at the code that it's wrong as the line 'if start = '1' then' only gets evaluated for a very short time. Anyone who could perhaps improve the code or help me come up with a better algorithm?
Thanks in advance!