ZeleC
Full Member level 5
pulse width generator in vhdl
im trying to do a pulse generator to be implemented in a cpld
the idea is to get an output pulse of 280 us derived from a 25khz clock
the pulse starts on rising edge of trig
i wrote this and it worked as expecteted when i simulated in modelsim
entity timer280us is
Port ( Clk25k : in std_logic;
Trig : in std_logic;
Output : out std_logic);
end timer280us;
architecture Behavioral of timer280us is
signal counter : std_logic_vector(2 downto 0) := "000";
signal Timer_on : std_logic := '0' ;
signal output_temp : std_logic := '1';
begin
countrocess (Clk25k,Trig)
begin
if trig = '1' then
-- if Timer_On = '1' then
counter <= "000";
Timer_on <= '1';
-- end if ;
elsif Clk25k'event and (Clk25k = '1') then
if Timer_On = '1' then
counter <= counter + 1;
Output_temp <= '0';
if counter = "110" then
Timer_On <= '0';
Output_temp <= '1';
end if ;
end if ;
end if ;
end process;
--resetrocess(trig)
--begin
-- if rising_edge(trig) then
-- counter <= "000";
-- Timer_On <= '1';
-- end if;
--end process;
output <= output_temp ;
end Behavioral;
but the problem was that when a trigger pulse occured and as long as the trig = '1' the counter would not start , what i want to do is to start immediately on the rising edge of trig
so how can i rewrite my code so to do this.
im trying to do a pulse generator to be implemented in a cpld
the idea is to get an output pulse of 280 us derived from a 25khz clock
the pulse starts on rising edge of trig
i wrote this and it worked as expecteted when i simulated in modelsim
entity timer280us is
Port ( Clk25k : in std_logic;
Trig : in std_logic;
Output : out std_logic);
end timer280us;
architecture Behavioral of timer280us is
signal counter : std_logic_vector(2 downto 0) := "000";
signal Timer_on : std_logic := '0' ;
signal output_temp : std_logic := '1';
begin
countrocess (Clk25k,Trig)
begin
if trig = '1' then
-- if Timer_On = '1' then
counter <= "000";
Timer_on <= '1';
-- end if ;
elsif Clk25k'event and (Clk25k = '1') then
if Timer_On = '1' then
counter <= counter + 1;
Output_temp <= '0';
if counter = "110" then
Timer_On <= '0';
Output_temp <= '1';
end if ;
end if ;
end if ;
end process;
--resetrocess(trig)
--begin
-- if rising_edge(trig) then
-- counter <= "000";
-- Timer_On <= '1';
-- end if;
--end process;
output <= output_temp ;
end Behavioral;
but the problem was that when a trigger pulse occured and as long as the trig = '1' the counter would not start , what i want to do is to start immediately on the rising edge of trig
so how can i rewrite my code so to do this.