4 -- based on code from LXPWR motion control board (c) PiKRON Ltd
5 -- idea by Pavel Pisa PiKRON Ltd <ppisa@pikron.com>
11 use ieee.std_logic_1164.all;
12 use ieee.numeric_std.all;
16 duration_width_g : natural := 4
20 clk_i : in std_logic; --clk to divide
21 en_i : in std_logic; --enable bit?
22 reset_i : in std_logic; --asynch. reset
23 trigger_i : in std_logic; --start to generate pulse
24 duration_i : in std_logic_vector(duration_width_g-1 downto 0);--duration/interval of the pulse
25 q_out_o : out std_logic --generates pulse for given duration
29 architecture behavioral of pulse_gen is
30 signal cnt_val_s : natural range 0 to (2**duration_width_g - 1); --counter value before DFF
31 signal cnt_val_r : natural range 0 to (2**duration_width_g - 1); --counter value after DFF
34 comb: process (reset_i, en_i, duration_i, trigger_i, cnt_val_r)
36 if reset_i = '1' then --reset detection
37 cnt_val_s <= 0; --set defined value
38 q_out_o <= '0'; --reset output
40 if en_i = '0' then --stop-state
41 cnt_val_s <= cnt_val_r; --hold the value
43 if trigger_i = '1' then --trigger pulse generator
44 if to_integer(unsigned(duration_i)) = 0 then
49 cnt_val_s <= to_integer(unsigned(duration_i)); --set initial value
50 elsif cnt_val_r = 0 then --pulse finished
51 cnt_val_s <= cnt_val_r;
52 q_out_o <= '0'; --set output
54 cnt_val_s <= cnt_val_r - 1; --decrement counter
55 q_out_o <= '1'; --reset output
63 wait until clk_i'event and clk_i = '1';
64 cnt_val_r <= cnt_val_s;