Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:   19:19:52 12/12/2017
  6. -- Design Name:
  7. -- Module Name:   adc - 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.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity adc is
  33.  
  34. port(
  35. reset3 : in  STD_LOGIC;
  36. clk: in STD_LOGIC;
  37.               SPI_MISO :in  STD_LOGIC;
  38.               AMP_CS : out STD_LOGIC;
  39.               SPI_SCK : out STD_LOGIC;
  40.               AMP_SHDN :  out STD_LOGIC ;
  41.               sf_ceo: out STD_logic:='1';
  42.               fpga_init_b: out STD_logic:='0';
  43.               dac_cs: out STD_logic:='1';
  44.               AD_CONV : out  STD_LOGIC;
  45.               SPI_MOSI :  OUT STD_LOGIC;
  46.               SPI_SS_B : out std_logic:='1' ;
  47.               output2 : out std_logic_vector (13 downto 6);
  48.               output4 : out std_logic_vector (13 downto 0)
  49.           );
  50.  
  51. end adc;
  52.  
  53. architecture Behavioral of adc is
  54.  
  55.  
  56.  
  57. Type State_typex is (S0,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10);
  58. Signal y: State_typex:=S0;
  59. signal output : std_logic_vector (13 downto 0):="00000000000000";
  60. signal output3 : std_logic_vector (13 downto 0):="00000000000000";
  61. Signal enable : std_logic:='0';
  62. Signal i4 : Integer:=0 ;
  63. Signal j : Integer range 0 to 50;
  64. Signal clock1m : std_logic := '0' ;
  65. constant gain: std_logic_vector(7 downto 0):="10001000";
  66.  
  67. begin
  68.  
  69. process (clk )
  70. begin
  71.     if(clk = '1' and clk'event)then
  72.         if(j = 25) then
  73.         clock1m <= clock1m xor '1' ;
  74.             j <= j+1;
  75.             elsif j=50 then
  76.             clock1m<= clock1m xor '1';
  77.             j<=0;
  78.             else
  79.             j<=j+1;
  80.             end if;
  81.         end if;
  82.         end process ;
  83.        
  84.         amp_shdn <= '0';
  85.         dac_cs <= '1';
  86.         spi_ss_b <= '1';
  87.         sf_ceo <= '1';
  88.         fpga_init_b <= '0';
  89.        
  90. process ( clock1m )
  91. begin
  92. if  (falling_edge(clock1m))  then  
  93. if  y=s6 then
  94.                     output <= output(12 downto 0) & spi_miso;
  95. elsif  y=s8 then
  96.                    output3<= output3(12 downto 0 ) & spi_miso ;
  97. end if ;
  98. end if;
  99. end process ;          
  100.  
  101.  
  102. gain1 : process(clock1m, y)
  103. begin
  104. if(falling_edge(clock1m) and y = s2) then
  105. spi_mosi <= gain(i4);
  106. end if;
  107. end process;
  108. process( clk ,reset3)
  109. begin
  110. if reset3 = '1' then
  111.     y<=S0 ;
  112. elsif  (clk'event and clk ='1' and j = 25)  then
  113. Case y is
  114.     when S0 =>
  115.          y <= S1;
  116.             amp_cs <= '1';
  117.     when S1 =>
  118.              y <= S2 ;
  119.              amp_cs <= '0';
  120.     when S2 =>
  121.          
  122.             if(i4 < 7) then
  123.              i4 <= i4+1 ;
  124.              y<=S2;
  125.            else
  126.                 y<=S3   ;
  127.             end if;
  128.  
  129.    when S3 =>
  130.          amp_cs <= '1';
  131.        i4 <= 0 ;         
  132.          y <= S4 ;
  133.          
  134.    when S4 =>
  135.              y<=S5 ;
  136.              
  137.     when S5 =>
  138.                y <= S6;
  139.     when S6 =>
  140.      if( i4<14 ) then
  141.                    
  142.                  i4<=i4+1;
  143.                y <= S6;
  144.  
  145.                   elsif(i4 = 14) then
  146.                   i4 <= 0;
  147.                   y <= S7 ;
  148.                   end if;
  149.     when S7 =>
  150.                     i4 <= 0;
  151.                      y<= S8 ;
  152.                  
  153.    when S8 =>
  154.                
  155.             if (i4 < 14) then
  156.                  i4 <= i4+1 ;
  157.                 y<= s8 ;
  158.                 else
  159.                 i4<=0;
  160.                 y<= S9 ;
  161.                 end if ;
  162.    when S9 =>
  163.              i4 <= i4+1 ;
  164.  
  165.           if( i4=1 ) then
  166.           i4<=0 ;
  167.           y <= S10;
  168.           else
  169.         y<=s9 ;
  170.           end if ;
  171.          
  172.    when S10 =>
  173.         i4 <= i4+1 ;
  174.           if( i4=1 ) then
  175.            i4<=0 ;
  176.           y <= S4;
  177.           output2<=output (13 downto 6);
  178.           output4<=output3 ;
  179.           else
  180.             y<=s10;
  181.           end if;
  182.     when others => y<=S0;    
  183.             end case;
  184.             end if;
  185.             end process ;          
  186.  
  187.  
  188. spisck1: process ( clock1m )
  189. begin
  190. if(falling_edge(clock1m)) then
  191. if( (y = s3  ) or  (  y = s10  ))  
  192. then
  193.  enable <= '0' ;
  194.  elsif (( i4 = 0 and  y = s2  ) or (y = s4 ) ) then
  195.  enable <= '1' ;
  196.  end if ;
  197. end if;
  198. end process;
  199.  
  200. spi_sck <= clock1m when enable = '1' else '0' ;
  201. ad_conv <= clock1m when y =s4 else '0' ;  
  202.  
  203. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement