Morell
Member level 1
Hi,
I wrote these Components.
I simulated both of them and they worked correctly but
in implementation(Spartan-3 50MHz), they sometimes work and sometimes don't.
1- Debouncer:
There are two counters : Clock_Divider_Counter (Works with 50MHz) and
Debounce_Counter (Works with 1KHz)
If Bounced_Start (Input) is '1' for about 100 mili seconds then
Decounced_Start (Output) will become '1' only for one clock pulse (1/50MHz).
2- FIFO :
Input (Data_in) is 1 to 4 bytes.
Output (Data_out) is 1 byte.
Data_out is Data_in_Reg(i).
I wrote these Components.
I simulated both of them and they worked correctly but
in implementation(Spartan-3 50MHz), they sometimes work and sometimes don't.
1- Debouncer:
There are two counters : Clock_Divider_Counter (Works with 50MHz) and
Debounce_Counter (Works with 1KHz)
If Bounced_Start (Input) is '1' for about 100 mili seconds then
Decounced_Start (Output) will become '1' only for one clock pulse (1/50MHz).
Code VHDL - [expand] 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 entity Debouncer is Port (Clock : in STD_LOGIC; Reset : in STD_LOGIC:='0'; Bounced_Start : in STD_LOGIC:='0'; Debounced_Start : out STD_LOGIC:='0'); end Debouncer; architecture Behavioral of Debouncer is Constant Clock_Divider_Counter_Top : integer := 50000; -- 50000 Constant Debounce_Counter_Top : integer := 100; -- 100 Signal Bounced_Start_Reg : std_logic := '0'; Signal Debounced_Start_Reg : std_logic := '0'; Signal Clock_Divider_Counter : integer range 0 to Clock_Divider_Counter_Top :=0; Signal Debounce_Counter : integer range 0 to Debounce_Counter_Top := 0; begin Debounced_Start <= Debounced_Start_Reg; Process (Clock) Begin if rising_edge (Clock) then if RESET = '1' then -- reset all assigned signals Bounced_Start_Reg <= '0'; Debounced_Start_Reg <= '0'; Clock_Divider_Counter <= 0; Debounce_Counter <= 0; else -- Default assignments Bounced_Start_Reg <= Bounced_Start; ------------------------------------------------------------------------------------ if Bounced_Start = '1' then Clock_Divider_Counter <= Clock_Divider_Counter + 1; else Clock_Divider_Counter <= 0; end if; ------------------------------------------------------------------------------------ if (Clock_Divider_Counter = Clock_Divider_Counter_Top) then Clock_Divider_Counter <= 0; if (Bounced_Start_Reg = '1') then Debounce_Counter <= Debounce_Counter + 1; else Debounce_Counter <= 0; end if; end if; ------------------------------------------------------------------------------------ if Debounce_Counter = Debounce_Counter_Top then Debounced_Start_Reg <= '1'; Debounce_Counter <= 0; else Debounced_Start_Reg <= '0'; end if; ------------------------------------------------------------------------------------ end if; end if; End Process; end Behavioral;
2- FIFO :
Input (Data_in) is 1 to 4 bytes.
Output (Data_out) is 1 byte.
Data_out is Data_in_Reg(i).
Code VHDL - [expand] 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 entity FIFO is Generic (FIFO_Length : integer range 1 to 4 :=1; Byte : integer := 8); Port (Clock : in STD_LOGIC; Reset : in STD_LOGIC:='0'; Write_in : in STD_LOGIC:='0'; FIFO_Ready : out STD_LOGIC:='0'; i : in integer range 0 to FIFO_Length-1:=0; Data_in : in STD_LOGIC_VECTOR((FIFO_Length * Byte)-1 downto 0); Data_out : out STD_LOGIC_VECTOR(Byte-1 downto 0)); end FIFO; architecture Behavioral of FIFO is type FIFO_Type is array (0 to FIFO_Length - 1) of std_logic_vector(7 downto 0) ; signal Data_in_Reg : FIFO_Type := (others => x"00"); signal Data_out_Reg : std_logic_vector(Byte-1 downto 0):=(Others => '0'); signal Write_in_Reg : std_logic:='0'; signal FIFO_Ready_Reg : std_logic:='0'; signal Index : integer range 0 to (FIFO_Length-1):=0; signal j : integer range 0 to (FIFO_Length-1):=0; type State is (Idle,Writing,Reading); signal Current : State := Idle; begin -- Combinatorial Parts FIFO_Ready <= FIFO_Ready_Reg; Data_out <= Data_out_Reg; Process(Clock) begin if rising_edge(Clock) then if reset = '1' then -- Reset all assigned signals Index <= 0; Write_in_Reg <= '0'; Current <= Idle; J <= 0; Data_in_Reg <= (Others => X"00"); Data_out_Reg <= (Others => '0'); FIFO_Ready_Reg <='0'; else -- Default assignments Index <= i; Write_in_Reg <= Write_in; Case Current is --Idle------------------------------------------------ When Idle => FIFO_Ready_Reg <= '0'; if Write_in_Reg = '1' then Current <= Writing; else Current <= Idle; end if; --Writing------------------------------------------------ When Writing => if (j /= FIFO_Length-1) then Data_in_Reg(j) <= Data_in( (Byte * (j+1))-1 downto Byte * j ); j <= j + 1; else Data_in_Reg(j) <= Data_in( (Byte * (j+1))-1 downto Byte * j ); Current <= Reading; end if; --Reading------------------------------------------------ When Reading => FIFO_Ready_Reg <= '1'; Data_out_Reg <= Data_in_Reg(Index); if (Index = 0) then Current <= Idle; end if; --------------------------------------------------------- End Case; end if; end if; end Process; end Behavioral;