---------------------------------------------------------------
-- L F S R . V
-- Scott Harrington
-- Spring 1995
-- VHDL source for simple GERM LFSR counter
--
-- For 3, 4, 6, 7, or 15 bit LFSR the XNOR feedback is from
-- the two most significant output bits.
-- See Xilinx Data Book p. 9-24.
----------------------------------------------------------------

LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;

-----------------------
-- I/O descriptions: --
-----------------------

--	Clk: FPGA TCLK
--	CE: Clock Enable to LFSR flip flops
--  CLR: Synchronous CLR to all zeros
--	Q3-0: output bits, pseudorandom sequence of length 15
--   (BUFFER type allows Q's value to be read as well as written)

ENTITY lfsr IS
	PORT (
		Clk: IN std_logic;
		CE: IN std_logic;
		CLR: IN std_logic;
		Q: BUFFER std_logic_vector(3 downto 0)
		);
END lfsr;

ARCHITECTURE behav OF lfsr IS

SIGNAL Qnext: std_logic_vector(3 downto 0);
SIGNAL feedback: std_logic;

BEGIN

	feedback <= NOT (Q(3) XOR Q(2));

	-- This is the combinational feedback logic
	LfsrComboProc: Qnext <= Q(2 downto 0) & feedback;

	-- This is the clocked process that causes flipflop to be inferred
	LfsrClockProc: PROCESS
	BEGIN
		WAIT UNTIL Clk'EVENT AND Clk='1';
		IF (CLR='1') THEN		-- infer synchronous clear
			Q <= "0000";
		ELSIF (CE='1') THEN		-- infer clock enable
			Q <= Qnext;
		END IF;
	END PROCESS;

END behav;

<div align="center"><br /><script type="text/javascript"><!--
google_ad_client = "pub-7293844627074885";
//468x60, Created at 07. 11. 25
google_ad_slot = "8619794253";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />&nbsp;</div>