Advertisement
rezafara

DNALock

Oct 17th, 2015
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.84 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    16:55:43 10/12/2015
  6. -- Design Name:
  7. -- Module Name:    DNALock - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.numeric_std.all;
  23.  
  24. library UNISIM;
  25. use UNISIM.VCOMPONENTS.ALL;
  26.  
  27. entity DNALock is
  28.     port(
  29.     CLK_98MHz     : in  std_logic;
  30.     readDNACmd    : in  std_logic;
  31.     DNA_SerailIn  : in  std_logic;
  32.     SR_Clear      : in  std_logic;
  33.     areset        : in  std_logic;
  34.     DNA_Shift     : out std_logic:='0';
  35.     DNA_Read      : out std_logic:='0';
  36.     DNA_CLK       : buffer std_logic;
  37.     DNAVerify     : out std_logic:='0';
  38.     DNAReady          : out std_logic:='0');
  39. end DNALock;
  40.  
  41. architecture Behavioral of DNALock is
  42.  
  43. -- Defining medium signals for shift register
  44. signal  SR_read: std_logic:= '0';
  45. signal  SR_clk : std_logic:= '0';
  46. signal   SR_Out: std_logic_vector(63 downto 0) := (others => '0');
  47. signal   SR_DataReady:std_logic:= '0';
  48.  
  49. --DNA clock medium signal
  50. signal   DNA_CLK_Temp: std_logic :='0';
  51.  
  52.  
  53. --10MHz signal period
  54. constant DNA_CLK_period : time := 100 ns;
  55. --Device DNA
  56. constant DeviceDNA :std_logic_vector(63 downto 0) :=X"FFFFFFFFFFFFFFFF";
  57.  
  58. signal  clkCounter: unsigned(7 downto 0):= "00000000";
  59. signal  clkCounter2: unsigned(7 downto 0):= "00000000";
  60. signal   SR_Readb :std_logic:= '1';
  61. --Defining state machine states:
  62. type controllerState is (zeroState,initState,readState,endReadState);
  63. signal state : controllerState;
  64.  
  65. begin
  66.  
  67.     --Magic clock generator!
  68.     DNA_CLK_Temp <= not DNA_CLK_Temp after DNA_CLK_period/2;
  69.  
  70.  
  71.     SR_Readb <= '1';
  72.  
  73.     --This process make read and shift signals for DNA device
  74. --  controller:process(DNA_CLK_Temp)
  75. -- 
  76. --      variable COUNT    :unsigned(7 downto 0) := "00000000";
  77. --      variable readFlag :bit:='0';
  78. --      variable busyFlag :bit:='0';
  79. --     
  80. --  begin
  81. --  if (DNA_CLK_Temp'event and DNA_CLK_Temp = '1') then
  82. --      if readFlag = '1' then
  83. --          DNA_Read  <= '0';
  84. --          DNA_Shift <= '1';--after 20 ns;
  85. --          readFlag :=  '0';
  86. --      end if;
  87. --     
  88. --      if readDNACmd = '1' and busyFlag = '0' then
  89. --          busyFlag  := '1';
  90. --          readFlag :=  '1';
  91. --          DNA_Read  <= '1';
  92. --          SR_read   <= '1';
  93. --          SR_clk    <= DNA_CLK;
  94. --      end if;
  95. --     
  96. --      if busyFlag = '1' then
  97. --          COUNT := COUNT + 1;
  98. --      end if;
  99. --       
  100. --      if COUNT = 66 then
  101. --          busyFlag := '0';
  102. --          DNA_Shift <= '0' after 20 ns;
  103. --          SR_read <= '0';
  104. --          SR_clk  <= '0';
  105. --      end if;
  106. --  end if;
  107. --  end process Controller;
  108.     --Implementing controller using FSM
  109.  
  110.    
  111.     FSMStateController:process(DNA_CLK_Temp,areset)
  112.    
  113.     --variable clkCounter    :unsigned(7 downto 0) := "00000000";
  114.    
  115.     begin
  116.    
  117.     if (areset = '1') then
  118.         state <= zeroState;
  119.     elsif (DNA_CLK_Temp'event and DNA_CLK_Temp = '1') then
  120.         case state is
  121.             when zeroState =>
  122.                 if readDnaCmd = '1' then
  123.                     state <= initState;
  124.                 end if;
  125.                
  126.             when initState =>
  127.                 state <= readState;
  128.                
  129.             when readState =>
  130.                 --clkCounter := clkCounter + 1;
  131.                 clkCounter <= clkCounter + X"01";
  132.                 if clkCounter = X"40" then
  133.                     state <= endReadState;
  134.                 end if;
  135.                
  136.             when endReadState =>
  137.                 state <= zeroState;
  138.                
  139.         end case;
  140.     end if;
  141.    
  142.     end process FSMStateController;
  143.    
  144.    
  145.     FSMOutputController:process(state,readDnaCmd)
  146.    
  147.     variable clkCounter    :unsigned(7 downto 0) := "00000000";
  148.    
  149.     begin
  150.    
  151.         case state is
  152.             when zeroState =>
  153.                 if readDnaCmd = '1' then
  154.                     DNA_Read <= '1';
  155.                     SR_read   <= '0';
  156.                 else
  157.                     SR_read   <= '1';
  158.                 end if;
  159.             when initState =>
  160.                 DNA_Read  <= '0';
  161.                 SR_read   <= '1';
  162.                 SR_clk    <= DNA_CLK_temp;
  163.                 DNA_Shift <= '1';
  164.                
  165.             when endReadState =>
  166.                 DNA_shift <= '0';
  167.                 SR_read   <= '0';
  168.             when readState =>
  169.                 clkCounter := clkCounter + 1;
  170.                 --clkCounter2 <= clkCounter2 + X"01";
  171.                 SR_read   <= '0';
  172.         end case;
  173.      
  174.     end process FSMOutputController;
  175.  
  176.  
  177.  
  178.     --Implementing a 64-bit shift register to read from DNA device
  179.     shiftRegister:process(DNA_CLK_Temp)
  180.     variable COUNT2:unsigned(7 downto 0):= "00000000";
  181.     begin
  182.     if (DNA_CLK_Temp'event and DNA_CLK_Temp = '1') then
  183.    
  184.         if SR_read = '1' then
  185.             SR_Out(to_integer(COUNT2)) <=  DNA_SerailIn;
  186.             COUNT2 := COUNT2 + 1;
  187.         end if;
  188.        
  189.         if COUNT2 = 64 then
  190.             SR_DataReady <= '1';
  191.             COUNT2 := "00000000";
  192.         end if;
  193.    
  194.     end if;
  195.     end process shiftRegister;
  196.  
  197.     checkDNA:process(SR_DataReady)
  198.     begin
  199.     if (SR_DataReady = '1') then
  200.         DNAReady <= '1';
  201.         if DeviceDNA = SR_Out then
  202.             DNAVerify <= '1';
  203.         end if;
  204.         DNAReady <= '0' after 500 ns;
  205.     end if;
  206.     end process checkDNA;
  207.    
  208.     DNA_CLK <= DNA_CLK_Temp;
  209.    
  210. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement