Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. -- Company:
  2. -- Engineer:
  3. --
  4. -- Create Date: 19:19:52 12/12/2017
  5. -- Design Name:
  6. -- Module Name: adc - Behavioral
  7. -- Project Name:
  8. -- Target Devices:
  9. -- Tool versions:
  10. -- Description:
  11. --
  12. -- Dependencies:
  13. --
  14. -- Revision:
  15. -- Revision 0.01 - File Created
  16. -- Additional Comments:
  17. --
  18. ----------------------------------------------------------------------------------
  19. library IEEE;
  20. use IEEE.STD_LOGIC_1164.ALL;
  21.  
  22. -- Uncomment the following library declaration if using
  23. -- arithmetic functions with Signed or Unsigned values
  24. --use IEEE.NUMERIC_STD.ALL;
  25.  
  26. -- Uncomment the following library declaration if instantiating
  27. -- any Xilinx primitives in this code.
  28. --library UNISIM;
  29. --use UNISIM.VComponents.all;
  30.  
  31. entity adc is
  32.  
  33. port(
  34. reset : in STD_LOGIC;
  35. clk: in STD_LOGIC;
  36. SPI_MISO :in STD_LOGIC;
  37. AMP_CS : out STD_LOGIC;
  38. SPI_SCK : out STD_LOGIC;
  39. AMP_SHDN : out STD_LOGIC ;
  40. sf_ceo: out STD_logic:='1';
  41. fpga_init_b: out STD_logic:='0';
  42. dac_cs: out STD_logic:='1';
  43. AD_CONV : out STD_LOGIC;
  44. SPI_MOSI : OUT STD_LOGIC;
  45. SPI_SS_B : out std_logic:='1' ;
  46. channela : out std_logic_vector (13 downto 6);
  47. channelb : out std_logic_vector (13 downto 0)
  48. );
  49.  
  50. end adc;
  51.  
  52. architecture Behavioral of adc is
  53.  
  54.  
  55.  
  56. Type State_typex is (S0,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10);
  57. Signal y: State_typex:=S0;
  58. signal channel1 : std_logic_vector (13 downto 0):="00000000000000";
  59. signal channel2 : std_logic_vector (13 downto 0):="00000000000000";
  60. Signal enable : std_logic:='0';
  61. Signal i : Integer:=0 ;
  62. Signal j : Integer range 0 to 50;
  63. Signal clock1m : std_logic := '0' ;
  64. constant gain: std_logic_vector(7 downto 0):="10001000";
  65.  
  66. begin
  67.  
  68. process (clk )
  69. begin
  70. if(clk = '1' and clk'event)then
  71. if(j = 25) then
  72. clock1m <= clock1m xor '1' ;
  73. j <= j+1;
  74. elsif j=50 then
  75. clock1m<= clock1m xor '1';
  76. j<=0;
  77. else
  78. j<=j+1;
  79. end if;
  80. end if;
  81. end process ;
  82.  
  83. amp_shdn <= '0';
  84. dac_cs <= '1';
  85. spi_ss_b <= '1';
  86. sf_ceo <= '1';
  87. fpga_init_b <= '0';
  88.  
  89. process ( clock1m )
  90. begin
  91. if (falling_edge(clock1m)) then
  92. if y=s6 then
  93. channel1 <= channel1(12 downto 0) & spi_miso;
  94. elsif y=s8 then
  95. channel2<= channel2(12 downto 0 ) & spi_miso ;
  96. end if ;
  97. end if;
  98. end process ;
  99.  
  100.  
  101. gain1 : process(clock1m, y)
  102. begin
  103. if(falling_edge(clock1m) and y = s2) then
  104. spi_mosi <= gain(i);
  105. end if;
  106. end process;
  107. process( clk ,reset
  108. )
  109. begin
  110. if reset = '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(i < 7) then
  123. i <= i+1 ;
  124. y<=S2;
  125. else
  126. y<=S3 ;
  127. end if;
  128.  
  129. when S3 =>
  130. amp_cs <= '1';
  131. i <= 0 ;
  132. y <= S4 ;
  133.  
  134. when S4 =>
  135. y<=S5 ;
  136.  
  137. when S5 =>
  138. y <= S6;
  139. when S6 =>
  140. if( i<14 ) then
  141.  
  142. i<=i+1;
  143. y <= S6;
  144.  
  145. elsif(i = 14) then
  146. i <= 0;
  147. y <= S7 ;
  148. end if;
  149. when S7 =>
  150. i <= 0;
  151. y<= S8 ;
  152.  
  153. when S8 =>
  154.  
  155. if (i < 14) then
  156. i <= i+1 ;
  157. y<= s8 ;
  158. else
  159. i<=0;
  160. y<= S9 ;
  161. end if ;
  162. when S9 =>
  163. i <= i+1 ;
  164.  
  165. if( i=1 ) then
  166. i<=0 ;
  167. y <= S10;
  168. else
  169. y<=s9 ;
  170. end if ;
  171.  
  172. when S10 =>
  173. i <= i+1 ;
  174. if( i=1 ) then
  175. i<=0 ;
  176. y <= S4;
  177. channela<=channel1 (13 downto 6);
  178. channelb<=channel2 ;
  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 (( i = 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