~ruther/vhdl-i2c

ref: 1a805dd2063476e1dff9765995f8058ef4d0a029 vhdl-i2c/src/utils/sync_edge_detector.vhd -rw-r--r-- 1.7 KiB
1a805dd2 — Rutherther tests: add slave testbench 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-------------------------------------------------------------------------------
-- Title      : Synchronous edge detector
-- Project    :
-------------------------------------------------------------------------------
-- File       : sync_edge_detector.vhd
-- Author     : Frantisek Bohacek  <rutherther@protonmail.com>
-- Created    : 2023-11-26
-- Last update: 2023-11-26
-- Platform   :
-- Standard   : VHDL'93/02
-------------------------------------------------------------------------------
-- Description: Detects edges in signal_i, synchronously to clk_i
-------------------------------------------------------------------------------
-- Copyright (c) 2023
-------------------------------------------------------------------------------
-- Revisions  :
-- Date        Version  Author  Description
-- 2023-11-26  1.0      ruther	Created
-------------------------------------------------------------------------------


library ieee;
use ieee.std_logic_1164.all;

entity sync_edge_detector is

  port (
    clk_i          : in  std_logic;
    signal_i       : in  std_logic;
    rising_edge_o  : out std_logic;
    falling_edge_o : out std_logic);

end entity sync_edge_detector;

architecture a1 of sync_edge_detector is
  signal reg_prev_signal : std_logic;
  signal next_prev_signal : std_logic;
begin  -- architecture a1
  next_prev_signal <= signal_i;

  rising_edge_o <= '1' when reg_prev_signal = '0' and signal_i = '1' else
                   '0';

  falling_edge_o <= '1' when reg_prev_signal = '1' and signal_i = '0' else
                    '0';

  set_next: process (clk_i) is
  begin  -- process set_next
    if rising_edge(clk_i) then          -- rising clock edge
      reg_prev_signal <= next_prev_signal;
    end if;
  end process set_next;

end architecture a1;
Do not follow this link