J
Jim
Guest
What would be the proper way to clock a register at a fixed multiple
of the system clock? I am trying to create a signal that is active
around the rising edge of the system clock as a clock enable. I am
using a counter to generate a signal at the time interval of
interest. I am then performing an edge detection to get a signal that
is active for a single system clock cycle. To get the enable centered
around the rising edge of the system clock, I am clocking the edge
detector with an inverted system clock. I have read not to use
anything other than the system clock as the clock signal to a flip
flop, so I am uncomfortable using the inverted clock. Is the inverted
clock ok? Does anyone have any recommendations on a better way to do
this.
library ieee;
use ieee.std_logic_1164.all;
entity edge_detector is
port (
clock : in std_logic;
d : in std_logic;
rising_edge_out : out std_logic
);
end;
architecture behavioral of edge_detector is
signal sreg : std_logic_vector(1 downto 0);
begin
edge_detector_proc : process(clock)
begin
if rising_edge(clock) then
if sreg(1 downto 0) = "01" then
rising_edge_out <= '1';
else
rising_edge_out <= '0';
end if;
sreg <= sreg(0) & d;
end if;
end process;
end architecture;
entity clock_divider is
port (
clock : in std_logic;
reset : in std_logic;
clock_enable_clock_divided : out std_logic
);
end clock_divider;
architecture behavioral of clock_divider is
signal inverted_clock : std_logic;
signal clock_divided_i : std_logic;
signal count : unsigned(4 downto 0) := (others => '0');
begin
clock_divided_edge_proc : entity work.edge_detector
port map (
clock => inverted_clock,
d => clock_divided_i,
rising_edge_out => clock_enable_clock_divided
);
inverted_clock <= not clock;
clock_divider_counter_proc: process (reset, clock)
begin
if reset = '1' then
count <= (others => '0');
clock_divided_i <= '0';
elsif rising_edge(clock) then
count <= count + 1;
clock_divided_i <= count(4);
end if;
end process;
end behavioral;
of the system clock? I am trying to create a signal that is active
around the rising edge of the system clock as a clock enable. I am
using a counter to generate a signal at the time interval of
interest. I am then performing an edge detection to get a signal that
is active for a single system clock cycle. To get the enable centered
around the rising edge of the system clock, I am clocking the edge
detector with an inverted system clock. I have read not to use
anything other than the system clock as the clock signal to a flip
flop, so I am uncomfortable using the inverted clock. Is the inverted
clock ok? Does anyone have any recommendations on a better way to do
this.
library ieee;
use ieee.std_logic_1164.all;
entity edge_detector is
port (
clock : in std_logic;
d : in std_logic;
rising_edge_out : out std_logic
);
end;
architecture behavioral of edge_detector is
signal sreg : std_logic_vector(1 downto 0);
begin
edge_detector_proc : process(clock)
begin
if rising_edge(clock) then
if sreg(1 downto 0) = "01" then
rising_edge_out <= '1';
else
rising_edge_out <= '0';
end if;
sreg <= sreg(0) & d;
end if;
end process;
end architecture;
entity clock_divider is
port (
clock : in std_logic;
reset : in std_logic;
clock_enable_clock_divided : out std_logic
);
end clock_divider;
architecture behavioral of clock_divider is
signal inverted_clock : std_logic;
signal clock_divided_i : std_logic;
signal count : unsigned(4 downto 0) := (others => '0');
begin
clock_divided_edge_proc : entity work.edge_detector
port map (
clock => inverted_clock,
d => clock_divided_i,
rising_edge_out => clock_enable_clock_divided
);
inverted_clock <= not clock;
clock_divider_counter_proc: process (reset, clock)
begin
if reset = '1' then
count <= (others => '0');
clock_divided_i <= '0';
elsif rising_edge(clock) then
count <= count + 1;
clock_divided_i <= count(4);
end if;
end process;
end behavioral;