发布网友 发布时间:2022-04-29 21:23
共1个回答
热心网友 时间:2022-06-23 02:07
N 进制计数器,自己把N的数据类型和大小改一下
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cntN is
port (clk,rst,en:in std_logic;
cq:out std_logic_vector (3 downto 0);
cout:out std_logic );
end cntN;
architecture bhv of cntN is
begin
process(clk,rst,en)
variable cqi:std_logic_vector(3 downto 0);
constant N:integer :=8;--keyi gaibian jin
begin
if rst='1' then cqi:=(others=>'0');
elsif clk'event and clk='1' then
if en='1' then
if cqi<(N-1) then cqi:=cqi+1;
else cqi:=(others=>'0');
end if;
end if;
end if;
if cqi=(N-1) then cout<='1';
else cout<='0';
end if;
cq<=cqi;
end process;
end bhv;