aboutsummaryrefslogtreecommitdiff
path: root/src/cntm13.vhd
blob: 3a8bfa9372f7d0f1176083991dcafd3c26182c41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity cntm13 is
  port (
    clk   : in std_ulogic;
    rst_n : in std_ulogic;
    up_i  : in std_ulogic;
    en_i  : in std_ulogic;
    cnt_o : out std_ulogic_vector(3 downto 0));
end entity;

architecture rtl of cntm13 is
  signal cnt, ncnt : unsigned(3 downto 0);
begin
  cnt <= to_unsigned(0,cnt'length) when rst_n = '0' else ncnt when en_i = '1' and rising_edge(clk);
  ncnt <= to_unsigned(0,cnt'length) when up_i = '1' and cnt = 12 else
          to_unsigned(12,cnt'length) when up_i = '0' and cnt = 0 else
          cnt + 1 when up_i = '1' else
          cnt - 1;
cnt_o <= std_ulogic_vector(cnt);
end architecture rtl;