Advertisement
Sebgg

uppgift21a

May 18th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  4.  
  5. entity timer is
  6. Port(
  7. clk, mux, time : in std_logic;
  8. start_in, reset_in : in std_logic;
  9. time_prec : in std_logic;
  10. a, b, c, d, e, f, g, dp, dspA, dspB : out std_logic);
  11. end timer;
  12.  
  13. architecture atimer of timer is
  14. signal en_p, en_t, en_p_plus, en_t_plus, start, reset, start_plus, reset_plus : std_logic := '0';
  15. signal adress, seconds_1, seconds_10, minutes_1, minutes_10 : std_logic_vector(3 downto 0) := "0000";
  16. signal mseconds_1, mseconds_10, mseconds_100 : std_logic_vector(3 downto 0) := "0000";
  17. signal t_prec : std_logic := '0';
  18. signal count_enable : std_logic := '0';
  19. signal display : std_logic_vector(1 downto 0) := "00";
  20. signal data : std_logic_vector(6 downto 0) := "0000000";
  21.  
  22. begin
  23.  
  24. -- Klocka insignaler
  25. process(clk) begin
  26. if rising_edge(clk) then
  27. en_p <= en_p_plus;
  28. en_t <= en_t_plus;
  29. en_p_plus <= mux;
  30. en_t_plus <= time;
  31. start <= start_plus;
  32. reset <= reset_plus;
  33. start_plus <= start_in;
  34. reset_plus <= reset_in;
  35. t_prec <= time_prec;
  36. end if;
  37. end process;
  38.  
  39. -- Räkna upp
  40. process(clk) begin
  41. if rising_edge(clk) then
  42. if (start='0' and start_plus='1') then
  43. count_enable <= not count_enable;
  44. elsif (reset='0' and reset_plus='1') then
  45. seconds_1 <= "0000";
  46. seconds_10 <= "0000";
  47. minutes_1 <= "0000";
  48. minutes_10 <= "0000";
  49. count_enable <= '0';
  50. elsif (en_t = '0' and en_t_plus = '1' and count_enable = '1') then
  51. mseconds_1 <= mseconds_1 + 1;
  52. if (mseconds_100 = 9 and mseconds_10 = 9 and mseconds_1 = 8 and seconds_1 = 9 and seconds_10 = 5 and minutes_1 = 9 and minutes_10 = 5) then
  53. count_enable <= '0';
  54. elsif (mseconds_100 = 9 and mseconds_10 = 9 and mseconds_1 = 9 and seconds_1 = 9 and seconds_10 = 5 and minutes_1 = 9) then
  55. minutes_10 <= minutes_10 + 1;
  56. minutes_1 <= "0000";
  57. seconds_10 <= "0000";
  58. seconds_1 <= "0000";
  59. mseconds_100 <= "0000";
  60. mseconds_10 <= "0000";
  61. mseconds_1 <= "0000";
  62. elsif (mseconds_100 = 9 and mseconds_10 = 9 and mseconds_1 = 9 and seconds_1 = 9 and seconds_10 = 5) then
  63. minutes_1 <= minutes_1 + 1;
  64. seconds_10 <= "0000";
  65. seconds_1 <= "0000";
  66. mseconds_100 <= "0000";
  67. mseconds_10 <= "0000";
  68. mseconds_1 <= "0000";
  69. elsif (mseconds_100 = 9 and mseconds_10 = 9 and mseconds_1 = 9 and seconds_1 = 9) then
  70. seconds_10 <= seconds_10 + 1;
  71. seconds_1 <= "0000";
  72. mseconds_100 <= "0000";
  73. mseconds_10 <= "0000";
  74. mseconds_1 <= "0000";
  75. elsif (mseconds_100 = 9 and mseconds_10 = 9 and mseconds_1 = 9) then
  76. seconds_1 <= seconds_1 + 1;
  77. mseconds_100 <= "0000";
  78. mseconds_10 <= "0000";
  79. mseconds_1 <= "0000";
  80. elsif (mseconds_10 = 9 and mseconds_1 = 9) then
  81. mseconds_100 <= mseconds_100 + 1;
  82. mseconds_10 <= "0000";
  83. mseconds_1 <= "0000";
  84. elsif(mseconds_1 = 9) then
  85. mseconds_10 <= mseconds_10 + 1;
  86. mseconds_1 <= "0000";
  87. end if;
  88. end if;
  89. end if;
  90. end process;
  91.  
  92. -- Sätt adress för PROMen samt välja display-segment
  93. process(clk) begin
  94. if rising_edge(clk) then
  95. if (en_p='0' and en_p_plus='1') then
  96. display <= display + 1;
  97. dp <= '0';
  98. if (display = 0) then
  99. dspA <= '1';
  100. dspB <= '1';
  101. if (t_prec='0') then
  102. adress <= seconds_1;
  103. else
  104. adress <= mseconds_10;
  105. end if;
  106. elsif (display = 1) then
  107. dspA <= '0';
  108. dspB <= '1';
  109. if (t_prec='0') then
  110. adress <= seconds_10;
  111. else
  112. adress <= mseconds_100;
  113. end if;
  114. elsif (display = 2) then
  115. dspA <= '1';
  116. dspB <= '0';
  117. dp <= '1';
  118. if (t_prec='0') then
  119. adress <= minutes_1;
  120. else
  121. adress <= seconds_1;
  122. end if;
  123. elsif (display = 3) then
  124. dspA <= '0';
  125. dspB <= '0';
  126. if (t_prec='0') then
  127. adress <= minutes_10;
  128. else
  129. adress <= seconds_10;
  130. end if;
  131. display <= "00";
  132. end if;
  133. end if;
  134. end if;
  135. end process;
  136.  
  137. -- Översätt tal till display
  138. with adress select
  139. data <= "1111110" when "0000",
  140. "0110000" when "0001",
  141. "1101101" when "0010",
  142. "1111001" when "0011",
  143. "0110011" when "0100",
  144. "1011011" when "0101",
  145. "1011111" when "0110",
  146. "1110000" when "0111",
  147. "1111111" when "1000",
  148. "1111011" when "1001",
  149. "-------" when others;
  150.  
  151. -- Sätt outputs
  152. process(clk) begin
  153. if (en_p='0' and en_p_plus='1') then
  154. if rising_edge(clk) then
  155. a <= data(6);
  156. b <= data(5);
  157. c <= data(4);
  158. d <= data(3);
  159. e <= data(2);
  160. f <= data(1);
  161. g <= data(0);
  162. end if;
  163. end if;
  164. end process;
  165.  
  166. -- Lagra föregående klockpuls
  167.  
  168. end atimer;
  169.  
  170. --vsim timer
  171. --add wave sim:/timer/*
  172. --restart -force
  173. --force -freeze sim:/timer/clk 0 0, 1 4 -r 8
  174. --force -freeze sim:/timer/mux 0 0, 1 50 -r 100
  175. --force -freeze sim:/timer/time 0 0, 1 50 -r 100
  176. --force -freeze sim:/timer/start_in 0 0, 1 100
  177. --force -freeze sim:/timer/reset_in 0 0
  178. --force -freeze sim:/timer/time_prec 1 0
  179. --run 500000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement