vhdl中conv_unsigned函数怎么使用呢?
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;
已改,你看看。 写VHDL,尽量不要用variable。
----------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.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
begin
if reset = '1' then
count <= conv_std_logic_vector(1,n);
elsif rising_edge(clk) then
count <= count + 1;
end if;
end process p0;
p1: process(clk, reset) 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;
谢谢你啊,受益匪浅。我现在还弄不清几种类型该用哪一种
