|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我定义的cnt变量是unsigned,但是我想它根据n的变化自动变化长度,在复位的时候赋初始值1.怎么做呢?
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity seris_gen is
generic(n : NATURAL := 3);
port(clk : in std_logic;
reset: in std_logic;
q : out std_logic);
end seris_gen;
architecture behave of seris_gen is
signal q_n : std_logic;
signal count: std_logic_vector(n-1 downto 0);
begin
p0: process (clk, reset, count) is
variable cnt : unsigned(n-1 downto 0);
begin
if reset = '1' then
-- cnt := (others => '0'); -- or use sxt
-- cnt := "001"; -- or use sxt
-- cnt := conv_unsigned(1,n);
cnt := conv_unsigned("001",3);
elsif rising_edge(clk) then
cnt := cnt + 1;
end if;
count <= std_logic_vector(cnt);
end process p0;
p1: process(clk, reset, count, q_n) is
begin
if (reset = '1') then
q_n <= '1';
elsif rising_edge(clk) then
if (count(2) and (not count(0))) = '1' then
q_n <= '0';
else
q_n <= '1';
end if;
end if;
end process p1;
q <= q_n;
end behave; |
|