I want to detect edges on a serial data signal (din). I wrote the following code in VHDL, which works successfully, but edges are detected with a single time period delay. The change output is generated with one delay of the clk_50mhz period on each edge. Can someone help me immediately spot the edges. Thanks.
process (clk_50mhz) begin if clk_50mhz'event and clk_50mhz = '1' then if (rst = '0') then shift_reg <= (others => '0'); else shift_reg(1) <= shift_reg(0); shift_reg(0) <= din; end if; end if; end process; process (clk_50mhz) begin if clk_50mhz'event and clk_50mhz = '1' then if rst = '0' then change <= '0' ; elsif(clk_enable_2mhz = '1') then change <= shift_reg(0) xor shift_reg(1); end if ; end if ; end process ;
When I changed my code to the next, I was able to detect edges
process (clk_50mhz) begin if clk_50mhz'event and clk_50mhz = '1' then if (RST = '0') then shift_reg <= (others=>'0'); else shift_reg(1) <= shift_reg(0); shift_reg(0) <= din; end if; end if; end process; change <= shift_reg(1) xor din;
source share