Advertisement
AymenSekhri

Problem 4

Nov 30th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_unsigned.all;
  4. Entity problem01 is
  5. Port(UP,clk,rst :in std_logic;
  6. y: out std_logic_vector(3 downto 0));
  7. End Entity;
  8. Architecture bhv of problem01 is
  9. signal counter:std_logic_vector(24 downto 0):= (others=>'0');
  10. signal Clk_slow :std_logic;
  11. signal Slow_Counter :std_logic_vector(3 downto 0):= (others=>'0');
  12. Begin
  13. Process(clk,rst)
  14. Begin
  15. if rst='1' Then
  16. counter <=(others=>'0');
  17. Elsif Clk'event and Clk='1' Then
  18. counter <= counter + 1;
  19. End if;
  20. End Process;
  21. Clk_slow <= counter(24);
  22. Process(Clk_slow,rst)
  23. Begin
  24. if rst='1' Then
  25. Slow_Counter <=(others=>'0');
  26. Elsif Clk_slow'event and Clk_slow='1' Then
  27. if UP = '0' Then--if UP is low
  28. Slow_Counter <= Slow_Counter + 1;
  29. Else--otherwise
  30. Slow_Counter <= Slow_Counter - 1;
  31. End if;
  32. End if;
  33. End Process;
  34. y <= Slow_Counter;
  35.  
  36. End;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement