Advertisement
milanmetal

PSDS z2_2

Oct 24th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.93 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    16:56:03 04/25/2017
  6. -- Design Name:
  7. -- Module Name:    m to n counter - 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. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.all;
  24. use ieee.numeric_std.all;
  25.  
  26. -- clog2b function
  27. use work.util_pkg.all;
  28.  
  29. entity range_counter is
  30.     generic(
  31.     M : integer := 3;
  32.     N : integer := 50
  33.   );
  34.  
  35.   port (clk             : in std_logic;
  36.           en_i          : in std_logic;
  37.           overflow_o    : out std_logic;
  38.           reset_i       : in std_logic;
  39.           q_o           : out std_logic_vector(clog2b(N+1)-1 downto 0)
  40.         );
  41. end range_counter;
  42.  
  43. architecture Behavioral of range_counter is
  44.   signal count_s : std_logic_vector(clog2b(N+1)-1 downto 0);
  45.  
  46.   -- bit_num gives the minimum number of bits needed to
  47.   -- represent upper limit
  48.   constant bit_num : integer := clog2b(N+1);
  49.  
  50. begin
  51.   process(clk)
  52.     begin
  53.       if(clk'event and clk='1') then
  54.         overflow_o <= '0';
  55.  
  56.         if reset_i='1' then
  57.  
  58.         -- put smaller value into bit_num of bigger number
  59.         count_s <= conv_std_logic_vector(M, bit_num);
  60.         else
  61.           if en_i ='1' then
  62.             if count_s < conv_std_logic_vector(N, bit_num) then
  63.               --if conv_integer(count_s) < 89 then      -- identicna provera
  64.               count_s <= count_s + '1';
  65.             else
  66.               overflow_o <= '1';
  67.               count_s <= conv_std_logic_vector(M, bit_num);
  68.             end if;
  69.           end if;
  70.         end if;
  71.       end if;
  72.     end process;
  73.   q_o <= count_s;
  74. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement