Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 21.08.2019 15:22:10
  6. -- Design Name:
  7. -- Module Name: Design - 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.  
  21.  
  22. library IEEE;
  23. use IEEE.STD_LOGIC_1164.ALL;
  24. use IEEE.numeric_std.ALL;
  25.  
  26. -- Uncomment the following library declaration if using
  27. -- arithmetic functions with Signed or Unsigned values
  28. --use IEEE.NUMERIC_STD.ALL;
  29.  
  30. -- Uncomment the following library declaration if instantiating
  31. -- any Xilinx leaf cells in this code.
  32. library UNISIM;
  33. use UNISIM.VComponents.all;
  34.  
  35.  
  36. entity Ect_v3 is
  37. generic ( CHARGE_TIME_NS : integer := 144405;
  38. DISCHARGE_TIME_NS : integer := 4545;
  39. START_READ_NS : integer := 10000;
  40. PERIOD_NS : integer := 400000
  41. );
  42. -- Port ( );
  43. port (
  44. S : inout std_logic;
  45. SS : out std_logic
  46. );
  47. end Ect_v3;
  48.  
  49. architecture Behavioral of Ect_v3 is
  50.  
  51. constant clock_cycle : integer := 21;
  52. constant one_time : integer := CHARGE_TIME_NS / clock_cycle;
  53. constant zero_time : integer := (CHARGE_TIME_NS + DISCHARGE_TIME_NS) / clock_cycle;
  54. constant read_time : integer := (START_READ_NS + CHARGE_TIME_NS + DISCHARGE_TIME_NS) / clock_cycle;
  55. constant max_time : integer := PERIOD_NS / clock_cycle;
  56.  
  57. --signal counter : std_logic_vector(25 downto 0):=(others=>'0');
  58. signal i_clk : std_logic;
  59. signal buf_i_clk : std_logic;
  60. signal r_led_value : std_logic := '0';
  61.  
  62. SIGNAL b : STD_LOGIC; --DFF that stores feedback value
  63. shared variable counter : integer range 0 to PERIOD_NS/clock_cycle :=0;
  64. signal dir : std_logic;
  65.  
  66. begin
  67.  
  68. STARTUPE2_inst : STARTUPE2
  69. generic map (
  70. PROG_USR => "FALSE",
  71. SIM_CCLK_FREQ => 0.0
  72. )
  73. port map (
  74. CFGCLK => open,
  75. CFGMCLK => i_clk,
  76. EOS => open,
  77. PREQ => open,
  78. CLK => '0',
  79. GSR => '0',
  80. GTS => '0',
  81. KEYCLEARB => '0',
  82. PACK => '0',
  83. USRCCLKO => '0',
  84. USRCCLKTS => '0',
  85. USRDONEO => '1',
  86. USRDONETS => '0'
  87. );
  88.  
  89. BUFG_i: component BUFG
  90. port map(
  91. I => i_clk ,
  92. O => buf_i_clk
  93. );
  94.  
  95. -- buf_i_clk has around 65MHz
  96.  
  97. process(buf_i_clk)
  98. begin
  99. if rising_edge(buf_i_clk) then
  100. if counter < max_time then
  101. counter := counter + 1;
  102. if counter < zero_time then
  103. dir <= '1';
  104. else
  105. dir <= '0';
  106. end if;
  107. else
  108. dir <= '0';
  109. counter := 0;
  110. end if;
  111. end if;
  112.  
  113. SS <= b;
  114.  
  115. if (dir = '0') then
  116. if counter = zero_time then
  117. S <= 'Z';
  118. else
  119. if counter = read_time then
  120. b <= S;
  121. end if;
  122. end if;
  123. else
  124. if counter < one_time then
  125. S <= '1';
  126. elsif counter >= one_time and counter < zero_time then
  127. S <= '0';
  128. end if;
  129. end if;
  130. end process;
  131.  
  132.  
  133. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement