Guest User

Untitled

a guest
Dec 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. 0000
  2. 0001
  3. 0005
  4. 3864
  5. 2290
  6. 1234
  7. .
  8. .
  9. .
  10. 0002
  11. 0004
  12. 0006
  13. 4532
  14. 3457
  15. .
  16. .
  17. .
  18.  
  19. library ieee;
  20. use ieee.std_logic_1164.all;
  21. use ieee.numeric_std.all;
  22. use ieee.std_logic_arith.all;
  23. use ieee.std_logic_textio.all;
  24. use std.textio.all;
  25.  
  26.  
  27.  
  28. entity HFA_tb is
  29. end HFA_tb;
  30.  
  31. architecture behave of HFA_tb is
  32.  
  33. --clock 100 MHz change to any value suitable
  34. constant c_CLOCK_PERIOD : time:= 100 ns;
  35. signal r_CLOCK : std_logic := '0';
  36. --**signal r_ENABLE : std_logic := '0';
  37. signal r_adcpulse : integer;
  38. signal r_hitstart : integer; ---output of single threshold
  39. signal r_hitend : integer;
  40. signal r_hitpeak : integer;
  41. signal r_peaktime : integer;
  42. signal r_hitsum : integer;
  43. signal r_opready : std_logic := '0';
  44.  
  45.  
  46.  
  47.  
  48.  
  49. --more signal
  50.  
  51. --describe HFA component here (Unit Under Test)
  52.  
  53. component HFA is
  54. port (
  55. adcpulse_i : in integer;
  56. clk : in std_logic;
  57. hitstart_o : out integer; ---output of single threshold
  58. hitend_o : out integer;
  59. hitpeak_o : out integer;
  60. peaktime_o : out integer;
  61. hitsum_o : out integer;
  62. opready_o : out std_logic
  63.  
  64. );
  65. end component HFA;
  66.  
  67. begin
  68.  
  69. --Instatiate the unit under test
  70. UUT : HFA
  71. port map (
  72. clk => r_CLOCK,
  73. adcpulse_i => r_adcpulse,
  74. hitstart_o => r_hitstart,
  75. hitend_o => r_hitend,
  76. hitpeak_o => r_hitpeak,
  77. peaktime_o => r_peaktime,
  78. hitsum_o => r_hitsum,
  79. opready_o => r_opready
  80. );
  81.  
  82. p_CLK_GEN : process is
  83. begin
  84. wait for c_CLOCK_PERIOD/2;
  85. r_CLOCK <= not r_CLOCK;
  86. end process p_CLK_GEN;
  87.  
  88.  
  89. --main testing logic for reading from text file; feed in the loop and check output
  90.  
  91. process
  92. file in_buffer : text;
  93. file out_buffer : text;
  94. variable v_ILINE : line;
  95. variable v_OLINE : line;
  96. variable v_adcValue : integer;
  97. variable line_counter : integer :=0;
  98. variable block_length : integer :=0;
  99. variable block_counter : integer :=0;
  100. variable header_length : integer :=0;
  101. type H is array (0 to 2) of integer;
  102.  
  103. begin
  104.  
  105. file_open(in_buffer,"sample.txt",read_mode);
  106.  
  107. file_open(out_buffer,"results.txt",write_mode);
  108.  
  109.  
  110. while not endfile(in_buffer) loop
  111. if line_counter=0 then
  112. f1 : for k in 0 to 2 loop
  113. readline(in_buffer, v_ILINE);
  114. read(v_ILINE, v_adcValue);
  115. H(0) := v_adcValue;
  116. line_counter := line_counter+1;
  117. end loop f1;
  118. end if;
  119.  
  120. if line_counter /= 2 and block_length /= 9 then
  121. f2 : for k in 0 to 2 loop
  122. readline(in_buffer, v_ILINE);
  123. read(v_ILINE, v_adcValue);
  124. r_adcpulse <= v_adcValue;
  125. line_counter := line_counter+1;
  126. block_length := block_length+1;
  127. end loop f2;
  128. end if;
  129.  
  130. if block_length=9 then
  131. f3 : for k in 0 to 2 loop
  132. readline(in_buffer, v_ILINE);
  133. read(v_ILINE, v_adcValue);
  134. header(k) <= v_adcValue;
  135. line_counter := line_counter+1;
  136. header_length := header_length+1;
  137. if header_length=3 then
  138. block_length := 0;
  139. exit;
  140. end if;
  141. end loop f3;
  142. end if;
  143.  
  144.  
  145.  
  146. wait for c_CLOCK_PERIOD;
  147.  
  148. end loop;
  149.  
  150. if endfile(in_buffer) then
  151.  
  152. write(v_OLINE, string'("hit_start_time"));
  153. writeline(out_buffer, v_OLINE);
  154.  
  155. write(v_OLINE, r_hitstart);
  156. writeline(out_buffer, v_OLINE);
  157.  
  158. end if;
  159.  
  160. wait for c_CLOCK_PERIOD;
  161.  
  162. file_close(in_buffer);
  163.  
  164. file_close(out_buffer);
  165.  
  166. wait;
  167.  
  168. end process;
  169.  
  170. MONITOR:
  171. process
  172. begin
  173. if now > 0 ns then
  174. report "header = " & to_string(header);
  175. end if;
  176. end process;
  177.  
  178.  
  179. end behave;
Add Comment
Please, Sign In to add comment